From 018954e70d1d04a04fd44bf434160ca2ecd76bb0 Mon Sep 17 00:00:00 2001 From: Guillaume Vagner <guillaume.vagner@supelec.fr> Date: Sun, 24 Feb 2019 13:08:12 +0100 Subject: [PATCH] true-reset --- connection-db.js | 14 +++++++++++++- telegram.js | 7 +++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/connection-db.js b/connection-db.js index 1d42911..807434f 100644 --- a/connection-db.js +++ b/connection-db.js @@ -1,5 +1,12 @@ +// CONNECTION-DB : Module de connexion à la base de données et fonctions pour modifier groupes et chans + +// Modules extérieurs var mysql = require('promise-mysql'); +// Création de variables +var schedules = {}; + +// Configurations const config = require('./config'); @@ -100,6 +107,11 @@ function removeGroup(chatId, groupId) { DELETE FROM groups WHERE chatId = ${chatId} AND grp = ${groupId}`) } +function removeAllGroups(chatId) { + return query(` + DELETE FROM groups WHERE chatId = ${chatId}`) +} + function getGroups(chatId) { return query(` SELECT grp @@ -119,4 +131,4 @@ function getSchedules() { } -module.exports = { query, getChanByChatId, createChan, deleteChanByChatId, modifyChan, getChanByState, addGroup, removeGroup, getGroups, getSchedules }; \ No newline at end of file +module.exports = { query, getChanByChatId, createChan, deleteChanByChatId, modifyChan, getChanByState, addGroup, removeGroup, removeAllGroups, getGroups, getSchedules }; \ No newline at end of file diff --git a/telegram.js b/telegram.js index 6b090db..9503c51 100644 --- a/telegram.js +++ b/telegram.js @@ -1,10 +1,12 @@ +// TELEGRAM.JS : Gestion du bot Telegram + process.env["NTBA_FIX_319"] = 1; // Modules extérieurs var TelegramBot = require('node-telegram-bot-api'); // Modules propres -var { getChanByChatId, createChan, deleteChanByChatId, modifyChan, addGroup, removeGroup, getGroups } = require('./connection-db'); +var { getChanByChatId, createChan, deleteChanByChatId, modifyChan, addGroup, removeGroup, removeAllGroups, getGroups } = require('./connection-db'); var { getBirthdays, searchGroups, getGroupById } = require('./requests'); var { schedules, addSchedule, deleteSchedule } = require('./schedule'); @@ -20,7 +22,7 @@ var bot = new TelegramBot(config.telegram.token, { polling: true }); bot.onText(/\/start/, msg => { const chatId = msg.chat.id; return getChanByChatId(chatId).then(chan => { - // /start déjà fait... + // /start déjà fait if (chan) return bot.sendMessage(chatId, 'Vous avez déjà fait lancé le bot sur cette conversation. Pour tout réinitialiser, faites /reset.') return createChan(chatId).then(_ => { const resp = 'Holà, je suis le Happy Botday, je suis là pour vous souhaiter vous rapeller les anniversaires de vos potes !\nPour commencer, il faut que quelqu\'un s\'identifie : /connect'; @@ -36,6 +38,7 @@ bot.onText(/\/reset/, msg => { deleteSchedule(chatId); return Promise.all([ deleteChanByChatId(chatId), + removeAllGroups(chatId) ]).then(_ => { const resp = 'Toutes vos paramètres ont été supprimés. Pour recommencer à m\'utiliser, faites /start.'; bot.sendMessage(chatId, resp); -- GitLab