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

commands with @namebot

parent 15018584
Branches
No related tags found
No related merge requests found
...@@ -130,9 +130,9 @@ bot.onText(/\/birthdays/, msg => { ...@@ -130,9 +130,9 @@ bot.onText(/\/birthdays/, msg => {
}); });
// recherche des groupes et renvoie le résultat avec leurs ID pour les rajouter // recherche des groupes et renvoie le résultat avec leurs ID pour les rajouter
bot.onText(/\/search (.+)/, (msg, match) => { bot.onText(new RegExp(`/search (.+)|/search@${config.telegram.name} (.+)`), (msg, match) => {
const chatId = msg.chat.id; const chatId = msg.chat.id;
const research = match[1]; const research = match[0].split(' ')[1];
getChanByChatId(chatId).then(chan => { getChanByChatId(chatId).then(chan => {
return searchGroups(chan, research) return searchGroups(chan, research)
}).then(groups => { }).then(groups => {
...@@ -149,10 +149,10 @@ bot.onText(/\/search (.+)/, (msg, match) => { ...@@ -149,10 +149,10 @@ bot.onText(/\/search (.+)/, (msg, match) => {
}) })
// Ajout d'un groupe dans la liste des groupes // Ajout d'un groupe dans la liste des groupes
bot.onText(/\/add (.+)/, (msg, match) => { bot.onText(new RegExp(`/add (.+)|/add@${config.telegram.name} (.+)`), (msg, match) => {
const chatId = msg.chat.id; const chatId = msg.chat.id;
getChanByChatId(chatId).then(chan => { getChanByChatId(chatId).then(chan => {
const id = parseInt(match[1].split(' ')[0]); const id = parseInt(match[0].split(' ')[1]);
return Promise.all([ return Promise.all([
getGroupById(chan, id), getGroupById(chan, id),
getGroups(chatId), getGroups(chatId),
...@@ -170,10 +170,10 @@ bot.onText(/\/add (.+)/, (msg, match) => { ...@@ -170,10 +170,10 @@ bot.onText(/\/add (.+)/, (msg, match) => {
}) })
}) })
bot.onText(/\/del (.+)/, (msg, match) => { bot.onText(new RegExp(`/del (.+)|/del@${config.telegram.name} (.+)`), (msg, match) => {
const chatId = msg.chat.id; const chatId = msg.chat.id;
getChanByChatId(chatId).then(chan => { getChanByChatId(chatId).then(chan => {
const id = parseInt(match[1].split(' ')[0]); const id = parseInt(match[0].split(' ')[1]);
return Promise.all([ return Promise.all([
getGroupById(chan, id), getGroupById(chan, id),
getGroups(chatId), getGroups(chatId),
...@@ -192,9 +192,9 @@ bot.onText(/\/del (.+)/, (msg, match) => { ...@@ -192,9 +192,9 @@ bot.onText(/\/del (.+)/, (msg, match) => {
}) })
// Ajout d'un rappel // Ajout d'un rappel
bot.onText(/\/schedule (.+)/, (msg, match) => { bot.onText(new RegExp(`/schedule (.+)|/schedule@${config.telegram.name} (.+)`), (msg, match) => {
const chatId = msg.chat.id; const chatId = msg.chat.id;
const time = match[1]; const time = match[0].split(' ')[1];
if (!RegExp('^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$').test(time)) return bot.sendMessage(chatId, 'Le temps entré n\'est pas au format hh:mm'); if (!RegExp('^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$').test(time)) return bot.sendMessage(chatId, 'Le temps entré n\'est pas au format hh:mm');
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');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment