BBLBTV_Suzie/app.js
2020-06-30 13:34:58 +01:00

175 lines
7.1 KiB
JavaScript

require('dotenv').config();
var request = require("request");
var throttledRequest = require('throttled-request')(request);
throttledRequest.configure({ requests: 8, milliseconds: 60000 }); //send 1 request per second
cachedRequest = require('cached-request')(throttledRequest);
cachedRequest.setCacheDirectory("./cache");
const fs = require('fs');
const logger = require('perfect-logger');
const TelegramBot = require('node-telegram-bot-api');
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/lib/requests')
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;
const channel = process.env.CHANNEL
const admins = JSON.parse(process.env.ADMIN_ID)
let comp_users = []
// Configure Settings
logger.initialize(name + "_bot", {
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
});
const bot = new TelegramBot(token, {
polling: true
});
// Wlecome Message
bot.on('new_chat_members', (msg) => {
bot_welcome.welcomeMessage(bot, msg, logger)
});
bot.on('message', (msg) => {
// Listen call for "help"
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)
// listen for "sub status"
bot_questions.subStatus(bot, msg, logger)
// listen for "set sub X to X"
bot_subStatus.setSubStatus(bot, msg, logger)
bot_faq_whatAppToUse.main(bot, msg, logger)
bot_faq_whatAppToUse.appSwitch(bot, msg, logger)
// FAQ susbcription prices
bot_faq_subscription.prices(bot, msg, logger)
const SurfShark = "- vpn (surfshark)";
if (msg.text && msg.text.toString().toLowerCase() === SurfShark) {
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Read the VPN details");
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");
}
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')
}
}
}),
// 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"]
// ]
// }
// })
// })