diff --git a/app.js b/app.js index a2ccee2..6220997 100644 --- a/app.js +++ b/app.js @@ -1,10 +1,11 @@ //Importing libs const { Telegraf } = require('telegraf'); +const fs = require('fs'); //Importing other files const { getJoke } = require('./libs/dadJokes'); const { rtag, r34 } = require('./libs/rule34'); -const { addToLogs, isTrue, image_search } = require('./libs/botTools'); +const { addToLogs, isTrue, image_search, getHelp } = require('./libs/botTools'); const { rockPaperScissorsAgainstBot } = require('./libs/games'); const { generateImage } = require('./libs/openAi'); @@ -18,36 +19,19 @@ bot.command('start', ctx => { addToLogs("--> sent the start message to " + ctx.message.from.username); }) -bot.help(ctx => { - const helpMessage = - ` -This is the help message : -Help command : - -/help -Anime command : - -/anime -AI Generated image command : - -\`/g \` -Image search command : - -\`/s \` -Dad jokes command : - -/dadjoke -Rock Paper Scissors command : - -\`/rps \` -Rule34 tag command : - -\`/rtag \` -Rule 34 image search : - -\`/r34 \` -Truce command : - -/truce (reply to a message with that command to verify it) -Suggest command : - -\`/suggest \` (allows you to add a suggestion to the chanel t.me/+SrzC81CGyusyODNk) -Github link command : - -/github - ` - bot.telegram.sendMessage(ctx.chat.id, helpMessage, {parse_mode: "Markdown"}) - console.log('--> sent the help message') - addToLogs('--> sent the help message') +bot.command('help', ctx => { + if (ctx.message.text.slice(+6) != '') { + getHelp(ctx.message.text.slice(+6), ctx, bot); + } else { + fs.readFile('./src/helps/default.txt', 'utf8', (err, data) => { + if (err) { + console.log(err); + bot.telegram.sendMessage(ctx.chat.id, "Something went wrong", {}); + } else { + bot.telegram.sendMessage(ctx.chat.id, data, {parse_mode: 'Markdown'}); + } + }); + } }) bot.command('anime', ctx => { @@ -70,8 +54,10 @@ bot.command('truce', ctx => { isTrue(ctx.update.message.reply_to_message.text, ctx, bot) }) -bot.command('chatInfo', ctx => { - console.log(ctx.chat.id) +bot.command('chatinfo', ctx => { + console.log('--> sent chat info') + addToLogs('--> sent chat info') + bot.telegram.sendMessage(ctx.chat.id, 'Chat id : ' + ctx.chat.id, {}) }) bot.command('suggest', ctx => { diff --git a/libs/botTools.js b/libs/botTools.js index c1b58f4..45e5909 100644 --- a/libs/botTools.js +++ b/libs/botTools.js @@ -60,4 +60,22 @@ function addToLogs(message) { }); } -module.exports = { addToLogs, isTrue, image_search }; \ No newline at end of file +function getHelp(commandName, ctx, bot) { + const commands = [ 'images', 'games', 'r34', 'openai', 'tools' ]; + const commandsPaths = { 'images': './src/helps/images.txt', 'games': './src/helps/games.txt', 'r34': './src/helps/r34.txt', 'openai': './src/helps/openAI.txt', 'tools': './src/helps/tools.txt' }; + + if (commands.includes(commandName)) { + fs.readFile(commandsPaths[commandName], 'utf8', (err, data) => { + if (err) { + console.log(err); + bot.telegram.sendMessage(ctx.chat.id, "Something went wrong", {}); + } else { + bot.telegram.sendMessage(ctx.chat.id, data, {parse_mode: 'Markdown'}); + } + }); + } else { + bot.telegram.sendMessage(ctx.chat.id, "This command doesn't exist", {}); + } +} + +module.exports = { addToLogs, isTrue, image_search, getHelp }; \ No newline at end of file diff --git a/libs/openAi.js b/libs/openAi.js index 31659ba..597f30b 100644 --- a/libs/openAi.js +++ b/libs/openAi.js @@ -13,10 +13,14 @@ function generateImage(query, ctx, bot) { n: 1, size: "1024x1024", response_format : 'url' - }) + }).catch((err) => { + console.log(err); + addToLogs("--> error : " + err); + bot.telegram.sendMessage(ctx.chat.id, "Something went wrong", {}); + }); - console.log("--> generating image for the querry" + query); - addToLogs("--> generating image for the querry" + query) + console.log("--> generating image for the querry " + query); + addToLogs("--> generating image for the querry " + query) bot.telegram.sendMessage(ctx.chat.id, "Generating the image.", {}); image.then((res) => { diff --git a/libs/rule34.js b/libs/rule34.js index a6cb789..15f0a63 100644 --- a/libs/rule34.js +++ b/libs/rule34.js @@ -6,10 +6,15 @@ const https = require('https'); const { addToLogs } = require('./botTools'); +const blockedChannels = [ -1001845876532 ]; + function rtag(query, ctx, bot) { - // - //Search for a tag on r34 - // + + if (blockedChannels.includes(ctx.chat.id)) { + bot.telegram.sendMessage(ctx.chat.id, "This command is disabled in this channel", {}); + return; + } + console.log("--> r34sTag query: " + query); addToLogs("--> r34sTag query: " + query); https.get("https://rule34.xxx/public/autocomplete.php?q=" + query, (resp) => { @@ -47,6 +52,11 @@ function r34(tag, ctx, bot) { // //Search for the tag on r34 and send a random image // + + if (blockedChannels.includes(ctx.chat.id)) { + bot.telegram.sendMessage(ctx.chat.id, "This command is disabled in this channel", {}); + return; + } console.log("--> r34 query: " + tag); addToLogs("--> r34 query: " + tag); https.get('https://api.rule34.xxx/index.php?page=dapi&s=post&q=index&json=1&tags=' + tag, (resp) => { diff --git a/src/helps/default.txt b/src/helps/default.txt new file mode 100644 index 0000000..0f3f54c --- /dev/null +++ b/src/helps/default.txt @@ -0,0 +1,15 @@ +This is the default help message, you can access help messages by typing `/help `. + +List of helps messages : + + -`/help` + + -`/help images` + + -`/help openai` + + -`/help games` + + -`/help r34` + + -`/help tools` \ No newline at end of file diff --git a/src/helps/games.txt b/src/helps/games.txt new file mode 100644 index 0000000..5e8df78 --- /dev/null +++ b/src/helps/games.txt @@ -0,0 +1,9 @@ +This is the games help message : + +list of games commands : + + -`/rps ` (used to play rock paper scissors against the bot) + + -`/truce` (reply to a message with that command to verify it) + + -`/dadjoke` (send a dad joke) \ No newline at end of file diff --git a/src/helps/images.txt b/src/helps/images.txt new file mode 100644 index 0000000..2316d76 --- /dev/null +++ b/src/helps/images.txt @@ -0,0 +1,5 @@ +This is the images help message : + +list of images commands : + + -`/s ` (send a random image of google for your query) \ No newline at end of file diff --git a/src/helps/openAI.txt b/src/helps/openAI.txt new file mode 100644 index 0000000..142df30 --- /dev/null +++ b/src/helps/openAI.txt @@ -0,0 +1,5 @@ +This is the opanAI help message : + +list of opanAI commands : + + -`/g ` (generate an image with DALL-E with your query) \ No newline at end of file diff --git a/src/helps/r34.txt b/src/helps/r34.txt new file mode 100644 index 0000000..53d2a06 --- /dev/null +++ b/src/helps/r34.txt @@ -0,0 +1,9 @@ +This is the rule34 help message : + +list of rule34 commands : + + -`/rtag ` (search for a tag on rule34 site) + + -`/r34 ` (send a random rule34 image of your tag) + +ps: only use these commands in private messages \ No newline at end of file diff --git a/src/helps/tools.txt b/src/helps/tools.txt new file mode 100644 index 0000000..ffde60d --- /dev/null +++ b/src/helps/tools.txt @@ -0,0 +1,9 @@ +This is the tools help message : + +list of tools commands : + + -`/suggest ` (suggest a new feature for the bot) + + -`/github` (send the GitHub repository link) + + -`/chatinfo` (send the current chat ID) \ No newline at end of file