-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
68 lines (62 loc) · 1.77 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
const Discord = require("discord.js");
var axios = require('axios');
var et = require('html-entities').AllHtmlEntities;
var blague = require('./blague.js');
var meteo = require('./meteo.js');
var image = require('./image.js');
var iss = require('./iss.js');
var yoda = require('./yoda.js');
var wit = require('./wit.js');
module.exports = function(params){
var self = this;
self.bot = null;
self.connect = function(){
self.bot = new Discord.Client();
self.bot.login(params.token);
self.bot.on('ready', self.onReady);
self.bot.on('message', self.onMessage);
self.bot.on('presenceUpdate',self.onPresenceUpdate);
}
self.onReady = function(){
console.log(`Logged in as ${self.bot.user.username}!`);
}
self.onMessage = function(msg){
if(msg.channel.type === 'dm' && !msg.author.bot){
//this is a direct message, response
self.response(msg,false);
}
else if(msg.channel.type === 'text'){
if(msg.mentions.users.get(self.bot.user.id) != undefined){
//on a été tagué
self.response(msg,true);
}
}
}
self.onPresenceUpdate = function(oldMember, newMember){
if(newMember.user.username == 'bramas' && newMember.presence.status == 'online'){
newMember.sendMessage("Bonjour maitre, je suis le bot de Charles et David, que puis-je faire pour vous aujourd'hui ?");
}
}
self.response = function(msg,isTag){
cont = msg.content.toLowerCase();
if(cont.includes('!blague')){
blague(msg);
}
else if(cont.includes('!meteo')){
meteo(msg,isTag)
}
else if(cont.includes('!image')){
image(msg,isTag);
}
else if(cont.includes('!iss')){
iss(msg,isTag);
}
else if(cont.includes('!yoda')){
yoda(msg,isTag);
}
else{
/*LANGAGE NATUREL*/
wit(msg,isTag);
}
}
}