From 70f4f17e71caeef4d8fa01cfe382b307050ed8f5 Mon Sep 17 00:00:00 2001 From: Lukian LEIZOUR Date: Sat, 19 Nov 2022 12:34:03 +0100 Subject: [PATCH] commit --- app.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index c1cecf7..34d4f31 100644 --- a/app.js +++ b/app.js @@ -4,7 +4,7 @@ const google = require('googlethis'); //bot initialization const bot = new Telegraf(process.env.TELEGRAM); -//function to search google +//functions function image_search(query, ctx) { const images = google.image(query, { safe: false }); images.then((results) => { @@ -14,6 +14,22 @@ function image_search(query, ctx) { }); } +function isTrue(message, ctx) { + var totalSum = 0 + + for (var i = 0; i < message.length; i++) { + totalSum += message.charCodeAt(i) + } + if (totalSum%2 == 0) { + bot.telegram.sendMessage(ctx.chat.id, "This message is true", {"reply_to_message_id": ctx.update.message.reply_to_message.message_id}); + console.log("--> sent true for the query: " + message); + } + else { + bot.telegram.sendMessage(ctx.chat.id, "This message is false", {"reply_to_message_id": ctx.update.message.reply_to_message.message_id}); + console.log("--> sent false for the query: " + message); + } +} + //bot commands bot.command('start', ctx => { console.log(ctx.from) @@ -22,7 +38,7 @@ bot.command('start', ctx => { }) bot.help(ctx => { - console.log(ctx.from) + console.log('--> sent help') ctx.reply('This is the help message :\nHelp command : \n -/help\nAnime command : \n -/anime\nImage search command : \n -/search or /s\nGithub link command : \n -/github') }) @@ -37,14 +53,17 @@ bot.command('github', ctx => { }) bot.command('search', ctx => { - console.log(ctx.from) image_search(ctx.message.text.slice(+8), ctx) }) bot.command('s', ctx => { - console.log(ctx.from) image_search(ctx.message.text.slice(+3), ctx) }) +bot.command('truce', ctx => { + const message = ctx.update.message.reply_to_message.text + isTrue(message, ctx) +}) + //bot launch bot.launch(); \ No newline at end of file