Added Config example
This commit is contained in:
1 parent
57378d5aa5
commit
a51a9d87cf
4 files changed
+1178
-7
No files matched your search
+4
-1
@@ -2,4 +2,7 @@
|
|||||||
node_modules/*
|
node_modules/*
|
||||||
|
|
||||||
# test file
|
# test file
|
||||||
test.js
|
test.js
|
||||||
|
|
||||||
|
# Config
|
||||||
|
config.json.example
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
const MongoClient = require('mongodb').MongoClient;
|
const MongoClient = require('mongodb').MongoClient;
|
||||||
|
const io = require('socket.io-client');
|
||||||
const bcrypt = require('bcrypt');
|
const bcrypt = require('bcrypt');
|
||||||
const socket = require('socket.io');
|
|
||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const client = new Discord.Client();
|
const client = new Discord.Client();
|
||||||
const config = require('./config');
|
const config = require('./config');
|
||||||
@@ -21,6 +21,7 @@ async function newPrefix(message, n) {
|
|||||||
|
|
||||||
// Remote Login
|
// Remote Login
|
||||||
async function remoteLogin(message, args) {
|
async function remoteLogin(message, args) {
|
||||||
|
if (data.userAcc.hasOwnProperty(message.author)) return message.author.send(`You are already logged in ${message.author}!`);
|
||||||
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}!`);
|
||||||
|
|
||||||
@@ -47,6 +48,67 @@ async function remoteLogin(message, args) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function remoteLogout(message) {
|
||||||
|
if (!data.userAcc.hasOwnProperty(message.author)) return message.channel.send(`You cannot logout if your not logged in ${message.author}!`);
|
||||||
|
for (let i=0;i<Object.keys(data.userAcc).length;i++) {
|
||||||
|
if (Object.keys(data.userAcc)[i]==`<@${message.author.id}>`) {
|
||||||
|
delete data.userAcc[i];
|
||||||
|
return message.channel.send(`Succesfully logged out ${message.author}!`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getUser(message) {
|
||||||
|
if (!data.userAcc.hasOwnProperty(message.author)) return null;
|
||||||
|
for (let i=0;i<Object.keys(data.userAcc).length;i++) {
|
||||||
|
if (Object.keys(data.userAcc)[i]==`<@${message.author.id}>`) {
|
||||||
|
let db = await MongoClient.connect(config.mongoURI,{useUnifiedTopology:true});
|
||||||
|
let dbo=db.db("knoldus");
|
||||||
|
return await dbo.collection("users").findOne({"user.email":Object.values(data.userAcc)[i]}).then(user => user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkStatus(message) {
|
||||||
|
getUser(message).then(user => {
|
||||||
|
if (user==null) return message.channel.send(`You are not logged in ${message.author}!`);
|
||||||
|
return message.channel.send(`${message.author}'s status: ${user.user.dispatchStatus} | Set by: ${user.user.dispatchStatusSetBy}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function updateStatus(message, args, prefix) {
|
||||||
|
let validStatus=['10-8','10-7','10-6','10-11','10-23','10-97','10-15','10-70','10-80'];
|
||||||
|
getUser(message).then(user => {
|
||||||
|
if (user==null) return message.channel.send(`You are not logged in ${message.author}!`);
|
||||||
|
if (!validStatus.includes(args[0])) return message.channel.send(`**${args[0]}** is a Invalid Status ${message.author}! To see a list of valid statuses, use command \`${prefix}validStatus\`.`);
|
||||||
|
let onDuty=null;
|
||||||
|
let updateDuty=false;
|
||||||
|
let status = args[0]
|
||||||
|
if (args[0]=='10-41') {
|
||||||
|
onDuty=true;
|
||||||
|
updateDuty=true;
|
||||||
|
status='Online';
|
||||||
|
}
|
||||||
|
if (args[0]=='10-42') {
|
||||||
|
onDuty=false;
|
||||||
|
updateDuty=true;
|
||||||
|
status='Offline';
|
||||||
|
}
|
||||||
|
req={
|
||||||
|
userID: user._id,
|
||||||
|
status: status,
|
||||||
|
setBy: 'Self',
|
||||||
|
onDuty: onDuty,
|
||||||
|
updateDuty: updateDuty
|
||||||
|
};
|
||||||
|
const socket = io.connect('http://localhost:8080');
|
||||||
|
socket.emit('bot_update_status', req);
|
||||||
|
socket.on('bot_updated_status', (res) => {
|
||||||
|
return message.channel.send(`Succesfully updated status to **${args[0]}** ${message.author}!`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
console.log(`Logged in as ${client.user.tag}`);
|
console.log(`Logged in as ${client.user.tag}`);
|
||||||
});
|
});
|
||||||
@@ -68,6 +130,28 @@ client.on('message', (message) => {
|
|||||||
const args = message.content.slice(prefix.length).trim().split(' ');
|
const args = message.content.slice(prefix.length).trim().split(' ');
|
||||||
const command = args.shift().toLowerCase();
|
const command = args.shift().toLowerCase();
|
||||||
|
|
||||||
|
// Valid Statuses Embed
|
||||||
|
let validStatus = new Discord.MessageEmbed()
|
||||||
|
.setColor('#0099ff')
|
||||||
|
.setTitle('Lines Police CAD')
|
||||||
|
.setURL('https://www.linespolice-cad.com/')
|
||||||
|
.setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t')
|
||||||
|
.setDescription('Valid Statuses')
|
||||||
|
.addFields(
|
||||||
|
{ name: 'Statuses:', value: `
|
||||||
|
10-8 | On Duty
|
||||||
|
10-7 | Off Duty
|
||||||
|
10-6 | Busy
|
||||||
|
10-11 | Traffic Stop
|
||||||
|
10-23 | Arrive on Scene
|
||||||
|
10-97 | In Route
|
||||||
|
10-15 | Subject in Custody
|
||||||
|
10-70 | Foot Pursuit
|
||||||
|
10-80 | Vehicle Pursiut
|
||||||
|
`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// Help Embed
|
// Help Embed
|
||||||
let help = new Discord.MessageEmbed()
|
let help = new Discord.MessageEmbed()
|
||||||
.setColor('#0099ff')
|
.setColor('#0099ff')
|
||||||
@@ -81,12 +165,15 @@ client.on('message', (message) => {
|
|||||||
${prefix}ping : Responds with Pong to check Bot responce
|
${prefix}ping : Responds with Pong to check Bot responce
|
||||||
${prefix}setPrefix <new prefix> : Sets new prefix
|
${prefix}setPrefix <new prefix> : Sets new prefix
|
||||||
${prefix}login <email> <password> : Login to LPS account (DM only command)
|
${prefix}login <email> <password> : Login to LPS account (DM only command)
|
||||||
|
${prefix}logout : Logs out of your current logged in account
|
||||||
|
${prefix}validStatus : Shows list of valid statuses to updade to
|
||||||
|
${prefix}checkStatus : Checks your current status
|
||||||
|
${prefix}updateStatus <status> : Updates your status
|
||||||
`
|
`
|
||||||
},
|
}
|
||||||
{ name: '\u200B', value: '\u200B' }
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if (command == 'ping') message.channel.send('pong');
|
if (command == 'ping') message.channel.send('Pong!');
|
||||||
if (command == 'help') message.channel.send(help);
|
if (command == 'help') message.channel.send(help);
|
||||||
if (command == 'whatisthemeaningoflife') message.channel.send('42');
|
if (command == 'whatisthemeaningoflife') message.channel.send('42');
|
||||||
if (command == 'setprefix') {
|
if (command == 'setprefix') {
|
||||||
@@ -98,6 +185,10 @@ client.on('message', (message) => {
|
|||||||
if (message.channel.type=="text") return message.channel.send(`You must direct message me to login ${message.author}!`);
|
if (message.channel.type=="text") return message.channel.send(`You must direct message me to login ${message.author}!`);
|
||||||
remoteLogin(message, args);
|
remoteLogin(message, args);
|
||||||
}
|
}
|
||||||
|
if (command == 'logout') remoteLogout(message);
|
||||||
|
if (command == 'validstatus') return message.channel.send(validStatus);
|
||||||
|
if (command == 'checkstatus') checkStatus(message);
|
||||||
|
if (command == 'updatestatus') updateStatus(message, args, prefix);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.login(config.token);
|
client.login(config.token);
|
||||||
Generated
+1076
-1
File diff suppressed because it is too large.
Load diff
+3
-1
@@ -12,8 +12,10 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcrypt": "^5.0.1",
|
"bcrypt": "^5.0.1",
|
||||||
"discord.js": "^12.5.3",
|
"discord.js": "^12.5.3",
|
||||||
|
"express": "^4.17.1",
|
||||||
"mongodb": "^3.6.8",
|
"mongodb": "^3.6.8",
|
||||||
"nodemon": "^2.0.9",
|
"nodemon": "^2.0.9",
|
||||||
"socket.io": "^4.1.2"
|
"socket.io": "^4.1.2",
|
||||||
|
"socket.io-client": "^4.1.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user