From 71a69c5f9b0e305797b87ca2b05029189a09a2a7 Mon Sep 17 00:00:00 2001 From: "karl.hudgell" Date: Mon, 29 Jun 2020 21:32:14 +0100 Subject: [PATCH] quick commit --- .vscode/launch.json | 11 +++++++++- app.js | 16 +++++++-------- data/bot/{ => functions}/chat.js | 0 data/bot/{ => functions}/faq/subscriptions.js | 0 data/bot/{ => functions}/faq/whatAppToUse.js | 0 data/bot/{ => functions}/questions.js | 0 data/bot/{ => functions}/requests/football.js | 0 data/bot/{ => functions}/requests/joke.js | 0 .../requests/updateSubStatus.js | 0 data/bot/{ => functions}/welcomeMesage.js | 0 data/bot/lib/common.js | 17 ++++++++++++++++ test.js | 20 +++++++++++++++++++ 12 files changed, 55 insertions(+), 9 deletions(-) rename data/bot/{ => functions}/chat.js (100%) rename data/bot/{ => functions}/faq/subscriptions.js (100%) rename data/bot/{ => functions}/faq/whatAppToUse.js (100%) rename data/bot/{ => functions}/questions.js (100%) rename data/bot/{ => functions}/requests/football.js (100%) rename data/bot/{ => functions}/requests/joke.js (100%) rename data/bot/{ => functions}/requests/updateSubStatus.js (100%) rename data/bot/{ => functions}/welcomeMesage.js (100%) create mode 100644 data/bot/lib/common.js create mode 100644 test.js diff --git a/.vscode/launch.json b/.vscode/launch.json index 7822582..48397af 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,11 +7,20 @@ { "type": "node", "request": "launch", - "name": "Launch Program", + "name": "App", "skipFiles": [ "/**" ], "program": "${workspaceFolder}\\app.js", + }, + { + "type": "node", + "request": "launch", + "name": "Test", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}\\test.js", } ] } \ No newline at end of file diff --git a/app.js b/app.js index e893075..ca0b14c 100644 --- a/app.js +++ b/app.js @@ -11,14 +11,14 @@ const fs = require('fs'); const logger = require('perfect-logger'); const TelegramBot = require('node-telegram-bot-api'); -const bot_chat = require('./data/bot/chat') -const bot_welcome = require('./data/bot/welcomeMesage') -const bot_questions = require('./data/bot/questions') -const bot_football = require('./data/bot/requests/football') -const bot_joke = require('./data/bot/requests/joke') -const bot_faq_subscription = require('./data/bot/faq/subscriptions') -const bot_subStatus = require('./data/bot/requests/updateSubStatus') -const bot_faq_whatAppToUse = require('./data/bot/faq/whatAppToUse') +const bot_chat = require('./data/bot/functions/chat') +const bot_welcome = require('./data/bot/functions/welcomeMesage') +const bot_questions = require('./data/bot/functions/questions') +const bot_football = require('./data/bot/functions/requests/football') +const bot_joke = require('./data/bot/functions/requests/joke') +const bot_faq_subscription = require('./data/bot/functions/faq/subscriptions') +const bot_subStatus = require('./data/bot/functions/requests/updateSubStatus') +const bot_faq_whatAppToUse = require('./data/bot/functions/faq/whatAppToUse') const token = process.env.BOT_TOKEN; const name = process.env.BOT_NAME; diff --git a/data/bot/chat.js b/data/bot/functions/chat.js similarity index 100% rename from data/bot/chat.js rename to data/bot/functions/chat.js diff --git a/data/bot/faq/subscriptions.js b/data/bot/functions/faq/subscriptions.js similarity index 100% rename from data/bot/faq/subscriptions.js rename to data/bot/functions/faq/subscriptions.js diff --git a/data/bot/faq/whatAppToUse.js b/data/bot/functions/faq/whatAppToUse.js similarity index 100% rename from data/bot/faq/whatAppToUse.js rename to data/bot/functions/faq/whatAppToUse.js diff --git a/data/bot/questions.js b/data/bot/functions/questions.js similarity index 100% rename from data/bot/questions.js rename to data/bot/functions/questions.js diff --git a/data/bot/requests/football.js b/data/bot/functions/requests/football.js similarity index 100% rename from data/bot/requests/football.js rename to data/bot/functions/requests/football.js diff --git a/data/bot/requests/joke.js b/data/bot/functions/requests/joke.js similarity index 100% rename from data/bot/requests/joke.js rename to data/bot/functions/requests/joke.js diff --git a/data/bot/requests/updateSubStatus.js b/data/bot/functions/requests/updateSubStatus.js similarity index 100% rename from data/bot/requests/updateSubStatus.js rename to data/bot/functions/requests/updateSubStatus.js diff --git a/data/bot/welcomeMesage.js b/data/bot/functions/welcomeMesage.js similarity index 100% rename from data/bot/welcomeMesage.js rename to data/bot/functions/welcomeMesage.js diff --git a/data/bot/lib/common.js b/data/bot/lib/common.js new file mode 100644 index 0000000..1e18f40 --- /dev/null +++ b/data/bot/lib/common.js @@ -0,0 +1,17 @@ +module.exports = { + help: (bot, msg, logger) => { + bot.on('message', (msg) => { + const updatesGroup = "/sub_status"; + const checkName = updatesGroup + name + if (msg.text && msg.text.toString() === checkName) { + // logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Got the updates group info"); + bot.sendMessage(msg.chat.id, "The updates groups can be found here") + .then(() => { + return bot.sendMessage(msg.chat.id, "https://t.me/joinchat/AAAAAFDxZ2rzgAW5acahxA").then(() => { + return bot.sendMessage(msg.chat.id, "Please join for BBLBTV updates") + }) + }) + } + }) + } +}; \ No newline at end of file diff --git a/test.js b/test.js new file mode 100644 index 0000000..c085737 --- /dev/null +++ b/test.js @@ -0,0 +1,20 @@ +require('dotenv').config(); +const TelegramBot = require('node-telegram-bot-api'); +const token = process.env.BOT_TOKEN; + +const bot = new TelegramBot(token, { polling: true }); + +function t(msg, input) { + bot.sendMessage(msg.chat.id, input) +} + + +bot.on('message', (msg) => { + if (msg.text && msg.text.toString().includes("/sub_status")) { + t(msg, "/sub_status") + } + + if (msg.text && msg.text.toString().includes("/test")) { + t(msg, "/test") + } +}) \ No newline at end of file