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

rebootproof

parent 65b29782
No related branches found
No related tags found
No related merge requests found
...@@ -105,5 +105,13 @@ function getGroups(chatId) { ...@@ -105,5 +105,13 @@ function getGroups(chatId) {
}) })
} }
function getSchedules() {
return query(`
SELECT *
FROM channel
WHERE schedule <> ""
`)
}
module.exports = { query, getChanByChatId, createChan, deleteChanByChatId, modifyChan, getChanByState, addGroup, getGroups }; module.exports = { query, getChanByChatId, createChan, deleteChanByChatId, modifyChan, getChanByState, addGroup, getGroups, getSchedules };
\ No newline at end of file \ No newline at end of file
...@@ -2,23 +2,22 @@ ...@@ -2,23 +2,22 @@
var schedule = require('node-schedule'); var schedule = require('node-schedule');
// Modules propres // Modules propres
var { modifyChan, getGroups } = require('./connection-db'); var { modifyChan, getGroups, getSchedules } = require('./connection-db');
var { getBirthdays, getNewToken } = require('./requests'); var { getBirthdays, getNewToken } = require('./requests');
var bot = require('./telegram');
// Création de variables // Création de variables
var schedules = {}; var schedules = {};
getSchedules().then(chans => {
chans.forEach(chan => {
addSchedule(chan, chan.schedule)
})
console.log(`[schdles] reload schedules`)
})
// En cas de redémarrage de l'appli function addSchedule(chan, time) {
// query(`SELECT chatId, schedule FROM channel WHERE schedule <> ""`).then(rep => {
// rep.forEach(chan => {
//
// })
// })
function addSchedule(chan, time, bot) {
const hour = parseInt(time.split(':')[0]); const hour = parseInt(time.split(':')[0]);
const minute = parseInt(time.split(':')[1]); const minute = parseInt(time.split(':')[1]);
chan.schedule = time; chan.schedule = time;
......
...@@ -168,7 +168,7 @@ bot.onText(/\/add (.+)/, (msg, match) => { ...@@ -168,7 +168,7 @@ bot.onText(/\/add (.+)/, (msg, match) => {
}) })
// Ajout du temps de schedule // Ajout d'un rappel
bot.onText(/\/schedule (.+)/, (msg, match) => { bot.onText(/\/schedule (.+)/, (msg, match) => {
const chatId = msg.chat.id; const chatId = msg.chat.id;
const time = match[1]; const time = match[1];
...@@ -180,19 +180,20 @@ bot.onText(/\/schedule (.+)/, (msg, match) => { ...@@ -180,19 +180,20 @@ bot.onText(/\/schedule (.+)/, (msg, match) => {
bot.sendMessage(chatId, `Votre rappel est configuré pour tous les jours à ${time}`); bot.sendMessage(chatId, `Votre rappel est configuré pour tous les jours à ${time}`);
}) })
// Suppression du rappel
bot.onText(/\/unschedule/, msg => { bot.onText(/\/unschedule/, msg => {
const chatId = msg.chat.id; const chatId = msg.chat.id;
getChanByChatId(chatId).then(chan => { getChanByChatId(chatId).then(chan => {
if (!chan) return bot.sendMessage(chatId, 'Pas de compte enregistré, faites /start pour commencer'); if (!chan) return bot.sendMessage(chatId, 'Pas de compte enregistré, faites /start pour commencer');
if (chan.time == '') return bot.sendMessage(chatId, 'Pas de rappel défini...'); if (chan.schedule == '') return bot.sendMessage(chatId, 'Pas de rappel défini...');
deleteSchedule(chatId) deleteSchedule(chatId)
chan.time = '' chan.schedule = ''
return modifyChan(chan) return modifyChan(chan)
}).then(_ => { }).then(_ => {
bot.sendMessage(chatId, 'Votre rappel a été supprimé.') bot.sendMessage(chatId, 'Votre rappel a été supprimé.')
}) })
}) })
// J'étais bien obligé (en vrai c'est pour tester) // J'étais bien obligé (en vrai c'est pour tester)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment