Added Class for easier dev
This commit is contained in:
1 parent
9a071ea341
commit
2ff93e5010
3 files changed
+46
-33
No files matched your search
@@ -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');
|
||||||
|
|
||||||
// Updates Prefix
|
|
||||||
async function newPrefix(message, n) {
|
class Bot {
|
||||||
|
|
||||||
|
constructor(dev, token) {
|
||||||
|
this.dev = dev;
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Updates Prefix
|
||||||
|
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});
|
||||||
@@ -15,10 +23,10 @@ async function newPrefix(message, n) {
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
return message.channel.send(`The new prefix is now **\`${n}\`**`);
|
return message.channel.send(`The new prefix is now **\`${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});
|
||||||
@@ -47,9 +55,9 @@ async function remoteLogin(message, args) {
|
|||||||
return message.author.send(`Incorrect password for **${args[0]}** ${message.author}!`);
|
return message.author.send(`Incorrect password for **${args[0]}** ${message.author}!`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function remoteLogout(message) {
|
async function remoteLogout(message) {
|
||||||
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);
|
||||||
let user = await dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user);
|
let user = await dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user);
|
||||||
@@ -58,22 +66,22 @@ async function remoteLogout(message) {
|
|||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
return message.channel.send(`Succesfully logged out ${message.author}!`);
|
return message.channel.send(`Succesfully logged out ${message.author}!`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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}!`);
|
||||||
@@ -88,9 +96,9 @@ async function checkStatus(message, args) {
|
|||||||
return message.channel.send(`${message.author}, **${User.tag}'s** status: ${user.user.dispatchStatus} | Set by: ${user.user.dispatchStatusSetBy}`);
|
return message.channel.send(`${message.author}, **${User.tag}'s** status: ${user.user.dispatchStatus} | Set by: ${user.user.dispatchStatusSetBy}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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}!`);
|
||||||
@@ -122,9 +130,9 @@ async function updateStatus(message, args, prefix) {
|
|||||||
return message.channel.send(`Succesfully updated status to **${args[0]}** ${message.author}!`);
|
return message.channel.send(`Succesfully updated status to **${args[0]}** ${message.author}!`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
@@ -147,14 +155,15 @@ async function getPrefix(message) {
|
|||||||
} else prefix = guild.server.prefix;
|
} else prefix = guild.server.prefix;
|
||||||
} else prefix = config.defaultPrefix;
|
} else prefix = config.defaultPrefix;
|
||||||
return prefix
|
return prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
client.on('ready', () => {
|
main() {
|
||||||
|
client.on('ready', () => {
|
||||||
console.log(`Logged in as ${client.user.tag}`);
|
console.log(`Logged in as ${client.user.tag}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Basic Commands
|
// Basic Commands
|
||||||
client.on('message', (message) => {
|
client.on('message', (message) => {
|
||||||
getPrefix(message).then(prefix => {
|
getPrefix(message).then(prefix => {
|
||||||
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
||||||
|
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user