Added Class for easier dev

This commit is contained in:
SowinskiBraeden committed 2021-08-04 11:04:08 -07:00
1 parent 9a071ea341
commit 2ff93e5010
3 files changed
+30 -17

No files matched your search

+25 -16
View File
@@ -5,8 +5,16 @@ const Discord = require('discord.js');
const client = new Discord.Client(); const client = new Discord.Client();
const config = require('./config'); const config = require('./config');
class Bot {
constructor(dev, token) {
this.dev = dev;
this.token = token;
}
// Updates Prefix // Updates Prefix
async function newPrefix(message, n) { async newPrefix(message, n) {
if (n[0]==undefined) return message.channel.send(`You must provide a **new prefix** ${message.author}!`); if (n[0]==undefined) return message.channel.send(`You must provide a **new prefix** ${message.author}!`);
if (n[0].length<1) return message.channel.send('Your new prefix must be \`1\` character!') if (n[0].length<1) return message.channel.send('Your new prefix must be \`1\` character!')
let db = await MongoClient.connect(config.mongoURI,{useUnifiedTopology:true}); let db = await MongoClient.connect(config.mongoURI,{useUnifiedTopology:true});
@@ -18,7 +26,7 @@ async function newPrefix(message, n) {
} }
// Remote Login // Remote Login
async function remoteLogin(message, args) { async remoteLogin(message, args) {
if (args.length==0) return message.author.send(`You must provide a **email** and **password** ${message.author}!`); if (args.length==0) return message.author.send(`You must provide a **email** and **password** ${message.author}!`);
if (!args[0]==null||!args[0]==undefined&&args[1]==null||args[1]==undefined) return message.author.send(`You must provide a **password** ${message.author}!`); if (!args[0]==null||!args[0]==undefined&&args[1]==null||args[1]==undefined) return message.author.send(`You must provide a **password** ${message.author}!`);
let db = await MongoClient.connect(config.mongoURI,{useUnifiedTopology:true}); let db = await MongoClient.connect(config.mongoURI,{useUnifiedTopology:true});
@@ -60,20 +68,20 @@ async function remoteLogout(message) {
}); });
} }
async function getUser(id) { async getUser(id) {
let db = await MongoClient.connect(config.mongoURI,{useUnifiedTopology:true}); let db = await MongoClient.connect(config.mongoURI,{useUnifiedTopology:true});
let dbo = db.db(config.dbo); let dbo = db.db(config.dbo);
return await dbo.collection("users").findOne({"user.discord.id":id}).then(user => user); return await dbo.collection("users").findOne({"user.discord.id":id}).then(user => user);
} }
async function account(message) { async account(message) {
getUser(message).then(user => { getUser(message).then(user => {
if (user==null) return message.channel.send(`You are not logged in ${message.author}!`); if (user==null) return message.channel.send(`You are not logged in ${message.author}!`);
return message.author.send(`${message.author} Logged in as **${user.user.username}** | **${user.user.email}**`); return message.author.send(`${message.author} Logged in as **${user.user.username}** | **${user.user.email}**`);
}); });
} }
async function checkStatus(message, args) { async checkStatus(message, args) {
if (args.length==0) { if (args.length==0) {
getUser(message.author.id).then(user => { getUser(message.author.id).then(user => {
if (user==null) return message.channel.send(`You are not logged in ${message.author}!`); if (user==null) return message.channel.send(`You are not logged in ${message.author}!`);
@@ -90,7 +98,7 @@ async function checkStatus(message, args) {
} }
} }
async function updateStatus(message, args, prefix) { async updateStatus(message, args, prefix) {
let validStatus=['10-8','10-7','10-6','10-11','10-23','10-97','10-15','10-70','10-80']; let validStatus=['10-8','10-7','10-6','10-11','10-23','10-97','10-15','10-70','10-80'];
getUser(message.author.id).then(user => { getUser(message.author.id).then(user => {
if (user==null) return message.channel.send(`You are not logged in ${message.author}!`); if (user==null) return message.channel.send(`You are not logged in ${message.author}!`);
@@ -124,7 +132,7 @@ async function updateStatus(message, args, prefix) {
}); });
} }
async function getPrefix(message) { async getPrefix(message) {
let prefix; let prefix;
let db = await MongoClient.connect(config.mongoURI,{useUnifiedTopology:true}); let db = await MongoClient.connect(config.mongoURI,{useUnifiedTopology:true});
let dbo = db.db(config.dbo); let dbo = db.db(config.dbo);
@@ -149,6 +157,7 @@ async function getPrefix(message) {
return prefix return prefix
} }
main() {
client.on('ready', () => { client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}`); console.log(`Logged in as ${client.user.tag}`);
}); });
@@ -220,18 +229,18 @@ client.on('message', (message) => {
if (command == 'updatestatus') updateStatus(message, args, prefix); if (command == 'updatestatus') updateStatus(message, args, prefix);
if (command == 'account') account(message); if (command == 'account') account(message);
if (command == 'penalcodes') return message.channel.send('https://www.linespolice-cad.com/penal-code'); if (command == 'penalcodes') return message.channel.send('https://www.linespolice-cad.com/penal-code');
if (command == 'namedb') nameSearch(message, args);
// In dev not prod if (command == 'platedb') plateSearch(message, args);
// if (command == 'namedb') nameSearch(message, args); if (command == 'firearmdb') weaponSearch(message, args);
// if (command == 'platedb') plateSearch(message, args); if (command == 'createbolo') createBolo(message, args);
// if (command == 'firearmdb') weaponSearch(message, args); if (command == 'panic') enablePanic(message);
// if (command == 'createbolo') createBolo(message, args);
// if (command == 'panic') enablePanic(message);
// Dev Commands (not visible in help) // Dev Commands (not visible in help)
if (command == 'version') return message.channel.send(`**LPS-BOT Version : PROD-${config.version}**`) if (command == 'version') return message.channel.send(`**LPS-BOT Version : ${this.dev}-${config.version}**`)
if (command == 'whatisthemeaningoflife') message.channel.send('42'); if (command == 'whatisthemeaningoflife') message.channel.send('42');
}); });
}); });
client.login(process.env.token); client.login(this.token);
}
}
+1 -1
View File
@@ -1 +1 @@
Worker: node LPS.js Worker: node index.js
+4
View File
@@ -0,0 +1,4 @@
const Bot = require('./LPS').Bot;
client = new bot('PRODUCTION', process.env.token);
client.main()