working initial competition logic
This commit is contained in:
parent
031fff48bd
commit
9286548bfd
98
app.js
98
app.js
@ -2,16 +2,20 @@ require('dotenv').config();
|
||||
|
||||
var request = require("request");
|
||||
var throttledRequest = require('throttled-request')(request);
|
||||
throttledRequest.configure({requests: 8, milliseconds: 60000}); //send 1 request per second
|
||||
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 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", {
|
||||
@ -156,9 +160,9 @@ bot.on('message', (msg) => {
|
||||
}
|
||||
|
||||
const deal = "deal";
|
||||
const me = 434187971
|
||||
const sarah = 868225940
|
||||
const MANC = 470861863
|
||||
// const me = 434187971
|
||||
// const sarah = 868225940
|
||||
// const MANC = 470861863
|
||||
if (msg.text && msg.text.toString().toLowerCase().match(/\bdeal\b/)) {
|
||||
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Said we got a deal!");
|
||||
bot.sendMessage(msg.chat.id, "I LOVE it when " + msg.from.first_name + ", does a deal :)");
|
||||
@ -230,14 +234,12 @@ bot.on('message', (msg) => {
|
||||
const installoOnAndroid = "- install filelinked on android";
|
||||
if (msg.text && msg.text.toString().toLowerCase() === installoOnAndroid) {
|
||||
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Found out how to install on Android");
|
||||
bot.sendMessage(msg.chat.id, "First thing you need to do is go to browser on your Android TV box and enter www.filelinked.com")
|
||||
bot.sendMessage(msg.chat.id, "First thing you need to do is go to browser on your Android TV box and enter http://get.filelinked.com")
|
||||
.then(() => {
|
||||
return bot.sendMessage(msg.chat.id, "From this browser page, download FileLinked.").then(() => {
|
||||
return bot.sendMessage(msg.chat.id, "Once you have pressed download then you can close the browser and go to your apps.").then(() => {
|
||||
return bot.sendMessage(msg.chat.id, "Then open file manager or file browser. In here go to downloads, filemanager, press install.").then(() => {
|
||||
return bot.sendMessage(msg.chat.id, "Then go back to your apps section on the box and find filelinked app.").then(() => {
|
||||
return bot.sendMessage(msg.chat.id, "Open the app and enter the code.")
|
||||
})
|
||||
return bot.sendMessage(msg.chat.id, "Once the apk has downloaded you can close the browser and go to your apps.").then(() => {
|
||||
return bot.sendMessage(msg.chat.id, "Then open file manager or file browser. In here go to downloads, filemanager, press install.").then(() => {
|
||||
return bot.sendMessage(msg.chat.id, "Then go back to your apps section on the box and find filelinked app.").then(() => {
|
||||
return bot.sendMessage(msg.chat.id, "Open the app and enter the code.")
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -308,7 +310,79 @@ bot.on('message', (msg) => {
|
||||
const howToResetCache = "- how do i clear cache?";
|
||||
if (msg.text && msg.text.toString().toLowerCase() === howToResetCache) {
|
||||
logger.info("ID - " + msg.from.id + " First Name - " + msg.from.first_name + " Asked how to clear cache");
|
||||
bot.sendMessage(msg.chat.id, "Cache files are main source of errors and problems in functioning of Apps, by clearing cache may solve most of the problems associated with Apps. To clear cache, go to Settings > Application > Manage apps > Select \"All\" tabs, select the app which was producing error and then tap Clear cache.");
|
||||
bot.sendMessage(msg.chat.id, process.env.ADMIN_ID);
|
||||
}
|
||||
|
||||
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')
|
||||
}
|
||||
}
|
||||
|
||||
const whatAppShouldIUse = "- what app should i use?";
|
||||
|
97
package-lock.json
generated
97
package-lock.json
generated
@ -103,6 +103,11 @@
|
||||
"type-detect": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"clone": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz",
|
||||
"integrity": "sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18="
|
||||
},
|
||||
"combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
@ -275,6 +280,11 @@
|
||||
"mime-types": "^2.1.12"
|
||||
}
|
||||
},
|
||||
"fs": {
|
||||
"version": "0.0.1-security",
|
||||
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
|
||||
"integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ="
|
||||
},
|
||||
"function-bind": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
||||
@ -349,6 +359,15 @@
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||
},
|
||||
"is-absolute": {
|
||||
"version": "0.2.6",
|
||||
"resolved": "https://registry.npmjs.org/is-absolute/-/is-absolute-0.2.6.tgz",
|
||||
"integrity": "sha1-IN5p89uULvLYe5wto28XIjWxtes=",
|
||||
"requires": {
|
||||
"is-relative": "^0.2.1",
|
||||
"is-windows": "^0.2.0"
|
||||
}
|
||||
},
|
||||
"is-callable": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.0.tgz",
|
||||
@ -367,6 +386,14 @@
|
||||
"has-symbols": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"is-relative": {
|
||||
"version": "0.2.1",
|
||||
"resolved": "https://registry.npmjs.org/is-relative/-/is-relative-0.2.1.tgz",
|
||||
"integrity": "sha1-0n9MfVFtF1+2ENuEu+7yPDvJeqU=",
|
||||
"requires": {
|
||||
"is-unc-path": "^0.1.1"
|
||||
}
|
||||
},
|
||||
"is-symbol": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz",
|
||||
@ -380,6 +407,19 @@
|
||||
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
||||
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
|
||||
},
|
||||
"is-unc-path": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/is-unc-path/-/is-unc-path-0.1.2.tgz",
|
||||
"integrity": "sha1-arBTpyVzwQJQ/0FqOBTDUXivObk=",
|
||||
"requires": {
|
||||
"unc-path-regex": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"is-windows": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/is-windows/-/is-windows-0.2.0.tgz",
|
||||
"integrity": "sha1-3hqm1j6indJIc3tp8f+LgALSEIw="
|
||||
},
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
@ -529,6 +569,24 @@
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
},
|
||||
"node-cache": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/node-cache/-/node-cache-5.1.1.tgz",
|
||||
"integrity": "sha512-bJ9nH25Z51HG2QIu66K4dMVyMs6o8bNQpviDnXzG+O/gfNxPU9IpIig0j4pzlO707GcGZ6QA4rWhlRxjJsjnZw==",
|
||||
"requires": {
|
||||
"clone": "2.x"
|
||||
}
|
||||
},
|
||||
"node-persist": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/node-persist/-/node-persist-2.1.0.tgz",
|
||||
"integrity": "sha1-5lK784haBNrWo1PXQXYXfIORRwc=",
|
||||
"requires": {
|
||||
"is-absolute": "^0.2.6",
|
||||
"mkdirp": "~0.5.1",
|
||||
"q": "~1.1.1"
|
||||
}
|
||||
},
|
||||
"node-telegram-bot-api": {
|
||||
"version": "0.50.0",
|
||||
"resolved": "https://registry.npmjs.org/node-telegram-bot-api/-/node-telegram-bot-api-0.50.0.tgz",
|
||||
@ -581,6 +639,15 @@
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"path": {
|
||||
"version": "0.12.7",
|
||||
"resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz",
|
||||
"integrity": "sha1-1NwqUGxM4hl+tIHr/NWzbAFAsQ8=",
|
||||
"requires": {
|
||||
"process": "^0.11.1",
|
||||
"util": "^0.10.3"
|
||||
}
|
||||
},
|
||||
"perfect-logger": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/perfect-logger/-/perfect-logger-2.0.1.tgz",
|
||||
@ -591,6 +658,11 @@
|
||||
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
||||
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
|
||||
},
|
||||
"process": {
|
||||
"version": "0.11.10",
|
||||
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
|
||||
"integrity": "sha1-czIwDoQBYb2j5podHZGn1LwW8YI="
|
||||
},
|
||||
"process-nextick-args": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
||||
@ -615,6 +687,11 @@
|
||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
|
||||
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
|
||||
},
|
||||
"q": {
|
||||
"version": "1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/q/-/q-1.1.2.tgz",
|
||||
"integrity": "sha1-Y1fikSBnAdmfGXq4TlforRlvKok="
|
||||
},
|
||||
"qs": {
|
||||
"version": "6.5.2",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
|
||||
@ -814,6 +891,11 @@
|
||||
"resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.1.tgz",
|
||||
"integrity": "sha512-UIEXBNeYmKptWH6z8ZnqTeS8fV74zG0/eRU9VGkpzz+LIJNs8W/zM/L+7ctCkRrgbNnnR0xxw4bKOr0cW0N0Og=="
|
||||
},
|
||||
"unc-path-regex": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/unc-path-regex/-/unc-path-regex-0.1.2.tgz",
|
||||
"integrity": "sha1-5z3T17DXxe2G+6xrCufYxqadUPo="
|
||||
},
|
||||
"uri-js": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz",
|
||||
@ -822,6 +904,21 @@
|
||||
"punycode": "^2.1.0"
|
||||
}
|
||||
},
|
||||
"util": {
|
||||
"version": "0.10.4",
|
||||
"resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz",
|
||||
"integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==",
|
||||
"requires": {
|
||||
"inherits": "2.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
|
||||
}
|
||||
}
|
||||
},
|
||||
"util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||
|
@ -16,9 +16,9 @@
|
||||
"dependencies": {
|
||||
"cached-request": "^2.0.1",
|
||||
"dotenv": "^8.2.0",
|
||||
"fs": "0.0.1-security",
|
||||
"node-telegram-bot-api": "^0.50.0",
|
||||
"perfect-logger": "^2.0.1",
|
||||
"rapidapi-connect": "0.0.6",
|
||||
"request": "^2.88.2",
|
||||
"throttled-request": "^0.1.1"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user