Skip to content
Snippets Groups Projects
Commit c9cfa7a3 authored by Guillaume Vagner's avatar Guillaume Vagner
Browse files

can remove groups

parent 218efe85
Branches
No related tags found
No related merge requests found
......@@ -95,6 +95,11 @@ function addGroup(chatId, groupId) {
`);
}
function removeGroup(chatId, groupId) {
return query(`
DELETE FROM groups WHERE chatId = ${chatId} AND grp = ${groupId}`)
}
function getGroups(chatId) {
return query(`
SELECT grp
......@@ -114,4 +119,4 @@ function getSchedules() {
}
module.exports = { query, getChanByChatId, createChan, deleteChanByChatId, modifyChan, getChanByState, addGroup, getGroups, getSchedules };
\ No newline at end of file
module.exports = { query, getChanByChatId, createChan, deleteChanByChatId, modifyChan, getChanByState, addGroup, removeGroup, getGroups, getSchedules };
\ No newline at end of file
......@@ -4,7 +4,7 @@ process.env["NTBA_FIX_319"] = 1;
var TelegramBot = require('node-telegram-bot-api');
// Modules propres
var { getChanByChatId, createChan, deleteChanByChatId, modifyChan, addGroup, getGroups } = require('./connection-db');
var { getChanByChatId, createChan, deleteChanByChatId, modifyChan, addGroup, removeGroup, getGroups } = require('./connection-db');
var { getBirthdays, searchGroups, getGroupById } = require('./requests');
var { schedules, addSchedule, deleteSchedule } = require('./schedule');
......@@ -167,6 +167,26 @@ bot.onText(/\/add (.+)/, (msg, match) => {
})
})
bot.onText(/\/del (.+)/, (msg, match) => {
const chatId = msg.chat.id;
getChanByChatId(chatId).then(chan => {
const id = parseInt(match[1].split(' ')[0]);
return Promise.all([
getGroupById(chan.token, id),
getGroups(chatId),
id
]);
}).then(([group, groups, id]) => {
// si pas de groupe trouvé
if (!group) return bot.sendMessage(chatId, 'Pas de groupe trouvé ayant cette ID');
// si le groupe y est déjà
if (groups.indexOf(id) === -1) return bot.sendMessage(chatId, 'Ce groupe n\'est pas dans votre liste d\'anniversaire.');
// sinon on le rajoute
return removeGroup(chatId, id).then(_ => {
bot.sendMessage(chatId, `Retrait du groupe \`${group}\` de la liste des anniversaires.`, { parse_mode: 'Markdown' });
})
})
})
// Ajout d'un rappel
bot.onText(/\/schedule (.+)/, (msg, match) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment