-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.js
45 lines (39 loc) · 1.62 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
const Discord = require('discord.js-selfbot');
const cleverbot = require("cleverbot-free");
const client = new Discord.Client();
var fs = require('fs')
var ini = require('ini')
var config = ini.parse(fs.readFileSync('./config.ini', 'utf-8'))
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
function sleep(millis) {
return new Promise(resolve => setTimeout(resolve, millis));
}
var busy = false; // anti-async
client.on('raw', input => { // raw allows me to intercept group chat messages, however no way to send back
if (input.t == 'MESSAGE_CREATE' && input.d.channel_id == config.channel_id && busy == false) {
if (input.d.author.id != client.user.id) {
busy = true;
var msgContextArray = new Array();
const channel = client.channels.cache.get(config.channel_id);
channel.messages.fetch({
limit: 5
}).then(messages => {
messages.forEach(message => msgContextArray.push(message.content)); // gives cleverbot some context!
})
channel.startTyping();
cleverbot(`${input.d.content}`, msgContextArray).then(response => {
sleep(225 * response.length);
if ( Math.floor(Math.random() * 100) + 1 < 10 ) { // sometimes just don't respond
return;
} else {
channel.send(`${response.toLowerCase()}`); // lower case for more "human"-like typing, at least on discord!
}
});
channel.stopTyping();
busy = false;
}
}
});
client.login(config.token);