-
Notifications
You must be signed in to change notification settings - Fork 0
/
yugibot.js
59 lines (52 loc) · 1.81 KB
/
yugibot.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
var Discord = require('discord.js');
var logger = require('winston');
var auth = require('./yugibotauth.json');
var rita = require('rita');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(logger.transports.Console, {
colorize: true
});
logger.level = 'debug';
// INIT MARKOV CHAIN
var dialogueMarkov = new rita.RiMarkov(3,true,true);
dialogueMarkov.loadFrom('dialogue.txt');
dialogueMarkov.minSentenceLength = 3;
var descriptionMarkov = new rita.RiMarkov(3,true,true);
descriptionMarkov.loadFrom('description.txt');
descriptionMarkov.minSentenceLength = 3;
// Initialize Discord Bot
var bot = new Discord.Client();
bot.on('ready', () => {
logger.info('Connected');
logger.info('Logged in as: ');
logger.info(bot.user.username + ' - (' + bot.user.id + ')');
});
bot.on('error',(error) => { logger.error(error.message); });
bot.on('message', (message) => {
if(message.author.username != 'yugibot'){
// say something ?
if(message.isMentioned(bot.user)) {
var text = '';
var nbLine = Math.floor(Math.random()*5) + 1;
var line = '';
for (var i=0;i<nbLine;i++) {
var desc = false;
if (Math.random() > 0.3) {
line = dialogueMarkov.generateSentences(1)[0];
} else {
desc = true;
line = descriptionMarkov.generateSentences(1)[0];
}
line = line.replace('..','.').replace('?.','?').replace('!.','!').replace(' .','.');
if (!desc){
text = line + '\n';
}else {
text = '***' + line + '***' + '\n';
}
message.channel.send(text);
}
}
}
});
bot.login(auth.token);