HerzaJ commited on
Commit
aa2955d
·
verified ·
1 Parent(s): ca4d525

Create hackai.js

Browse files
Files changed (1) hide show
  1. plugins/hackai.js +158 -0
plugins/hackai.js ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const axios = require('axios');
2
+
3
+ let currentAccount = null;
4
+ let requestCount = 0;
5
+
6
+ async function hackai(query) {
7
+ if (!currentAccount || requestCount >= 5) {
8
+ const tempMailResponse = await axios.post('https://api.internal.temp-mail.io/api/v3/email/new', {
9
+ min_name_length: 10,
10
+ max_name_length: 10
11
+ }, {
12
+ headers: {
13
+ 'Content-Type': 'application/json',
14
+ 'Application-Name': 'web',
15
+ 'Application-Version': '4.0.0',
16
+ 'X-CORS-Header': 'iaWg3pchvFx48fY'
17
+ }
18
+ });
19
+
20
+ const { email, token } = tempMailResponse.data;
21
+
22
+ await axios.post('https://identitytoolkit.googleapis.com/v1/accounts:sendOobCode?key=AIzaSyAaSg74fiq2FKPvfqo9QT55c5DmCmETKVY', {
23
+ requestType: 'EMAIL_SIGNIN',
24
+ email: email,
25
+ clientType: 'CLIENT_TYPE_WEB',
26
+ continueUrl: 'https://chat.hackaigc.com',
27
+ canHandleCodeInApp: true
28
+ }, {
29
+ headers: {
30
+ 'X-Client-Version': 'Chrome/JsCore/10.12.1/FirebaseCore-web',
31
+ 'X-Firebase-gmpid': '1:1096968884444:web:346299d4d159d5f9d8e419',
32
+ 'Content-Type': 'application/json'
33
+ }
34
+ });
35
+
36
+ await new Promise(resolve => setTimeout(resolve, 5000));
37
+
38
+ const messagesResponse = await axios.get(`https://api.internal.temp-mail.io/api/v3/email/${email}/messages`, {
39
+ headers: {
40
+ 'Content-Type': 'application/json',
41
+ 'Application-Name': 'web',
42
+ 'Application-Version': '4.0.0',
43
+ 'X-CORS-Header': 'iaWg3pchvFx48fY'
44
+ }
45
+ });
46
+
47
+ const message = messagesResponse.data[0];
48
+ const urlMatch = message.body_html.match(/href='([^']+)'/);
49
+ const verifyUrl = urlMatch[1].replace(/&/g, '&');
50
+
51
+ const oobCodeMatch = verifyUrl.match(/oobCode=([^&]+)/);
52
+ const oobCode = oobCodeMatch[1];
53
+
54
+ const signInResponse = await axios.post('https://identitytoolkit.googleapis.com/v1/accounts:signInWithEmailLink?key=AIzaSyAaSg74fiq2FKPvfqo9QT55c5DmCmETKVY', {
55
+ email: email,
56
+ oobCode: oobCode
57
+ }, {
58
+ headers: {
59
+ 'Content-Type': 'application/json'
60
+ }
61
+ });
62
+
63
+ const bearerToken = signInResponse.data.idToken;
64
+ const userId = signInResponse.data.localId;
65
+
66
+ currentAccount = {
67
+ email: email,
68
+ otpUrl: verifyUrl,
69
+ bearerToken: bearerToken,
70
+ userId: userId
71
+ };
72
+
73
+ requestCount = 0;
74
+ }
75
+
76
+ requestCount++;
77
+
78
+ const chatResponse = await axios.post('https://chat.hackaigc.com/api/chat', {
79
+ user_id: currentAccount.userId,
80
+ user_level: 'free',
81
+ model: 'gpt-4o',
82
+ messages: [{ role: 'user', content: query }],
83
+ prompt: '',
84
+ temperature: 0.7,
85
+ enableWebSearch: false,
86
+ usedVoiceInput: false
87
+ }, {
88
+ headers: {
89
+ 'Content-Type': 'application/json',
90
+ 'Authorization': `Bearer ${currentAccount.bearerToken}`
91
+ }
92
+ });
93
+
94
+ return {
95
+ email: currentAccount.email,
96
+ otpUrl: currentAccount.otpUrl,
97
+ bearerToken: currentAccount.bearerToken,
98
+ requestCount: requestCount,
99
+ response: chatResponse.data
100
+ };
101
+ }
102
+
103
+ const accountLimits = new Map();
104
+
105
+ const handler = async (req, res) => {
106
+ try {
107
+ const { text, key } = req.query;
108
+
109
+ if (!text || !key) {
110
+ return res.status(400).json({
111
+ success: false,
112
+ error: 'Missing required parameters: text and key'
113
+ });
114
+ }
115
+
116
+ const currentCount = accountLimits.get(key) || 0;
117
+
118
+ if (currentCount >= 8) {
119
+ return res.status(429).json({
120
+ success: false,
121
+ error: 'API key limit reached. Maximum 8 requests per key.'
122
+ });
123
+ }
124
+
125
+ const result = await hackai(text);
126
+
127
+ accountLimits.set(key, currentCount + 1);
128
+
129
+ res.json({
130
+ author: "Herza",
131
+ success: true,
132
+ email: result.email,
133
+ otpUrl: result.otpUrl,
134
+ bearerToken: result.bearerToken,
135
+ requestCount: result.requestCount,
136
+ keyUsage: `${currentCount + 1}/8`,
137
+ msg: result.response
138
+ });
139
+
140
+ } catch (error) {
141
+ res.status(500).json({
142
+ success: false,
143
+ error: error.message
144
+ });
145
+ }
146
+ };
147
+
148
+ module.exports = {
149
+ name: 'HackAI GPT-4o',
150
+ description: 'Generate responses using HackAI GPT-4o with automatic account rotation',
151
+ type: 'GET',
152
+ routes: ['api/AI/hackai'],
153
+ tags: ['ai', 'gpt4o', 'hackai'],
154
+ main: ['AI'],
155
+ parameters: ['text', 'key'],
156
+ enabled: true,
157
+ handler
158
+ };