-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.old.js
More file actions
419 lines (380 loc) · 13.3 KB
/
app.old.js
File metadata and controls
419 lines (380 loc) · 13.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
// Imports
const qrcode = require('qrcode-terminal');
const { Client, LocalAuth, GroupNotificationTypes, Util } = require('whatsapp-web.js');
const fs = require('fs');
const wikipedia = require('wikipedia');
const FormData = require('form-data');
const axios = require('axios');
const express = require('express');
const { Configuration, OpenAIApi } = require("openai");
require('dotenv').config();
const configuration = {
apiKey: process.env.GROQ_API_KEY, //get a free key in our discord server!
basePath: "https://api.groq.com/openai/v1"
};
const openai = new OpenAIApi(configuration);
openai.createChatCompletion({
model: "deepseek-r1-distill-llama-70b",
messages: [
{
role: "user",
content: "Hey there, how are you?"
}
]
}).then((dt) => {
console.log(dt.data.choices[0].message)
}).catch((error) => {
console.log(error)
})
async function getWeather(apiKey, city) {
try {
const response = await axios.get('http://api.openweathermap.org/data/2.5/weather', {
params: {
q: city,
appid: apiKey,
units: 'metric'
}
});
// Handle the API response
console.log(response.data);
// You can perform additional processing or return the data as needed
return response.data;
} catch (error) {
// Handle any errors
console.error(error);
}
}
server = express();
server.get('/', (req, res) => {
res.send('I am Alive.')
})
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
async function insultAPI(){
try{
const response = await axios.get(`https://evilinsult.com/generate_insult.php?lang=en&type=json`);
return response.data.insult;
} catch (error) {
console.log(error)
return 'Insulting you is an Insult to those wors, whom i used as an Insult.'
}
}
// Function to decode base64 image and upload it to 0x0.st
async function uploadImageTo0x0St(imageBase64) {
const imagePath = 'tempImage.jpg';
// Decode the base64 image and save it to disk
const imageBuffer = Buffer.from(imageBase64, 'base64');
fs.writeFileSync(imagePath, imageBuffer);
// Create form data with the image file
const formData = new FormData();
formData.append('file', fs.createReadStream(imagePath));
try {
const response = await axios.post('https://0x0.st', formData, {
headers: formData.getHeaders()
});
return response.data.trim();
} catch (error) {
console.error('Error occurred while uploading image:', error);
} finally {
// Remove the temporary image file
fs.unlinkSync(imagePath);
}
}
// Function to check for NSFW images and alcoholic photos
async function checkImage(imageBase64, apiUser, apiSecret) {
const imageUrl = await uploadImageTo0x0St(imageBase64);
const endpoint = 'https://api.sightengine.com/1.0/check.json';
const params = {
models: 'nudity-2.0,wad,offensive,tobacco',
api_user: apiUser,
api_secret: apiSecret,
url: imageUrl
};
try {
const response = await axios.get(endpoint, { params });
const { nudity, alcohol, offensive } = response.data;
console.log(response.data)
if (alcohol > 0.5){
return true
}
if (nudity.none < 0.8){
return true
}
if (offensive.middle_finger > 0.5) {
return true
}
return false; // No NSFW content or alcoholic photo found
} catch (error) {
console.error('Error occurred during image analysis:', error);
}
}
//Client Object with LocalAuth to preserve the session
const client = new Client({
authStrategy: new LocalAuth({clientId: 'Primary_Session'})
});
// Profanity Filter English
function detectEnSlang(message) {
// Load and parse the JSON file
const jsonData = fs.readFileSync('slangs_en.json');
const slangs = JSON.parse(jsonData);
msg = message.toLowerCase().split(' ')
// Iterate through the slangs array
for (const slang of slangs) {
if (msg.includes(slang.text)) {
return {
detected: true,
data: slang
}; // Slang detected
}
}
return {
detected: false,
data: null
}; // No slangs detected
}
client.on('qr', qr => {
qrcode.generate(qr, {small: true});
});
client.on('ready', () => {
console.log('Client is ready!');
});
function keepAlive() {
server.listen(8000, () => {
console.log('Server has started on port 8000');
})
}
//keepAlive();
function choice(array) {
return array[Math.floor(Math.random() * array.length)];
}
client.on('message', async (message) => {
//await sleep(2*1000);
// Chat Logs
console.log(message);
//Profanity check
if (typeof message.body === 'string'){
param = detectEnSlang(message.body);
console.log(param);
if (param.detected){
console.log(message.body)
} else {
client.sendMessage(message.from, `Stop Slanging. You have been warned for using a ${param.data['category_1']} like slang.`);
client.sendMessage(message.author, `Stop Slanging. You have been warned for using a ${param.data['category_1']} like slang.`).catch((error) => {
console.log(error);
});
message.forward(message.author).catch((error) => {
console.log(error);
});
message.delete(true).catch((error) => {
console.log(error);
});
}}
}
//NSFW Images
if ((message.type === 'image') || (message.type === 'sticker')) {
media = await message.downloadMedia();
try {
checkImage(media.data, process.env.SIGHTENGINE_API_USER, process.env.SIGHTENGINE_API_SECRET)
.then((dt) => {
console.log(dt)
if (dt){
message.delete(true).catch((error) => {console.log(error)});
client.sendMessage(message.from, 'Aiii, Chup! Ye sab nahi chalega yaha')
}
})
.catch((error) => {
console.log(error)
})} catch (error) {
console.log(error)
}
} //Shorten it to Maybe 30 Words, and make it look like a Text that would have been sent in a Chat room
// Wa me settings bug Shorten it to Maybe 30 Words, and make it look like a Text that would have been sent in a Chat room
//Probability to reply to a Messge via GPT
num = Math.floor(Math.random()*69)
if ((num === 2) && (message.author != undefined)){
console.log('Lucky')
try{
chat = await message.getChat();
msgs = await chat.fetchMessages({
limit: 10
});
last10texts = msgs.map((message) => {
contact = message.getContact();
return JSON.stringify({
body : message.body,
from: ((message.fromMe) ? 'Nova' : ((contact.isMyContact) ? (contact.name) : (message.puhname)))})
}).join('\n');
} catch (error) {
console.log(error);
last10texts = '';
}
dt = await openai.createChatCompletion({
model: "deepseek-r1-distill-llama-70b",
messages: [
{
role: 'user',
content: `${last10texts}\n${message.body}\nThese are the Last 10 messages. Now You need to reply as Nova the Moderator of BroCode Tech Community, and in a short (30-40 words) and as if you are texting in a chatroom, like including acronyms and ect.Remember to be Funny, but wise with your response`
}
]
}).catch((error) => {
console.log(error)
})
try {
text = dt.data.choices[0].message.content;
console.log(text);
} catch (error) {
console.log(error)
text='Unexpected Error'
}
message.reply(text)
}
// DM to get reply and help
if ((message.author == undefined)&&(message.type === 'chat')){
console.log('DM')
try{
chat = await message.getChat();
msgs = await chat.fetchMessages({
limit: 10
});
last10texts = msgs.map((message) => {
return JSON.stringify({body : message.body, from: ((message.fromMe) ? 'Nova' : 'User')})
}).join('\n');
} catch (error) {
console.log(error);
last10texts = '';
}
dt = await openai.createChatCompletion({
model: "deepseek-r1-distill-llama-70b",
messages: [
{
role: 'user',
content: `'${last10texts}\n${message.body}'\nThese are the Last 10 messages for context. Now You need to reply as Nova, pretending to be him, the Moderator (bot) of BroCode Tech Community made by Arnav ghosh, and text as if you are texting in a chatroom. Don't Respond like a Dialouge Script and Don't Start the message with 'Nova:'. Remind the User too, that sending ;h reveals all the Available Commands. Skip with your Introduction if it gets repetative.`
}
]
}).catch((error) => {
console.log(error)
})
try {
text = dt.data.choices[0].message.content;
console.log(text);
} catch (error) {
console.log(error)
text='Unexpected Error'
}
message.reply(text)
}
console.log(`${message.from} ${message.author} ${message.type} ${message.body}`);
// Commands
if (message.body === ';web'){
message.reply('Email: [email protected]\nWebsite: https://brocode-tech.netlify.app/\nTwitter: https://twitter.com/brocode501\nVisit our website More Details');
} else {
if (message.body === ';source'){
message.reply('Hi, I am Nova, the Moderation Bot and here is the source code: https://github.com/BroCode501/moderation-bot')
} else {
if ((message.body === ';h') || (message.body === ';help')){
message.reply(`
Hi, I am Nova, the Moderation Bot of the Group.
Command List:
Argument less Commands.
;help or ;h - Help Command
;web - External links to Author and BroCode
;source - Source code of Bot
;oof - Random Insults
Commands That Need Arguments
;wikipedia - Get any wikipedia article (argument1: article name)
;0x0-img - Uploads the Attached image to 0x0.st and replies the link (argument1: Attached Image (Just Use this as the caption of a photo))
;gpt - GPT-3.5-turbo Bot *Usage: _;gpt Hello!_*
;weather - Get weather of that Place (argument1: Place)
`)
} else {
// Complex Commands Go here
cmd_array = message.body.split(' ')
if (cmd_array[0] === ';wikipedia'){
wikipedia.summary(cmd_array.slice(1).join(' '))
.then((dt) => {
if ((dt.title === 'Not found.') ||dt.content_urls) {
message.reply(`${dt.extract}\n${dt.content_urls.mobile.page}`)
} else {
message.reply('Not found')
}
})
.catch((error) => {
message.reply(`Unexpected Error Occured. Please Try again later`)
console.log(error)
})
} else {
if ((message.body === ';tirtha') || (message.body === ';tutu') || (message.body === ';oof')){
enhi = ['en', 'hi'];
dt = await insultAPI(choice(enhi));
message.reply(`${dt}`)
console.log(`${dt}`)
}else {
if (cmd_array[0] === ';weather'){
try{
dt = await getWeather(process.env.OWMAPI_KEY, cmd_array[1])
strweather = JSON.stringify(dt)
} catch (error) {
console.log(error)
}
try{
dt = await openai.createCompletion({
model: "text-davinci-003",
prompt: `The data contains the following JSON:\n${strweather}\n\nGive a Summary of the Weather Report:`,
max_tokens: 100,
temperature: 0.4
})
reply = dt.data.choices[0].text.trim();
console.log(reply)
} catch (error) {
console.log(error)
reply = "Unexpected Error"
}
message.reply(reply)
}else {
if (cmd_array[0] === ';gpt'){
dt = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{role: "user", content: cmd_array.slice(1).join(' ')}]
}).catch((error) => {
console.log(error)
})
try {
text = dt.data.choices[0].message.content;
console.log(text);
} catch (error) {
console.log(error)
text='Unexpected Error'
}
message.reply(text)
} else {
if (message.body === ';0x0-img'){
try{
try{
media = await message.downloadMedia();
} catch (error) {
message.reply('Can\'t download image')
}
url = await uploadImageTo0x0St(media.data);
message.reply(url)
} catch (error) {
message.reply('Unexpected Error')
console.log(error)
}
} else{
console.log('')
}
}
}
}
}
}
}
}
});
client.initialize();