BBLBTV_Suzie/app.js

175 lines
7.1 KiB
JavaScript
Raw Normal View History

2020-06-21 17:10:37 +01:00
require('dotenv').config();
var request = require("request");
2020-06-24 10:54:55 +01:00
var throttledRequest = require('throttled-request')(request);
2020-06-25 16:17:46 +01:00
throttledRequest.configure({ requests: 8, milliseconds: 60000 }); //send 1 request per second
2020-06-24 10:54:55 +01:00
cachedRequest = require('cached-request')(throttledRequest);
cachedRequest.setCacheDirectory("./cache");
2020-06-23 11:29:19 +01:00
2020-06-25 16:17:46 +01:00
const fs = require('fs');
2020-06-21 23:00:04 +01:00
const logger = require('perfect-logger');
2020-06-21 12:01:11 +01:00
const TelegramBot = require('node-telegram-bot-api');
2020-06-29 21:32:14 +01:00
const bot_chat = require('./data/bot/functions/chat')
const bot_welcome = require('./data/bot/functions/welcomeMesage')
const bot_questions = require('./data/bot/functions/questions')
2020-06-30 10:09:22 +01:00
const bot_football = require('./data/bot/lib/requests')
2020-06-29 21:32:14 +01:00
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')
2020-06-25 19:45:38 +01:00
const token = process.env.BOT_TOKEN;
const name = process.env.BOT_NAME;
const channel = process.env.CHANNEL
2020-06-25 16:17:46 +01:00
const admins = JSON.parse(process.env.ADMIN_ID)
let comp_users = []
2020-06-22 11:17:00 +01:00
2020-06-21 23:00:04 +01:00
// Configure Settings
logger.initialize(name + "_bot", {
2020-06-21 23:00:04 +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-21 13:44:21 +01:00
const bot = new TelegramBot(token, {
polling: true
});
2020-06-21 12:01:11 +01:00
2020-06-23 11:01:32 +01:00
// Wlecome Message
bot.on('new_chat_members', (msg) => {
2020-06-25 19:45:38 +01:00
bot_welcome.welcomeMessage(bot, msg, logger)
});
2020-06-21 12:01:11 +01:00
bot.on('message', (msg) => {
2020-06-23 11:01:32 +01:00
// Listen call for "help"
2020-06-25 19:45:38 +01:00
bot_chat.help(bot, msg, logger)
// listen for "filelinked code"
bot_chat.filelinked_help(bot, msg, logger)
// listen for "bye"
bot_chat.bye(bot, msg, logger)
// listen for "thank you BOT"
bot_chat.thankYou(bot, msg, logger, name)
// listen for "i love you BOT"
bot_chat.iLoveYou(bot, msg, logger, name)
// listen for "deal"
bot_chat.loveADeal(bot, msg, logger)
// listen for "football today"
bot_football.gamesToday(bot, msg, logger)
// listen for "BOT tell me a joke"
bot_joke.tellMe(bot, msg, logger, name)
// listen for "you there BOT"
bot_chat.youThere(bot, msg, logger, name)
// listen for "fuck off BOT"
bot_chat.fOff(bot, msg, logger, name)
// listen for "what sub should i buy?"
bot_questions.whatSubShouldIBuy(bot, msg, logger)
2020-06-26 18:33:46 +01:00
// listen for "sub status"
2020-06-25 21:55:17 +01:00
bot_questions.subStatus(bot, msg, logger)
2020-06-26 18:33:46 +01:00
// listen for "set sub X to X"
2020-06-25 22:44:18 +01:00
bot_subStatus.setSubStatus(bot, msg, logger)
2020-06-28 21:43:40 +01:00
2020-06-28 21:34:24 +01:00
bot_faq_whatAppToUse.main(bot, msg, logger)
2020-06-28 21:43:40 +01:00
bot_faq_whatAppToUse.appSwitch(bot, msg, logger)
2020-06-28 21:34:24 +01:00
2020-06-25 21:55:17 +01:00
// FAQ susbcription prices
bot_faq_subscription.prices(bot, msg, logger)
2020-06-21 13:44:21 +01:00
2020-06-21 21:31:20 +01:00
const SurfShark = "- vpn (surfshark)";
if (msg.text && msg.text.toString().toLowerCase() === SurfShark) {
2020-06-22 13:41:43 +01:00
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Read the VPN details");
2020-06-21 14:10:28 +01:00
bot.sendMessage(msg.chat.id, "SurfShark is the VPN that we advise you use on your device to bypass the blocks,\n\nYou can install this on your device from our FileLinked\n\nWe provide a username and password for you to use in the updates groups. DO NOT SHARE THE DETAILS");
}
2020-06-25 16:17:46 +01:00
const whoAdmin = "who is an admin";
if (msg.text && msg.text.toString().toLowerCase() === whoAdmin) {
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked who is an admin");
admins.forEach(element =>
bot.sendMessage(msg.chat.id, element)
);
}
const startCompCalled = "start comp called";
if (msg.text && msg.text.toString().toLowerCase().includes(startCompCalled)) {
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked who is an admin");
test = msg.text.match(/\b(\w+)$/gm);
fs.writeFileSync('./data/' + test + '.json', '[]')
bot.sendMessage(msg.chat.id, 'Comp created')
}
const stopCompCalled = "stop comp called";
if (msg.text && msg.text.toString().toLowerCase().includes(stopCompCalled)) {
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked who is an admin");
test = msg.text.match(/\b(\w+)$/gm);
fs.unlinkSync('./data/' + test + '.json', '[]')
bot.sendMessage(msg.chat.id, 'Comp removed')
}
const comp = "entered the comp";
if (msg.text && msg.text.toString().toLowerCase().includes(comp)) {
if (admins.indexOf(msg.from.id) > -1) {
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked who is an admin");
user = msg.text.match(/^([\w\-]+)/gm)[0];
let comp_name = msg.text.match(/\b(\w+)$/gm)[0];
comp_users = JSON.parse(fs.readFileSync('./data/' + comp_name + '.json', 'utf8'))
let new_comp_users = comp_users.concat(user)
fs.writeFileSync('./data/' + comp_name + '.json', JSON.stringify(new_comp_users))
bot.sendMessage(msg.chat.id, user + " has been added to the competition")
} else {
console.log('not found')
}
}
const enteredTheComp = "how many in comp";
if (msg.text && msg.text.toString().toLowerCase().includes(enteredTheComp)) {
if (admins.indexOf(msg.from.id) > -1) {
let comp_name = msg.text.match(/\b(\w+)$/gm)[0];
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked who is an admin");
var comp_entered = JSON.parse(fs.readFileSync('./data/' + comp_name + '.json', 'utf8'))
bot.sendMessage(msg.chat.id, "There are " + comp_entered.length + " people in the comp")
} else {
console.log('not found')
}
}
const whoWon = "who won comp";
if (msg.text && msg.text.toString().toLowerCase().includes(whoWon)) {
if (admins.indexOf(msg.from.id) > -1) {
let comp_name = msg.text.match(/\b(\w+)$/gm)[0];
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked who is an admin");
var comp_entered = JSON.parse(fs.readFileSync('./data/' + comp_name + '.json', 'utf8'))
var winner = comp_entered[Math.floor(Math.random() * comp_entered.length)];
bot.sendMessage(msg.chat.id, "There winner is .....").then(() => {
return bot.sendMessage(msg.chat.id, winner)
})
} else {
console.log('not found')
}
2020-06-21 14:40:31 +01:00
}
2020-06-21 16:42:38 +01:00
}),
2020-06-30 13:34:58 +01:00
// bot.onText(/^- FileLinked$/, (msg) => {
// logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Got the fileLinked code");
// bot.sendMessage(msg.chat.id, "The current FileLinked code is - " + process.env.FILELINKED_PIN + "\n\nYou can download all our players from there", {
// "reply_markup": {
// "keyboard": [
// ["- Install FileLinked on FireStick", "- Install FileLinked on Android"],
// ["- Home"]
// ]
// }
// })
// })
2020-06-21 14:10:28 +01:00
2020-06-21 14:28:52 +01:00