-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
100 lines (86 loc) · 2.8 KB
/
bot.js
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
const { Client, Intents } = require('discord.js');
const axios = require('axios');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const BOT_TOKEN = '';
const userRequestMap = new Map();
const nomesInvertidos = [
"Amando",
"Beatrizo",
"Cecilio",
"Deniso",
"Estelo",
"Giselo",
"Heleno",
"Ivono",
"Janaino",
"Karino",
"Leticio",
"Monico",
"Nadio",
"Sonio",
"Ursulo",
"Viviano",
"Grazielo",
"Samsungo",
"Iphono",
"Rito Cadilaco",
"Microsofto",
"Facebooko",
"Amazono",
"Snapchato",
"TikToko",
"WhatsAppo",
"Linkedinio",
"Netflixo",
"Spotifyo",
];
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.login(BOT_TOKEN);
client.on('messageCreate', async message => {
if (message.mentions.has(client.user.id) && !message.author.bot) {
try {
const channel = message.channel;
console.info(channel);
const userId = message.author.id;
const currentTime = Date.now();
const fiveMinutes = 300000; // 5 minutes in milliseconds
if (userRequestMap.has(userId) && currentTime - userRequestMap.get(userId) < fiveMinutes) {
// Calculate remaining time
const remainingTime = fiveMinutes - (currentTime - userRequestMap.get(userId));
const remainingSeconds = Math.round(remainingTime / 1000);
// get random index from nomesInvertidos
const randomIndex = Math.floor(Math.random() * nomesInvertidos.length);
message.reply(`Calma ai ${nomesInvertidos[randomIndex]} segura ${remainingSeconds} segundos, não sou um robô!`);
return;
}
// Update the user's request time
userRequestMap.set(userId, currentTime);
const tempMessage = await message.reply('Só um minuto, estou pensando...');
const messageContent = message.content.replace(/<@!?\d+>/, '').trim();
const isRapidao = messageContent.includes('#rapidao');
const apiEndpoint = 'http://localhost:11434/api/generate';
console.info(`User ${userId} requested: ${messageContent}`);
let response;
if (isRapidao) {
userRequestMap.set(userId, currentTime / 5);
response = await axios.post(apiEndpoint, {
model: "mistral",
prompt: `Responda de forma breve, simples e resumida. ${messageContent}`,
stream: false
});
} else {
response = await axios.post(apiEndpoint, {
model: "codellama:7b-instruct",
prompt: `Você é um programador especialista que escreve códigos e explicações simples e concisos. ${messageContent}`,
stream: false
});
}
tempMessage.edit(`<@${userId}> ${response.data.response}`);
} catch (error) {
tempMessage.edit("nao faço ideia kkkk");
console.error(error);
}
}
});