This commit is contained in:
Lukian LEIZOUR 2022-11-20 11:41:41 +01:00
parent a8552daa6b
commit 86d6ff67bf

59
app.js
View file

@ -1,6 +1,7 @@
const { Telegraf } = require('telegraf'); const { Telegraf } = require('telegraf');
const google = require('googlethis'); const google = require('googlethis');
const fs = require('fs'); const fs = require('fs');
const { assert } = require('console');
//bot initialization //bot initialization
const bot = new Telegraf(process.env.TELEGRAM); const bot = new Telegraf(process.env.TELEGRAM);
@ -12,84 +13,66 @@ function image_search(query, ctx) {
var imgLink = results[Math.floor(Math.random() * results.length)].url var imgLink = results[Math.floor(Math.random() * results.length)].url
bot.telegram.sendPhoto(ctx.chat.id, imgLink, {"caption": "This is a random image for the query : " + query}); bot.telegram.sendPhoto(ctx.chat.id, imgLink, {"caption": "This is a random image for the query : " + query});
console.log("--> sent the image for the query: " + query); console.log("--> sent the image for the query: " + query);
fs.appendFile('./logs/logs.txt', "--> sent the image for the query: " + query + "\n", err => { addToLogs("--> sent the image for the query: " + query);
if (err) {
console.log(err);
}
});
}) })
} }
function isTrue(message, ctx) { function isTrue(message, ctx) {
if (message != undefined) { if (message != undefined) {
console.log("--> message received: " + message); console.log("--> message received: " + message);
addToLogs("--> message received: " + message);
var totalSum = 0 var totalSum = 0
for (var i = 0; i < message.length; i++) { for (var i = 0; i < message.length; i++) {
totalSum += message.charCodeAt(i) totalSum += message.charCodeAt(i)
} }
if (totalSum%2 == 0) { 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}); 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); console.log("--> sent true for the query: " + message);
fs.appendFile('./logs/logs.txt', "--> sent true for the query: " + message + "\n", err => { addToLogs("--> sent true for the query: " + message);
if (err) {
console.log(err);
}
});
} }
else { else {
bot.telegram.sendMessage(ctx.chat.id, "This message is false", {"reply_to_message_id": ctx.update.message.reply_to_message.message_id}); 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); console.log("--> sent false for the query: " + message);
fs.appendFile('./logs/logs.txt', "--> sent false for the query: " + message + "\n", err => { addToLogs("--> sent false for the query: " + message);
if (err) {
console.log(err);
}
});
} }
} else { } else {
bot.telegram.sendMessage(ctx.chat.id, "Please reply to a text message", {'reply_to_message_id': ctx.update.message.message_id}); bot.telegram.sendMessage(ctx.chat.id, "Please reply to a text message", {'reply_to_message_id': ctx.update.message.message_id});
} }
} }
//bot commands function addToLogs(message) {
bot.command('start', ctx => { fs.appendFile('./logs/logs.txt', message + "\n", err => {
bot.telegram.sendMessage(ctx.chat.id, 'hello there! Welcome to my new telegram bot.\nType /help for help.', {})
console.log("--> sent the start message to " + ctx.message.from.username);
fs.appendFile('./logs/logs.txt', "--> sent the start message to " + ctx.message.from.username + "\n", err => {
if (err) { if (err) {
console.log(err); console.log(err);
} }
}); });
}
//bot commands
bot.command('start', ctx => {
bot.telegram.sendMessage(ctx.chat.id, 'hello there! Welcome to my new telegram bot.\nType /help for help.', {})
console.log("--> sent the start message to " + ctx.message.from.username);
addToLogs("--> sent the start message to " + ctx.message.from.username);
}) })
bot.help(ctx => { bot.help(ctx => {
ctx.reply('This is the help message :\nHelp command : \n -/help\nAnime command : \n -/anime\nImage search command : \n -/search or /s <query>\nTruce command :\n -/truce (reply to a message with that command to verify it)\nSuggest command :\n -/suggest <suggestion> (allows you to add a suggestion to the chanel t.me/+SrzC81CGyusyODNk)\nGithub link command : \n -/github') ctx.reply('This is the help message :\nHelp command : \n -/help\nAnime command : \n -/anime\nImage search command : \n -/search or /s <query>\nTruce command :\n -/truce (reply to a message with that command to verify it)\nSuggest command :\n -/suggest <suggestion> (allows you to add a suggestion to the chanel t.me/+SrzC81CGyusyODNk)\nGithub link command : \n -/github')
console.log('--> sent the help message') console.log('--> sent the help message')
fs.appendFile("./logs/logs.txt", "--> sent the help message\n", err => { addToLogs('--> sent the help message')
if (err) {
console.log(err)
}
})
}) })
bot.command('anime', ctx => { bot.command('anime', ctx => {
bot.telegram.sendMessage(ctx.chat.id, 'List of anime :\nKonosuba 1 : \nhttps://mega.nz/folder/M4gFRYbT#jiHwPRtkf7YyN6-MoguQcw\nKonosuba 2 :\nhttps://mega.nz/folder/JgZgiZbS#S0J1SoUd_TFKKun6SSJgmQ', {}) bot.telegram.sendMessage(ctx.chat.id, 'List of anime :\nKonosuba 1 : \nhttps://mega.nz/folder/M4gFRYbT#jiHwPRtkf7YyN6-MoguQcw\nKonosuba 2 :\nhttps://mega.nz/folder/JgZgiZbS#S0J1SoUd_TFKKun6SSJgmQ', {})
console.log('--> sent anime list') console.log('--> sent anime list')
fs.appendFile("./logs/logs.txt", "--> sent anime list\n", err => { addToLogs('--> sent anime list')
if (err) {
console.log(err)
}
})
}) })
bot.command('github', ctx => { bot.command('github', ctx => {
bot.telegram.sendMessage(ctx.chat.id, 'Link of the Gihhub repository :\n -https://github.com/Ninja-Jambon/chaise_bot', {}) bot.telegram.sendMessage(ctx.chat.id, 'Link of the Gihhub repository :\n -https://github.com/Ninja-Jambon/chaise_bot', {})
console.log('--> sent github link') console.log('--> sent github link')
fs.appendFile("./logs/logs.txt", "--> sent github link\n", err => { addToLogs('--> sent github link')
if (err) {
console.log(err)
}
})
}) })
bot.command('search', ctx => { bot.command('search', ctx => {
@ -113,11 +96,7 @@ bot.command('suggest', ctx => {
bot.telegram.sendMessage('-1001782224138', 'New suggestion of ' + ctx.message.from.username + " : " + ctx.message.text.slice(+9), {}) bot.telegram.sendMessage('-1001782224138', 'New suggestion of ' + ctx.message.from.username + " : " + ctx.message.text.slice(+9), {})
bot.telegram.sendMessage(ctx.chat.id, 'Your suggestion has been sent to the channel t.me/+SrzC81CGyusyODNk', {}) bot.telegram.sendMessage(ctx.chat.id, 'Your suggestion has been sent to the channel t.me/+SrzC81CGyusyODNk', {})
console.log('--> sent suggestion message to the channel') console.log('--> sent suggestion message to the channel')
fs.appendFile("./logs/logs.txt", "--> sent suggestion message to the channel\n", err => { addToLogs('--> sent suggestion message to the channel')
if (err) {
console.log(err)
}
})
}) })
//bot launch //bot launch