seeeeems to be working...

This commit is contained in:
karl.hudgell 2020-06-30 14:21:28 +01:00
parent 89545576c5
commit 79672af370
6 changed files with 125 additions and 322 deletions

200
app.js
View File

@ -1,174 +1,76 @@
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
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
});
const TelegramBot = require('node-telegram-bot-api');
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')
let commands = require('./data/group/commands')
let navigation = require('./data/group/FAQ')
let chat = require('./data/group/chat')
let jointArray = navigation.concat(chat)
const bot = new TelegramBot(token, { polling: true });
// Wlecome Message
bot.on('new_chat_members', (msg) => {
bot_welcome.welcomeMessage(bot, msg, logger)
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_subStatus.setSubStatus(bot, msg, logger)
if (msg.text && msg.text.toString().includes("/sub_status")) {
questions.subStatus(bot, msg, logger)
}
if (msg.text && msg.text.toString().includes("/football_today")) {
requests.football_today(bot, msg, logger)
}
if (msg.text && msg.text.toString().includes("/joke")) {
requests.joke(bot, msg, logger)
}
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)
}
bot_faq_whatAppToUse.appSwitch(bot, msg, logger)
// FAQ susbcription prices
if (msg.text && msg.text.toString() === "- Subscription 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");
for (const x of jointArray) {
if (msg.text && msg.text.toString() === x.NAME) {
common.chat(bot, msg, x.NAME)
}
}
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)
);
for (const x of commands) {
if (msg.text && msg.text.toString().includes(x.NAME)) {
common.commands(bot, msg, x.NAME)
}
}
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"]
// ]
// }
// })
// })
})

View File

@ -0,0 +1,67 @@
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')
}
}
}),

View File

@ -12,15 +12,12 @@ subArray.push(["- Home"])
module.exports = {
main: (bot, msg, logger) => {
// const whatAppShouldIUse = "- what app should i use?";
// if (msg.text && msg.text.toString().toLowerCase() === whatAppShouldIUse) {
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked what app to use");
bot.sendMessage(msg.chat.id, "What Subscription do you have?", {
"reply_markup": {
"keyboard": subArray
}
})
// }
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked what app to use");
bot.sendMessage(msg.chat.id, "What Subscription do you have?", {
"reply_markup": {
"keyboard": subArray
}
})
},
appSwitch: (bot, msg, logger) => {
let string = ""

View File

@ -1,4 +1,3 @@
const name = process.env.BOT_NAME
const channel = process.env.CHANNEL
module.exports = {

View File

@ -1,91 +1 @@
[{
"SUB": "Premium Plus",
"COST": 30,
"STATUS": 1,
"APPS": [
"XCIPTV Blue",
"Sky Q Yellow",
"SMARTERS Green"
]
}, {
"SUB": "VIP",
"COST": 25,
"STATUS": 1,
"APPS": [
"XCIPTV Blue",
"Sky Q Yellow",
"SMARTERS Green"
]
}, {
"SUB": "Old Premium",
"COST": 17,
"STATUS": 1,
"APPS": [
"XCIPTV Blue",
"Sky Q Yellow",
"SMARTERS Green"
]
}, {
"SUB": "Bluemoon",
"COST": 15,
"STATUS": 1,
"APPS": [
"SMARTERS Green"
]
}, {
"SUB": "KDB",
"COST": 14,
"STATUS": 1,
"APPS": [
"SMARTERS Green"
]
}, {
"SUB": "Gold",
"COST": 13,
"STATUS": 1,
"APPS": [
"XCIPTV Red",
"Sky Q Yellow",
"SMARTERS Green"
]
}, {
"SUB": "Technoid",
"COST": 13,
"STATUS": 1,
"APPS": [
"SMARTERS Green"
]
}, {
"SUB": "Bronze",
"COST": 10,
"STATUS": 1,
"APPS": [
"XCIPTV Red",
"SMARTERS Green"
]
}, {
"SUB": "SOL",
"COST": 10,
"STATUS": 1,
"APPS": [
"SMARTERS Green"
]
}, {
"SUB": "New Premium (tvob)",
"COST": "X",
"STATUS": 1,
"APPS": [
"SMARTERS Green"
]
}, {
"SUB": "Gambler",
"COST": "X",
"STATUS": 1,
"APPS": [
"SMARTERS Green"
]
}, {
"SUB": "All of em",
"COST": "X",
"STATUS": "X"
}]
[{"SUB":"Premium Plus","COST":30,"STATUS":1,"APPS":["XCIPTV Blue","Sky Q Yellow","SMARTERS Green"]},{"SUB":"VIP","COST":25,"STATUS":1,"APPS":["XCIPTV Blue","Sky Q Yellow","SMARTERS Green"]},{"SUB":"Old Premium","COST":17,"STATUS":1,"APPS":["XCIPTV Blue","Sky Q Yellow","SMARTERS Green"]},{"SUB":"Bluemoon","COST":15,"STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"KDB","COST":14,"STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"Gold","COST":13,"STATUS":1,"APPS":["XCIPTV Red","Sky Q Yellow","SMARTERS Green"]},{"SUB":"Technoid","COST":13,"STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"Bronze","COST":10,"STATUS":1,"APPS":["XCIPTV Red","SMARTERS Green"]},{"SUB":"SOL","COST":10,"STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"New Premium (tvob)","COST":"X","STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"Gambler","COST":"X","STATUS":1,"APPS":["SMARTERS Green"]},{"SUB":"All of em","COST":"X","STATUS":"X"}]

72
test.js
View File

@ -1,72 +0,0 @@
require('dotenv').config();
const logger = require('perfect-logger');
const token = process.env.BOT_TOKEN;
const name = process.env.BOT_NAME;
// 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 TelegramBot = require('node-telegram-bot-api');
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')
let commands = require('./data/group/commands')
let navigation = require('./data/group/FAQ')
let chat = require('./data/group/chat')
let jointArray = navigation.concat(chat)
const bot = new TelegramBot(token, { polling: true });
bot.on('new_chat_members', (msg) => {
bot_welcome.welcomeMessage(bot, msg, logger)
});
bot.on('message', (msg) => {
if (msg.text && msg.text.toString().includes("/sub_status")) {
questions.subStatus(bot, msg, logger)
}
if (msg.text && msg.text.toString().includes("/football_today")) {
requests.football_today(bot, msg, logger)
}
if (msg.text && msg.text.toString().includes("/joke")) {
requests.joke(bot, msg, logger)
}
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)
if (msg.text && msg.text.toString() === "- Subscription Prices") {
bot_faq_subscription.prices(bot, msg, logger)
}
for (const x of jointArray) {
if (msg.text && msg.text.toString() === x.NAME) {
common.chat(bot, msg, x.NAME)
}
}
for (const x of commands) {
if (msg.text && msg.text.toString().includes(x.NAME)) {
common.commands(bot, msg, x.NAME)
}
}
})