educ-bot/educ.js
2020-03-30 20:55:12 +02:00

133 lines
4.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 daccord',
},
'non': {
'prefix': ':thumbsdown:',
'description': 'Je ne suis pas daccord',
},
'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': 'Jadore',
},
'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 lon 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');