BBLBTV_Suzie/app.js

94 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-06-21 17:10:37 +01:00
require('dotenv').config();
2020-06-21 23:00:04 +01:00
const logger = require('perfect-logger');
2020-06-25 19:45:38 +01:00
const token = process.env.BOT_TOKEN;
const name = process.env.BOT_NAME;
2020-06-22 11:17:00 +01:00
2020-06-21 23:00:04 +01:00
// Configure Settings
logger.initialize(name + "_bot", {
2020-06-30 14:21:28 +01:00
logLevelFile: 0, // Log level for file
logLevelConsole: 0, // Log level for STDOUT/STDERR
logDirectory: 'logs/', // Log directory
// customBannerHeaders: 'This is a custom banner' // Custom Log Banner
2020-06-21 23:00:04 +01:00
});
2020-06-30 14:21:28 +01:00
const TelegramBot = require('node-telegram-bot-api');
2020-06-30 14:21:28 +01:00
const common = require('./data/bot/lib/common')
const questions = require('./data/bot/lib/questions')
const requests = require('./data/bot/lib/requests')
const bot_welcome = require('./data/bot/functions/welcomeMesage')
const bot_faq_whatAppToUse = require('./data/bot/functions/faq/whatAppToUse')
const bot_faq_subscription = require('./data/bot/functions/faq/subscriptions')
const bot_subStatus = require('./data/bot/functions/requests/updateSubStatus')
2020-06-28 21:34:24 +01:00
2020-06-21 13:44:21 +01:00
2020-06-30 14:21:28 +01:00
let commands = require('./data/group/commands')
let navigation = require('./data/group/FAQ')
let chat = require('./data/group/chat')
let jointArray = navigation.concat(chat)
2020-06-21 13:44:21 +01:00
2020-06-21 14:10:28 +01:00
2020-06-30 14:21:28 +01:00
const bot = new TelegramBot(token, { polling: true });
2020-06-25 16:17:46 +01:00
2020-06-30 14:21:28 +01:00
bot.on('new_chat_members', (msg) => {
bot_welcome.welcomeMessage(bot, msg, logger)
});
2020-06-25 16:17:46 +01:00
2020-06-30 14:21:28 +01:00
bot.on('message', (msg) => {
2020-06-25 16:17:46 +01:00
2020-06-30 14:21:28 +01:00
if (msg.text && msg.text.toString().includes("/sub_status")) {
questions.subStatus(bot, msg, logger)
}
2020-06-25 16:17:46 +01:00
2020-06-30 14:21:28 +01:00
if (msg.text && msg.text.toString().includes("/football_today")) {
requests.football_today(bot, msg, logger)
}
2020-06-25 16:17:46 +01:00
2020-06-30 14:21:28 +01:00
if (msg.text && msg.text.toString().includes("/joke")) {
requests.joke(bot, msg, logger)
}
2020-06-25 16:17:46 +01:00
2020-06-30 14:21:28 +01:00
if (msg.text && msg.text.toString() === "- What app should I use?") {
bot_faq_whatAppToUse.main(bot, msg, logger)
}
bot_faq_whatAppToUse.appSwitch(bot, msg, logger)
2020-06-25 16:17:46 +01:00
2020-06-30 14:21:28 +01:00
if (msg.text && msg.text.toString() === "- Subscription Prices") {
bot_faq_subscription.prices(bot, msg, logger)
}
2020-06-25 16:17:46 +01:00
2020-06-30 14:21:28 +01:00
for (const x of jointArray) {
if (msg.text && msg.text.toString() === x.NAME) {
2020-07-01 19:10:05 +01:00
common.chat(bot, msg, x.NAME, logger)
2020-06-25 16:17:46 +01:00
}
2020-06-30 14:21:28 +01:00
}
2020-06-25 16:17:46 +01:00
2020-06-30 14:21:28 +01:00
for (const x of commands) {
if (msg.text && msg.text.toString().includes(x.NAME)) {
2020-07-01 19:10:05 +01:00
common.commands(bot, msg, x.NAME, logger)
2020-06-21 14:40:31 +01:00
}
2020-06-30 14:21:28 +01:00
}
2020-06-21 14:40:31 +01:00
2020-07-01 19:10:05 +01:00
if (msg.text && msg.text.toString().includes("/chat")) {
const chatId = msg.chat.id;
match = msg.text.match(/([^\s]+)/g);
const resp = match[1]; // the captured "whatever"
2020-07-02 08:43:16 +01:00
2020-07-01 19:10:05 +01:00
// for (const x of jointArray) {
2020-07-02 08:43:16 +01:00
// if (resp === x.NAME) {
// common.chat(bot, msg, resp)
// }
2020-07-01 19:10:05 +01:00
// }
2020-07-02 08:43:16 +01:00
console.log('chat')
2020-07-01 19:10:05 +01:00
bot.sendMessage(msg.chat.id, resp, logger)
}
2020-07-04 11:18:14 +01:00
if (msg.text && msg.text.toString().toLowerCase().includes("set sub")) {
2020-07-02 08:43:16 +01:00
bot_subStatus.setSubStatus(bot, msg, logger)
}
2020-07-01 19:10:05 +01:00
});