133 lines
4.0 KiB
JavaScript
133 lines
4.0 KiB
JavaScript
const Discord = require('discord.js');
|
||
const client = new Discord.Client();
|
||
|
||
client.on('ready', () => {
|
||
console.log('Logged in as ${client.user.tag}');
|
||
});
|
||
|
||
// l'ID du channel de test (test-bot) pour plus tard
|
||
// var testchan_id = '691952512332202064';
|
||
|
||
/* Liste des réactions possibles et de leurs représentants actuel */
|
||
var reactions = {
|
||
'oui': {
|
||
'prefix': ':thumbsup:',
|
||
'description': 'Je suis d’accord',
|
||
},
|
||
'non': {
|
||
'prefix': ':thumbsdown:',
|
||
'description': 'Je ne suis pas d’accord',
|
||
},
|
||
'parole': {
|
||
'prefix': ':raised_hand:',
|
||
'description': 'Je veux parler',
|
||
},
|
||
'réponse': {
|
||
'prefix': ':raised_hands:',
|
||
'description': 'Je veux répondre rapidement',
|
||
},
|
||
'suffit': {
|
||
'prefix': ':octogonal_sign:',
|
||
'description': 'On tourne en rond',
|
||
},
|
||
'écoute': {
|
||
'prefix': ':hear_no_evil:',
|
||
'description': 'On ne s’écoute pas',
|
||
},
|
||
'love': {
|
||
'prefix': ':heart_eyes:',
|
||
'description': 'J’adore',
|
||
},
|
||
'dab': {
|
||
'prefix': ':dab:',
|
||
'description': 'Dab',
|
||
},
|
||
};
|
||
for (var index in reactions) {
|
||
reactions[index].people = []
|
||
}
|
||
|
||
/* Liste des channels où on peut lire avec le dernier message que l’on y a envoyé */
|
||
/* 1282482389371398137183: <msg> */
|
||
var channels = {}
|
||
|
||
var last_post = null; /* On se souvient du derier post que ce bot a envoyé pour le virer dès que possible */
|
||
|
||
client.on('message', msg => {
|
||
if(msg.content === '!educpop-reset') {
|
||
for (var index in reactions) {
|
||
reactions[index].people = []
|
||
}
|
||
reply(msg)
|
||
msg.reply('La liste est vidée :)')
|
||
}
|
||
else if (msg.content === '!educpop-enable') {
|
||
var id = msg.channel.id
|
||
if (id in channels) {
|
||
msg.reply('J’écoute déjà ce canal texte.')
|
||
} else {
|
||
channels[id] = null
|
||
msg.reply('J’écoute maintenant ce canal texte.')
|
||
}
|
||
}
|
||
else if (msg.content === '!educpop-disable') {
|
||
var id = msg.channel.id
|
||
if (id in channels) {
|
||
delete channels[id]
|
||
msg.reply('Je n’écoute plus ce canal texte.')
|
||
} else {
|
||
msg.reply('Je n’écoutais pas ce canal texte :o')
|
||
}
|
||
}
|
||
else if (msg.content === '!educpop-help') {
|
||
var text = 'Tapez simplement le mot-clé ci-dessous pour être comptabilisé. Tapez un - immédiatement suivi du mot-clé pour être retiré du compte : -oui !'
|
||
for (var index in reactions) {
|
||
text += '\n' + reactions[index].prefix + index + ' : ' + reactions[index].description
|
||
}
|
||
msg.author.send(text)
|
||
msg.delete()
|
||
}
|
||
/* Listen to educ pop stuff only in authorized channels */
|
||
else if(!(msg.channel.id in channels)) {
|
||
return;
|
||
}
|
||
/* save and ignore own messages */
|
||
else if(msg.author.username === 'bod-educ-pop'){ // TODO only log it if answer to educpop
|
||
channels[msg.channel.id] = msg;
|
||
}
|
||
/* Educ pop stuff */
|
||
else if(msg.content.startsWith('-')) {
|
||
var content = msg.content.slice(1)
|
||
if (content in reactions) {
|
||
var reaction = reactions[content].people
|
||
var index = reaction.indexOf(msg.author.username)
|
||
if (index >= 0) {
|
||
reaction.splice(index, 1)
|
||
}
|
||
reply(msg)
|
||
}
|
||
}
|
||
else if (msg.content in reactions) {
|
||
var reaction = reactions[msg.content].people
|
||
if (reaction.indexOf(msg.author.username) < 0) {
|
||
reaction.push(msg.author.username)
|
||
}
|
||
reply(msg)
|
||
}
|
||
});
|
||
|
||
|
||
function reply (msg) {
|
||
var text = ''
|
||
for (var index in reactions) {
|
||
if (reactions[index].people.length > 0)
|
||
text += '\n' + reactions[index].prefix + String(reactions[index].people)
|
||
}
|
||
|
||
if(channels[msg.channel.id]) channels[msg.channel.id].delete()
|
||
msg.reply(text)
|
||
msg.delete()
|
||
}
|
||
|
||
client.login('NjkxOTUzMDQzMDcxMzAzNzIy.Xnnhng.pYBFO2ogooVs2AyYz8Pk6AKhMoo');
|