Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
24576ca981 | ||
|
|
6c19a50f87 | ||
|
|
c6563ca2cd | ||
|
|
5ddd430cbc | ||
|
|
4a22b36aa0 | ||
|
|
56180a7f4b | ||
|
|
3355302994 | ||
|
|
4435f0b2df | ||
|
|
358f1f560d | ||
|
|
7bfecb3624 | ||
|
|
574ead8f4a | ||
|
|
86104599a1 | ||
|
|
f6ebb43317 | ||
|
|
7366c299cc | ||
|
|
a24a616459 | ||
|
|
b396cd742b | ||
|
|
9d9a764b1d | ||
|
|
13e66b29ad | ||
|
|
2cd8185c0a | ||
|
|
4c51956f59 | ||
|
|
6dae712074 | ||
|
|
86acd5ea7a | ||
|
|
21e1eec514 | ||
|
|
83aca4b7b0 | ||
|
|
ef85183f1c | ||
|
|
39160ab3dd | ||
|
|
d7d2928aea | ||
|
|
df3ec26f13 | ||
|
|
8997b5de01 | ||
|
|
abc078eab8 | ||
|
|
a653b8d394 | ||
|
|
5dcd737189 | ||
|
|
14ea5a56c4 | ||
|
|
05930e8d33 | ||
|
|
2a8252289c | ||
|
|
db9dc35912 | ||
|
|
cb118a886f | ||
|
|
3ce08793c9 | ||
|
|
d88cbb7241 | ||
|
|
ef72b58921 | ||
|
|
56bdecc872 | ||
|
|
2e463c480a | ||
|
|
8a22560357 | ||
|
|
93dfd8c6da | ||
|
|
deb5f90654 | ||
|
|
c972d3610d | ||
|
|
00d7ccb631 | ||
|
|
f04f6ba211 | ||
|
|
481f012d6a | ||
|
|
fd811f30ab | ||
|
|
21811a18a9 | ||
|
|
7b13df2c73 | ||
|
|
a1cc29c43c | ||
|
|
4b0d89899a | ||
|
|
aa5ee4f8e3 | ||
|
|
ce905463f5 | ||
|
|
75b685cab4 | ||
|
|
418645ebd8 | ||
|
|
6245826c6f | ||
|
|
f33853e698 | ||
|
|
d6df756eca | ||
|
|
eeebd59817 | ||
|
|
88f89eae11 | ||
|
|
f456891373 | ||
|
|
0d69c6c79d | ||
|
|
9d6be863ad | ||
|
|
295744fbe0 | ||
|
|
d1d86c2e26 | ||
|
|
13fabf2839 | ||
|
|
b3db586a7f | ||
|
|
f7b8d06bd1 | ||
|
|
ec0096cdd3 | ||
|
|
66966c7fd6 | ||
|
|
6b1f010f32 | ||
|
|
62077831b4 | ||
|
|
7ab1b78de1 | ||
|
|
8e80c38255 | ||
|
|
d39e0226fc | ||
|
|
759a1032c3 | ||
|
|
424d5721b5 | ||
|
|
a0a2308270 | ||
|
|
a1edacd4db | ||
|
|
8ace046edf | ||
|
|
b07139bda9 | ||
|
|
449131e990 | ||
|
|
cd799a8974 | ||
|
|
c41849eb51 | ||
|
|
adb40b3bb8 | ||
|
|
7565a75575 | ||
|
|
e79ba906af | ||
|
|
a4025837a7 | ||
|
|
9c835a2503 | ||
|
|
2e43637d67 | ||
|
|
50fcd6900c | ||
|
|
96fc4f8fe4 | ||
|
|
9a4bd50dd6 | ||
|
|
98ea99e879 | ||
|
|
41411856f2 | ||
|
|
81732072ba | ||
|
|
47fec8ccb0 | ||
|
|
63667c30b8 | ||
|
|
8d5584d097 | ||
|
|
e1c599d3c6 | ||
|
|
9edb6b98d7 | ||
|
|
1cbe4356bc | ||
|
|
3df8bc70e8 | ||
|
|
698f04195a | ||
|
|
21b17797d7 | ||
|
|
03ee421432 | ||
|
|
4caccd74d4 | ||
|
|
d9855048c6 | ||
|
|
0bd83dad87 | ||
|
|
dcbaf23828 | ||
|
|
ee23d59a44 | ||
|
|
a8f4785478 | ||
|
|
5242344db3 | ||
|
|
495c4755ae | ||
|
|
441bb0672c | ||
|
|
76467288f5 | ||
|
|
cb22a8fe80 | ||
|
|
d116ea9c8c | ||
|
|
3e2fe386c3 | ||
|
|
68120d1e60 | ||
|
|
6cbd981a00 | ||
|
|
5a8753357e | ||
|
|
6e6dbd2c3b | ||
|
|
55912cb29e | ||
|
|
2c1d15cfc4 | ||
|
|
0495577b3c | ||
|
|
d0cb22b54e | ||
|
|
19cf2a4d8f | ||
|
|
64efe3f772 | ||
|
|
495c356d41 | ||
|
|
80c065c408 | ||
|
|
d3d5f94df2 | ||
|
|
e8bb22b69f | ||
|
|
57522a03ad | ||
|
|
1a4d130ad9 | ||
|
|
c37133211c | ||
|
|
1da3f590e2 | ||
|
|
a78e1cdd77 | ||
|
|
2ff1aa5153 | ||
|
|
dd1db5c9c9 | ||
|
|
7838cf3fbb | ||
|
|
9f75974b7e | ||
|
|
7c8a339e27 | ||
|
|
0b312947f1 | ||
|
|
c09484f617 | ||
|
|
13e830e439 | ||
|
|
7bab3836f7 | ||
|
|
c4644ce44d | ||
|
|
4f4de80ed7 | ||
|
|
02c0e0c554 | ||
|
|
d745ec29ad | ||
|
|
d0b8c802d1 | ||
|
|
f54dd72317 | ||
|
|
65c5f88e94 | ||
|
|
60630c77e6 | ||
|
|
79db375eba | ||
|
|
dc55d3876c | ||
|
|
7119d01096 | ||
|
|
6a1d1bf167 | ||
|
|
ad7bd3e8b7 | ||
|
|
44fae74f40 | ||
|
|
3872a5d242 | ||
|
|
1b56608d07 | ||
|
|
f174e603a3 | ||
|
|
2a300a2bb6 | ||
|
|
a15a598459 | ||
|
|
5960153618 | ||
|
|
267eab304d | ||
|
|
9aa714a7c7 | ||
|
|
3df5e4d617 | ||
|
|
1c3a5ae83a | ||
|
|
8dac1d4262 |
No files matched your search
@@ -0,0 +1,6 @@
|
||||
# MongoDB connection URI as set in police-cad .env
|
||||
dbo=knoldus
|
||||
mongoURI=mongodb://localhost/knoldus
|
||||
|
||||
# Discord Bot Token
|
||||
token=
|
||||
@@ -0,0 +1,24 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Use command.....
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
+4
-4
@@ -1,8 +1,8 @@
|
||||
# dependencies
|
||||
node_modules/*
|
||||
|
||||
# test file
|
||||
test.js
|
||||
# logs
|
||||
logs/*
|
||||
|
||||
# Dev version
|
||||
dev.js
|
||||
# environment variables
|
||||
.env
|
||||
@@ -1,490 +0,0 @@
|
||||
const MongoClient = require('mongodb').MongoClient;
|
||||
const randomstring = require('randomstring');
|
||||
const io = require('socket.io-client');
|
||||
const Discord = require('discord.js');
|
||||
const client = new Discord.Client();
|
||||
|
||||
class Bot {
|
||||
|
||||
constructor(dev, token, config) {
|
||||
this.dev = dev;
|
||||
this.token = token;
|
||||
this.config = require(config);
|
||||
this.connectMongo();
|
||||
}
|
||||
|
||||
async connectMongo() {
|
||||
this.db = await MongoClient.connect(this.config.mongoURI,{useUnifiedTopology:true});
|
||||
this.dbo = this.db.db(this.config.dbo);
|
||||
}
|
||||
|
||||
// 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].length<1) return message.channel.send('Your new prefix must be \`1\` character!')
|
||||
this.dbo.collection("prefixes").updateOne({"server.serverID":message.guild.id},{$set:{"server.prefix":n[0]}},function(err, res) {
|
||||
if (err) throw err;
|
||||
message.channel.send(`The new prefix is now **\`${n}\`**`);
|
||||
});
|
||||
}
|
||||
|
||||
// Remote Login
|
||||
async remoteLogin(message, args) {
|
||||
let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user);
|
||||
if (user) return message.author.send(`You are already logged in ${message.author}! Use \`?logout\` to logout or \`?account\` to see your logged in account.`);
|
||||
if (args.length==0) return message.author.send(`You must provide a **email** and **login token** ${message.author}!`);
|
||||
if (!args[0]==null||!args[0]==undefined&&args[1]==null||args[1]==undefined) return message.author.send(`You must provide a **login token** ${message.author}!`);
|
||||
user = await this.dbo.collection("users").findOne({"user.email":args[0]}).then(user => user);
|
||||
if (user==null||user==undefined) return message.author.send(`Cannot find the email **${args[0]}** ${message.author}!`);
|
||||
|
||||
// Check discord Login Token
|
||||
if (args[1]==user.user.discordLoginToken) {
|
||||
// Modify user to include user.user.discord
|
||||
let discord = {
|
||||
id: message.author.id,
|
||||
username: message.author.username,
|
||||
discriminator: message.author.discriminator
|
||||
}
|
||||
let newToken = randomstring.generate(12);
|
||||
this.dbo.collection("users").updateOne(
|
||||
{
|
||||
"user.email": args[0]
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
"user.discord": discord,
|
||||
"user.discordLoginToken": newToken
|
||||
}
|
||||
}, function(err,res) {
|
||||
if (err) throw err;
|
||||
return message.author.send(`Logged in as **${user.user.username}** ${message.author}!`);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
return message.author.send(`Incorrect login token ${message.author}! Try again or Regenerate your Discord Login Token.`);
|
||||
}
|
||||
}
|
||||
|
||||
async remoteLogout(message) {
|
||||
let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user);
|
||||
if (!user) return message.channel.send(`You cannot logout if your not logged in ${message.author}!`);
|
||||
this.dbo.collection("users").updateOne({"user.discord.id":message.author.id},{$unset:{"user.discord":""}},function(err,res) {
|
||||
if (err) throw err;
|
||||
message.channel.send(`Succesfully logged out ${message.author}!`);
|
||||
});
|
||||
}
|
||||
|
||||
async account(message) {
|
||||
let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user);
|
||||
if (user==null) return message.channel.send(`You are not logged in ${message.author}!`);
|
||||
message.author.send(`${message.author} Logged in as **${user.user.username}** | **${user.user.email}**`);
|
||||
}
|
||||
|
||||
async nameSearch(message, args) {
|
||||
let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user);
|
||||
if (!user) return message.channel.send(`You are not logged in ${message.author}!`);
|
||||
let data;
|
||||
if (user.user.activeCommunity=='' || user.user.activeCommunity==null) {
|
||||
if (args.length==0) return message.channel.send(`You must provide a **First Name**, **Last Name** and **DOB**(mm/dd/yyyy) ${message.author}!`);
|
||||
if (args.length==1) return message.channel.send(`You're missing a **Last Name** and **DOB**(mm/dd/yyyy) ${message.author}!`);
|
||||
if (args.length==2) return message.channel.send(`You're missing a **DOB**(mm/dd/yyyy) ${message.author}!`);
|
||||
}
|
||||
if (args.length==0) return message.channel.send(`You must provide a **First Name** and **Last Name** ${message.author}!`);
|
||||
if (args.length==1) return message.channel.send(`You're missing a **Last Name** ${message.author}!`);
|
||||
|
||||
if (user.user.activeCommunity=='' || user.user.activeCommunity==null) {
|
||||
data = {
|
||||
user: user,
|
||||
query: {
|
||||
firstName: args[0],
|
||||
lastName: args[1],
|
||||
dateOfBirth: args[2],
|
||||
activeCommunityID: user.user.activeCommunity
|
||||
}
|
||||
}
|
||||
} else {
|
||||
data = {
|
||||
user: user,
|
||||
query: {
|
||||
firstName: args[0],
|
||||
lastName: args[1],
|
||||
activeCommunityID: user.user.activeCommunity
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const socket = io.connect(this.config.socket);
|
||||
socket.emit("bot_name_search", data);
|
||||
socket.on("bot_name_search_results", results => {
|
||||
|
||||
if (results.user._id==user._id) {
|
||||
if (results.civilians.length == 0) {
|
||||
return message.channel.send(`Name **${args[0]} ${args[1]}** not found ${message.author}`);
|
||||
}
|
||||
|
||||
for (let i = 0; i < results.civilians.length; i++) {
|
||||
// Get Drivers Licence Status
|
||||
let licenceStatus;
|
||||
if (results.civilians[i].civilian.licenseStatus == 1) licenceStatus = 'Valid';
|
||||
if (results.civilians[i].civilian.licenceStatus == 2) licenceStatus = 'Revoked';
|
||||
if (results.civilians[i].civilian.licenceStatus == 3) licenceStatus = 'None';
|
||||
// Get Firearm Licence Status
|
||||
let firearmLicence = results.civilians[i].civilian.firearmLicense;
|
||||
if (firearmLicence == undefined || firearmLicence == null) firearmLicence = 'None';
|
||||
if (firearmLicence == '2') firearmLicence = 'Valid';
|
||||
if (firearmLicence == '3') firearmLicence = 'Revoked';
|
||||
let nameResult = new Discord.MessageEmbed()
|
||||
.setColor('#0099ff')
|
||||
.setTitle(`**${results.civilians[i].civilian.firstName} ${results.civilians[i].civilian.lastName} | ${results.civilians[i]._id}**`)
|
||||
.setURL('https://discord.gg/jgUW656v2t')
|
||||
.setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t')
|
||||
.setDescription('Name Search Results')
|
||||
.addFields(
|
||||
{ name: `**First Name**`, value: `**${results.civilians[i].civilian.firstName}**`, inline: true },
|
||||
{ name: `**Last Name**`, value: `**${results.civilians[i].civilian.lastName}**`, inline: true },
|
||||
{ name: `**DOB**`, value: `**${results.civilians[i].civilian.birthday}**`, inline: true },
|
||||
{ name: `**Drivers License**`, value: `**${licenceStatus}**`, inline: true },
|
||||
{ name: `**Firearm Licence**`, value: `**${firearmLicence}**`, inline: true },
|
||||
{ name: `**Gender**`, value: `**${results.civilians[i].civilian.gender}**`, inline: true }
|
||||
)
|
||||
// Check Other details
|
||||
let address = results.civilians[i].civilian.address;
|
||||
let occupation = results.civilians[i].civilian.occupation;
|
||||
let height = results.civilians[i].civilian.height;
|
||||
let weight = results.civilians[i].civilian.weight;
|
||||
let eyeColor = results.civilians[i].civilian.eyeColor;
|
||||
let hairColor = results.civilians[i].civilian.hairColor;
|
||||
if (address != null && address != undefined && address != '') nameResult.addFields({ name: `**Address**`, value: `**${address}**`, inline: true });
|
||||
if (occupation != null && occupation != undefined && occupation != '') nameResult.addFields({ name: `**Occupation**`, value: `**${occupation}**`, inline: true });
|
||||
if (height!=null&&height!=undefined&&height!="NaN"&&height!='') {
|
||||
if (results.civilians[i].civilian.heightClassification=='imperial') {
|
||||
let ft = Math.floor(height/12);
|
||||
let inch = height%12;
|
||||
nameResult.addFields({ name: '**Height**', value: `**${ft}'${inch}"**`, inline: true });
|
||||
} else {
|
||||
nameResult.addFields({ name: '**Height**', value: `**${height}cm**`, inline: true });
|
||||
}
|
||||
}
|
||||
if (weight!=null&&weight!=undefined&&weight!='') {
|
||||
if (results.civilians[i].civilian.weightClassification=='imperial') {
|
||||
nameResult.addFields({ name: '**Weight**', value: `**${weight}lbs.**`, inline: true });
|
||||
} else {
|
||||
nameResult.addFields({ name: '**Weight**', value: `**${weight}kgs.**`, inline: true });
|
||||
}
|
||||
}
|
||||
if (eyeColor!=null&&eyeColor!=undefined&&eyeColor!='') nameResult.addFields({name:'**Eye Color**',value:`**${eyeColor}**`,inline:true});
|
||||
if (hairColor!=null&&hairColor!=undefined&&hairColor!='') nameResult.addFields({name:'**Hair Color**',value:`**${hairColor}**`,inline:true});
|
||||
nameResult.addFields({name:'**Organ Donor**',value:`**${results.civilians[i].civilian.organDonor}**`,inline:true});
|
||||
nameResult.addFields({name:'**Veteran**',value:`**${results.civilians[i].civilian.veteran}**`,inline:true});
|
||||
message.channel.send(nameResult);
|
||||
}
|
||||
}
|
||||
socket.disconnect();
|
||||
});
|
||||
}
|
||||
|
||||
async plateSearch(message, args) {
|
||||
let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user);
|
||||
if (!user) return message.channel.send(`You are not logged in ${message.author}!`);
|
||||
if (args.length==0) return message.channel.send(`You are missing a **Plate #** ${message.author}`);
|
||||
let data = {
|
||||
user: user,
|
||||
query: {
|
||||
plateNumber: args[0],
|
||||
activeCommunityID: user.user.activeCommunity
|
||||
}
|
||||
}
|
||||
const socket = io.connect(this.config.socket);
|
||||
socket.emit('bot_plate_search', data);
|
||||
socket.on('bot_plate_search_results', results => {
|
||||
|
||||
if (results.user._id==user._id) {
|
||||
if (results.vehicles.length == 0) {
|
||||
return message.channel.send(`Plate Number **${args[0]}** not found ${message.author}`);
|
||||
}
|
||||
|
||||
for (let i = 0; i < results.vehicles.length; i++) {
|
||||
let plateResult = new Discord.MessageEmbed()
|
||||
.setColor('#0099ff')
|
||||
.setTitle(`**${results.vehicles[i].vehicle.plate} | ${results.vehicles[i]._id}**`)
|
||||
.setURL('https://discord.gg/jgUW656v2t')
|
||||
.setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t')
|
||||
.setDescription('Plate Search Results')
|
||||
.addFields(
|
||||
{ name: `**Plate #**`, value: `**${results.vehicles[i].vehicle.plate}**`, inline: true },
|
||||
{ name: `**Vin #**`, value: `**${results.vehicles[i].vehicle.vin}**`, inline: true },
|
||||
{ name: `**Model**`, value: `**${results.vehicles[i].vehicle.model}**`, inline: true },
|
||||
{ name: `**Color**`, value: `**${results.vehicles[i].vehicle.color}**`, inline: true },
|
||||
{ name: `**Owner**`, value: `**${results.vehicles[i].vehicle.registeredOwner}**`, inline: true },
|
||||
)
|
||||
// Other details
|
||||
let validRegistration = results.vehicles[i].vehicle.validRegistration;
|
||||
let validInsurance = results.vehicles[i].vehicle.validInsurance;
|
||||
let stolen = results.vehicles[i].vehicle.isStolen;
|
||||
if (validRegistration=='1') plateResult.addFields({ name: `**Registration**`, value: `**Valid**`, inline: true });
|
||||
if (validRegistration=='2') plateResult.addFields({ name: `**Registration**`, value: `**InValid**`, inline: true });
|
||||
if (validInsurance=='1') plateResult.addFields({ name: `**Insurance**`, value: `**Valid**`, inline: true });
|
||||
if (validInsurance=='2') plateResult.addFields({ name: `**Insurance**`, value: `**InValid**`, inline: true });
|
||||
if (stolen=='1') plateResult.addFields({ name: `**Stolen**`, value: `**No**`, inline: true });
|
||||
if (stolen=='2') plateResult.addFields({ name: `**Stolen**`, value: `**Yes**`, inline: true });
|
||||
message.channel.send(plateResult);
|
||||
}
|
||||
}
|
||||
socket.disconnect();
|
||||
});
|
||||
}
|
||||
|
||||
async firearmSearch(message, args) {
|
||||
let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user);
|
||||
if (!user) return message.channel.send(`You are not logged in ${message.author}!`);
|
||||
if (args.length==0) return message.channel.send(`You are missing a **Serial Number** ${message.author}`);
|
||||
let data = {
|
||||
user: user,
|
||||
query: {
|
||||
serialNumber: args[0],
|
||||
activeCommunityID: user.user.activeCommunity
|
||||
}
|
||||
}
|
||||
const socket = io.connect(this.config.socket);
|
||||
socket.emit('bot_firearm_search', data);
|
||||
socket.on('bot_firearm_search_results', results => {
|
||||
if (results.user._id==user._id) {
|
||||
if (results.firearms.length==0) {
|
||||
return message.channel.send(`No Firearms found ${message.author}`);
|
||||
}
|
||||
|
||||
for (let i = 0; i < results.firearms.length; i++) {
|
||||
let firearmResult = new Discord.MessageEmbed()
|
||||
.setColor('#0099ff')
|
||||
.setTitle(`**${results.firearms[i].firearm.serialNumber} | ${results.firearms[i]._id}**`)
|
||||
.setURL('https://discord.gg/jgUW656v2t')
|
||||
.setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t')
|
||||
.setDescription('Firearm Search Results')
|
||||
.addFields(
|
||||
{ name: `**Serial Number**`, value: `**${results.firearms[i].firearm.serialNumber}**`, inline: true },
|
||||
{ name: `**Type**`, value: `**${results.firearms[i].firearm.weaponType}**`, inline: true },
|
||||
{ name: `**Owner**`, value: `**${results.firearms[i].firearm.registeredOwner}**`, inline: true },
|
||||
)
|
||||
// Other details
|
||||
let isStolen = results.firearms[i].firearm.isStolen;
|
||||
if (isStolen=="false"||isStolen==false) firearmResult.addFields({name:`**Stolen**`,value:'**No**',inline: true});
|
||||
if (isStolen=="true"||isStolen==true) firearmResult.addFields({name:`**Stolen**`,value:'**Yes**',inline: true});
|
||||
message.channel.send(firearmResult);
|
||||
}
|
||||
}
|
||||
socket.disconnect();
|
||||
});
|
||||
}
|
||||
|
||||
async checkStatus(message, args) {
|
||||
if (args.length==0) {
|
||||
let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user);
|
||||
if (!user) return message.channel.send(`You are not logged in ${message.author}!`);
|
||||
message.channel.send(`${message.author}'s status: ${user.user.dispatchStatus} | Set by: ${user.user.dispatchStatusSetBy}`);
|
||||
} else {
|
||||
let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user);
|
||||
if (!user) return message.channel.send(`Cannot find **${args[0]}** ${message.author}!`);
|
||||
// This lame line of code to get username without ping on discord
|
||||
const User = client.users.cache.get(args[0].replace('<@!', '').replace('>', ''));
|
||||
message.channel.send(`${message.author}, **${User.tag}'s** status: ${user.user.dispatchStatus} | Set by: ${user.user.dispatchStatusSetBy}`);
|
||||
}
|
||||
}
|
||||
|
||||
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', 'Panic', '10-41', '10-42'];
|
||||
let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user);
|
||||
if (!user) return message.channel.send(`You are not logged in ${message.author}!`);
|
||||
if (args.length==0) return message.channel.send(`You must provide a new status ${message.author} | To see a list of valid statuses, use command \`${prefix}validStatus\`.`);
|
||||
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';
|
||||
}
|
||||
let req={
|
||||
userID: user._id,
|
||||
status: status,
|
||||
setBy: 'Self',
|
||||
onDuty: onDuty,
|
||||
updateDuty: updateDuty
|
||||
};
|
||||
const socket = io.connect(this.config.socket);
|
||||
socket.emit('bot_update_status', req);
|
||||
socket.on('bot_updated_status', (res) => {
|
||||
message.channel.send(`Succesfully updated status to **${args[0]}** ${message.author}!`);
|
||||
socket.disconnect();
|
||||
});
|
||||
}
|
||||
|
||||
async enablePanic(message) {
|
||||
let user = await this.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user);
|
||||
if (!user) return message.channel.send(`You are not logged in ${message.author}!`);
|
||||
// If panic isn't enabled, enable panic
|
||||
if (user.user.dispatchStatus!='Panic') {
|
||||
this.updateStatus(message, ['Panic'], null);
|
||||
let myReq = {
|
||||
userID: user._id,
|
||||
userUsername: user.user.username,
|
||||
activeCommunity: user.user.activeCommunity
|
||||
}
|
||||
const socket = io.connect(this.config.socket);
|
||||
socket.emit('botping');
|
||||
socket.emit('panic_button_update', myReq);
|
||||
message.channel.send(`Enabled Panic ${message.author}!`);
|
||||
// If panic is enabled, set status to Online (panic off)
|
||||
} else if (user.user.dispatchStatus=='Panic') {
|
||||
let myReq = {
|
||||
userID: user._id,
|
||||
communityID: user.user.activeCommunity
|
||||
};
|
||||
const socket = io.connect(this.config.socket);
|
||||
socket.emit('clear_panic', myReq);
|
||||
|
||||
let myUpdateReq = {
|
||||
userID: user._id,
|
||||
status: '10-8',
|
||||
setBy: 'System',
|
||||
onDuty: null,
|
||||
updateDuty: false
|
||||
};
|
||||
socket.emit('update_status', myUpdateReq);
|
||||
message.channel.send(`Disabled Panic ${message.author} and set status to 10-8.`);
|
||||
}
|
||||
}
|
||||
|
||||
async getPrefix(message) {
|
||||
let prefix;
|
||||
if (message.channel.type!="dm") {
|
||||
let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild);
|
||||
|
||||
// If not prefix, generate server default
|
||||
if (!guild) {
|
||||
let newGuild = {
|
||||
server: {
|
||||
serverID: message.guild.id,
|
||||
prefix: this.config.defaultPrefix
|
||||
}
|
||||
}
|
||||
this.dbo.collection("prefixes").insertOne(newGuild, function(err, res) {
|
||||
if (err) throw err;
|
||||
});
|
||||
prefix = newGuild.server.serverID;
|
||||
} else prefix = guild.server.prefix;
|
||||
} else prefix = this.config.defaultPrefix;
|
||||
return prefix
|
||||
}
|
||||
|
||||
main() {
|
||||
client.on('ready', () => {
|
||||
console.log(`Logged in as ${client.user.tag}`);
|
||||
});
|
||||
|
||||
// Basic Commands
|
||||
client.on('message', (message) => {
|
||||
this.getPrefix(message).then(prefix => {
|
||||
if (!message.content.startsWith(prefix) || message.author.bot) return;
|
||||
|
||||
const args = message.content.slice(prefix.length).trim().split(' ');
|
||||
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
|
||||
let help = new Discord.MessageEmbed()
|
||||
.setColor('#0099ff')
|
||||
.setTitle('**Commands:**')
|
||||
.setURL('https://discord.gg/jgUW656v2t')
|
||||
.setAuthor('LPS Website Support', 'https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-server.png', 'https://discord.gg/jgUW656v2t')
|
||||
.setDescription('Lines Police CAD Bot Commands')
|
||||
.addFields(
|
||||
{ name: `**${prefix}help**`, value: 'Displays this help page', inline: true },
|
||||
{ name: `**${prefix}ping**`, value: 'Responds with Pong to check Bot responce', inline: true },
|
||||
{ name: `**${prefix}setPrefix** <new prefix>`, value: 'Sets new prefix (Admin only command)', inline: true },
|
||||
{ name: `**${prefix}login** <email> <login token>`, value: 'Login to LPS account (DM only command)', inline: true },
|
||||
{ name: `**${prefix}logout**`, value: 'Logs out of your current logged in account', inline: true },
|
||||
{ name: `**${prefix}validStatus**`, value: 'Shows list of valid statuses to updade to', inline: true },
|
||||
{ name: `**${prefix}checkStatus** <user>`, value: 'Leave user blank to check own status', inline: true },
|
||||
{ name: `**${prefix}updateStatus** <status>`, value: 'Updates your status', inline: true },
|
||||
{ name: `**${prefix}account**`, value: 'returns logged in account', inline: true },
|
||||
{ name: `**${prefix}penalCodes**`, value: 'Provides Link to penal codes', inline: true },
|
||||
{ name: `**${prefix}namedb <firstName> <lastName> <dob>**`, value: 'Searches in your community for name (dob only required if not in a community)', inline: true },
|
||||
{ name: `**${prefix}platedb <licence plate #>**`, value: 'Searches in your community for Vehicles with the given Licence plate #', inline: true },
|
||||
{ name: `**${prefix}firearmdb <Serial #>**`, value: 'Searches for Firearms with the given Serial #', inline: true },
|
||||
{ name: `**${prefix}panic**`, value: 'Enables or disables your panic button', inline: true }
|
||||
)
|
||||
|
||||
if (command == 'ping') message.channel.send('Pong!');
|
||||
if (command == 'help') message.channel.send(help);
|
||||
if (command == 'setprefix') {
|
||||
if (message.channel.type=="dm") return message.author.send(`You cannot set a prefix in a dm ${message.author}!`);
|
||||
if(!message.member.hasPermission(["ADMINISTRATOR","MANAGE_GUILD"])) return message.channel.send(`You don't have permission to used this command ${message.author}`);
|
||||
this.newPrefix(message, args);
|
||||
}
|
||||
// Login
|
||||
if (command == 'login') {
|
||||
if (message.channel.type=="text") return message.channel.send(`You must direct message me to use this command ${message.author}!`);
|
||||
this.remoteLogin(message, args);
|
||||
}
|
||||
if (command == 'logout') this.remoteLogout(message);
|
||||
if (command == 'validstatus') message.channel.send(validStatus);
|
||||
if (command == 'checkstatus') this.checkStatus(message, args);
|
||||
if (command == 'updatestatus') this.updateStatus(message, args, prefix);
|
||||
if (command == 'account') this.account(message);
|
||||
if (command == 'penalcodes') return message.channel.send('https://www.linespolice-cad.com/penal-code');
|
||||
if (command == 'namedb') this.nameSearch(message, args);
|
||||
if (command == 'platedb') this.plateSearch(message, args);
|
||||
if (command == 'firearmdb') this.firearmSearch(message, args);
|
||||
if (command == 'panic') this.enablePanic(message);
|
||||
|
||||
// Disabled for dev
|
||||
// if (command == 'createbolo') this.createBolo(message, args);
|
||||
|
||||
// Dev Commands (not visible in help) && easter egg commands
|
||||
if (command == 'version') message.channel.send(`**LPS-BOT Version : ${this.dev}-${this.config.version}**`)
|
||||
if (command == 'whatisthemeaningoflife') message.channel.send('42');
|
||||
if (command == 'whatareyou' || command == 'whoareyou') message.channel.send('Im your friendly neighborhood Lines Police CAD Bot');
|
||||
if (command == 'whocreatedyou') message.channel.send('Lines Police CAD Developer McDazzzled | https://github.com/SowinskiBraeden');
|
||||
if (command == 'pingserver') {
|
||||
const socket = io.connect(this.config.socket);
|
||||
socket.emit('botping', {message:'hello there'});
|
||||
socket.on('botpong', (data) => {
|
||||
console.log(data);
|
||||
socket.disconnect();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
client.login(this.token);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {Bot};
|
||||
@@ -0,0 +1,12 @@
|
||||
# Lines Police CAD Discord Bot
|
||||
|
||||
|
||||
> [!WARNING]
|
||||
>
|
||||
> Migrating to Organization repository.
|
||||
> ---
|
||||
>
|
||||
> ***Notice:*** This repository will transition to read-only mode starting on **November 7, 2024**.
|
||||
>
|
||||
> All new commits, issues, feature requests and more will take place on the organization repository.
|
||||
> Visit our [organization!](https://github.com/Lines-Police-CAD/)
|
||||
@@ -0,0 +1,6 @@
|
||||
const LinesPoliceCadBot = require('./structures/LinesPoliceCadBot');
|
||||
const { GatewayIntentBits } = require('discord.js');
|
||||
const config = require('./config/config');
|
||||
|
||||
let client = new LinesPoliceCadBot({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages] }, config);
|
||||
client.build()
|
||||
@@ -0,0 +1,32 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "account",
|
||||
description: "View connected Lines Police CAD account",
|
||||
usage: "",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||
if (user==null) return interaction.send({ content: `You are not logged in.` });
|
||||
client.users.fetch(interaction.member.user.id)
|
||||
.then(duser => duser.send(`<@${interaction.member.user.id}> Logged in as **${user.user.username}** | **${user.user.email}**`).catch(err => {client.log(err)}))
|
||||
.catch(err => {client.log(err)});
|
||||
return interaction.send({ content: 'Your account details have been sent in your dm.' });
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "channels",
|
||||
description: "View a list of allowed channels",
|
||||
usage: "",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").MessageCreate} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild);
|
||||
if (!GuildDB.customChannelStatus) {
|
||||
return interaction.send({ content: 'There are no channels set for the bot.' });
|
||||
}
|
||||
|
||||
let channels = ``;
|
||||
for (let i = 0; i < guild.server.allowedChannels.length; i++) {
|
||||
if (!client.exists(guild.server.allowedChannels[i])) continue;
|
||||
else channels += `\n<#${guild.server.allowedChannels[i]}>`;
|
||||
}
|
||||
let channelsEmbed = new EmbedBuilder()
|
||||
.setColor('#0099ff')
|
||||
.setDescription('**Allowed Channels to use the Bot**')
|
||||
.addFields(
|
||||
{ name: `There are currently ${guild.server.allowedChannels.length} allowed channels.`, value: `Channels:${channels}`, inline: true },
|
||||
)
|
||||
.setFooter({ text: 'LPS Website Support', iconURL: client.config.IconURL, proxyIconURL: 'https://discord.gg/jgUW656v2t' })
|
||||
return interaction.send({ embeds: [channelsEmbed] });
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "checkstatus",
|
||||
description: "Check your own or another officer status",
|
||||
usage: "[user]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "user",
|
||||
description: "Discord Username",
|
||||
value: "user",
|
||||
type: 6,
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles);
|
||||
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
||||
|
||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||
if (!user) return interaction.send({ content: `You are not logged in.` });
|
||||
if (user.user.activeCommunity == null) return interaction.send({ content: `You must join a community to use this command.` });
|
||||
if (!client.exists(args)) {
|
||||
return interaction.send({ content: `<@${interaction.member.user.id}>'s status: \`${user.user.dispatchStatus}\` | Set by: \`${user.user.dispatchStatusSetBy}\`` });
|
||||
} else {
|
||||
let targetUserID = args[0].value.replace('<@!', '').replace('>', '');
|
||||
let targetUser = await client.dbo.collection("users").findOne({"user.discord.id":targetUserID}).then(user => user);
|
||||
// This lame line of code to get username without ping on discord
|
||||
const User = client.users.cache.get(targetUserID);
|
||||
if (!targetUser) return interaction.send({ content: `Cannot find **${args[0].value}** <@${interaction.member.user.id}>` });
|
||||
if (targetUser.user.activeCommunity!=user.user.activeCommunity) {
|
||||
return interaction.send({ content: `You are not in the same community as \`${User.tag}\` <@${interaction.member.user.id}>` });
|
||||
}
|
||||
return interaction.send({ content: `<@${interaction.member.user.id}>, \`${User.tag}'s\` status: \`${targetUser.user.dispatchStatus}\` | Set by: \`${targetUser.user.dispatchStatusSetBy}\`` });
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const ObjectId = require('mongodb').ObjectId;
|
||||
|
||||
module.exports = {
|
||||
name: "community",
|
||||
description: "Check active community",
|
||||
usage: "",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").MessageCreate} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||
if (!user) return interaction.send({ content: `You are not logged in.` });
|
||||
if (user.user.activeCommunity==null) return interaction.send({ content: `You are not in a community.` });
|
||||
let community = await client.dbo.collection("communities").findOne({_id:ObjectId(user.user.activeCommunity)}).then(community => community);
|
||||
if (!community) return interaction.send({ content: `Community not found.` });
|
||||
return interaction.send({ content: `You are in the community \`${community.community.name}\`` });
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "connect_account",
|
||||
description: "Connect your Discord Account to the Lines Police CAD Database",
|
||||
usage: "",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
return interaction.send({ content: 'Login from Lines Police CAD `account_management` https://www.linespolice-cad.com/' });
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const io = require('socket.io-client');
|
||||
|
||||
module.exports = {
|
||||
name: "debug",
|
||||
description: "Debug for bot admin",
|
||||
usage: "command",
|
||||
debug: true,
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "command",
|
||||
description: "The debug command to execute",
|
||||
value: "command",
|
||||
type: 3,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "consoleoutput",
|
||||
description: "Output debug messages to console (deault=false)",
|
||||
value: "consoleoutput",
|
||||
type: 5,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (!client.config.Admins.includes(interaction.member.user.id)) return;
|
||||
|
||||
if (args.length==0) return message.channel.send({ content: 'Debug Error: Provide a debug command' });
|
||||
if (!client.exists(args[0].value)) return interaction.send({ content: 'Debug Error: Provide a valid debug command' });
|
||||
|
||||
let debugConsole = args[1].value;
|
||||
|
||||
let command = args[0].value.toLowerCase();
|
||||
|
||||
if (command == 'server' || args[0] == 'guild') {
|
||||
if (debugConsole) client.log("Debug: Guild >> ");console.debug(GuildDB);
|
||||
return interaction.send({ content: "Debug: guild >> read log output" })
|
||||
|
||||
} else if (command == "interaction") {
|
||||
if (debugConsole) {
|
||||
client.log("Debug: interaction >> ");
|
||||
console.debug(interaction);
|
||||
}
|
||||
return interaction.send({ content: "Debug: interaction >> read log output" });
|
||||
|
||||
} else if (command == "message") {
|
||||
return interaction.send({ content: `Use command with prefix to debug \`message\`` });
|
||||
|
||||
} else if (command == "pingserver") {
|
||||
const socket = io.connect(client.config.socket);
|
||||
socket.emit('botping', {message:'hello there'});
|
||||
socket.on('botpong', (data) => {
|
||||
if (debugConsole) client.log('Debug: Socket responded')
|
||||
socket.disconnect();
|
||||
return interaction.send({ content: `Debug: Socket responded` })
|
||||
});
|
||||
|
||||
} else if (command == "apicheck") {
|
||||
// TODO: Make axios call to api and get api health
|
||||
return interaction.send({ content: 'Debug Notice: \`apicheck\` is currently unavailable' });
|
||||
|
||||
} else {
|
||||
return interaction.send({ content: 'Debug Error: Provide a valid debug command' });
|
||||
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "disconnect_account",
|
||||
description: "Disconnect your Discord account from the Lines Police CAD Database",
|
||||
usage: "",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||
if (!user) return interaction.send({ content: `You cannot logout if your not logged in.` });
|
||||
client.dbo.collection("users").updateOne({"user.discord.id":interaction.member.user.id},{$unset:{"user.discord":""}, $set:{"user.discordConnected":false}},function(err,res) {
|
||||
if (err) throw err;
|
||||
return interaction.send({ content: `Succesfully disconnected you Discord account.` });
|
||||
});
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const io = require('socket.io-client');
|
||||
|
||||
module.exports = {
|
||||
name: "firearmsearch",
|
||||
description: "Search registered firearms",
|
||||
usage: "[Serial #]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "serialnumber",
|
||||
description: "Firearms's serial number",
|
||||
value: "serialnumber",
|
||||
type: 3,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles);
|
||||
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
||||
|
||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||
if (!user) return interaction.send({ content: `You are not logged in.` });
|
||||
let data = {
|
||||
user: user,
|
||||
query: {
|
||||
serialNumber: args[0].value,
|
||||
activeCommunityID: user.user.activeCommunity
|
||||
}
|
||||
}
|
||||
const socket = io.connect(client.config.socket);
|
||||
socket.emit('bot_firearm_search', data);
|
||||
socket.on('bot_firearm_search_results', results => {
|
||||
if (results.user._id==user._id) {
|
||||
if (results.firearms.length==0) {
|
||||
return interaction.send({ content: `No Firearms found <@${interaction.member.user.id}>` });
|
||||
}
|
||||
|
||||
for (let i = 0; i < results.firearms.length; i++) {
|
||||
let firearmResult = new EmbedBuilder()
|
||||
.setColor('#0099ff')
|
||||
.setTitle(`**${results.firearms[i].firearm.serialNumber} | ${results.firearms[i]._id}**`)
|
||||
.setURL('https://discord.gg/jgUW656v2t')
|
||||
.setAuthor({ name: 'LPS Website Support', iconURL: client.config.IconURL, url: 'https://discord.gg/jgUW656v2t' })
|
||||
.setDescription('Firearm Search Results')
|
||||
.addFields(
|
||||
{ name: `**Serial Number**`, value: `\`${results.firearms[i].firearm.serialNumber}\``, inline: true },
|
||||
{ name: `**Type**`, value: `\`${results.firearms[i].firearm.weaponType}\``, inline: true },
|
||||
{ name: `**Owner**`, value: `\`${results.firearms[i].firearm.registeredOwner}\``, inline: true },
|
||||
)
|
||||
// Other details
|
||||
let isStolen = results.firearms[i].firearm.isStolen;
|
||||
if (isStolen=="false"||isStolen==false) firearmResult.addFields({name:`**Stolen**`,value:'\`No\`',inline: true});
|
||||
if (isStolen=="true"||isStolen==true) firearmResult.addFields({name:`**Stolen**`,value:'\`Yes\`',inline: true});
|
||||
interaction.send({ embeds: [firearmResult] });
|
||||
}
|
||||
}
|
||||
socket.disconnect();
|
||||
});
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
const { EmbedBuilder, ButtonStyle } = require("discord.js");
|
||||
|
||||
module.exports = {
|
||||
name: "help",
|
||||
description: "Get information on a specific command",
|
||||
usage: "[command]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "command",
|
||||
description: "Get information on a specific command",
|
||||
value: "command",
|
||||
type: 3,
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
let Commands = client.commands.filter((cmd) => {
|
||||
if (client.exists(cmd.debug)) return !cmd.debug
|
||||
else return true
|
||||
}).map((cmd) =>
|
||||
`\`/${cmd.name}${cmd.usage ? " " + cmd.usage : ""}\` - ${cmd.description}`
|
||||
);
|
||||
|
||||
let Embed = new EmbedBuilder()
|
||||
.setColor(client.config.EmbedColor)
|
||||
.setDescription(`${Commands.join("\n")}
|
||||
|
||||
LPC Bot Version: v${client.config.Version}`);
|
||||
if (!args) return interaction.send({ embeds: [Embed] });
|
||||
else {
|
||||
let cmd =
|
||||
client.commands.get(args[0].value) ||
|
||||
client.commands.find(
|
||||
(x) => x.aliases && x.aliases.includes(args[0].value)
|
||||
);
|
||||
if (!cmd)
|
||||
return client.sendTime(
|
||||
interaction,
|
||||
`❌ | Unable to find that command.`
|
||||
);
|
||||
|
||||
let embed = new EmbedBuilder()
|
||||
.setAuthor({ name: `Command: ${cmd.name}`, iconURL: client.config.IconURL })
|
||||
.setDescription(cmd.description)
|
||||
.setColor(ButtonStyle.Success) // Green
|
||||
.addFields({
|
||||
name: "Usage",
|
||||
value: `\`/${cmd.name}${cmd.usage ? " " + cmd.usage : ""}\``,
|
||||
inline: true
|
||||
})
|
||||
.addFields({
|
||||
name: "Permissions",
|
||||
value: "Member: " +
|
||||
cmd.permissions.member.join(", ") +
|
||||
"\nBot: " +
|
||||
cmd.permissions.channel.join(", "),
|
||||
inline: true
|
||||
})
|
||||
|
||||
return interaction.send({ embeds: [embed] });
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const io = require('socket.io-client');
|
||||
|
||||
module.exports = {
|
||||
name: "joincommunity",
|
||||
description: "Join a community",
|
||||
usage: "[code]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "code",
|
||||
description: "Join community with community code",
|
||||
value: "code",
|
||||
type: 3,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").MessageCreate} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||
if (!user) return interaction.send({ content: `You are not logged in.` });
|
||||
let myReq = {
|
||||
userID: user._id,
|
||||
communityCode: args[0].value
|
||||
};
|
||||
const socket = io.connect(client.config.socket);
|
||||
socket.emit('bot_join_community', myReq);
|
||||
socket.on('bot_joined_community', (data) => {
|
||||
socket.disconnect()
|
||||
if (data.error) {
|
||||
return interaction.send({ content: `${data.error}` });
|
||||
}
|
||||
return interaction.send({ content: `Successfully joined the community \` ${data.commName} \`` })
|
||||
});
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const io = require('socket.io-client');
|
||||
|
||||
module.exports = {
|
||||
name: "leavecommunity",
|
||||
description: "Leave your active community",
|
||||
usage: "",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").MessageCreate} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||
if (!user) return interaction.send({ content: `You are not logged in.` });
|
||||
let myReq = {
|
||||
userID: user._id
|
||||
};
|
||||
const socket = io.connect(client.config.socket);
|
||||
socket.emit('bot_leave_community', myReq);
|
||||
socket.on('bot_left_community', (data) => {
|
||||
socket.disconnect()
|
||||
if (data.error) {
|
||||
return interaction.send({ content: `${data.error}` });
|
||||
}
|
||||
return interaction.send({ content: `${data.message}` });
|
||||
});
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const io = require('socket.io-client');
|
||||
|
||||
module.exports = {
|
||||
name: "namesearch",
|
||||
description: "Search a civilian",
|
||||
usage: "[First Name] [Last Name] [yyyy-mm-dd]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "firstname",
|
||||
description: "Civilian's First Name",
|
||||
value: "firstname",
|
||||
type: 3,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "lastname",
|
||||
description: "Civilian's Last Name",
|
||||
value: "lastname",
|
||||
type: 3,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "dob",
|
||||
description: "Civilian's DOB (yyyy-mm-dd)",
|
||||
value: "dob",
|
||||
type: 3,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles);
|
||||
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
||||
|
||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||
if (!user) return interaction.send({ content: `You are not logged in.` });
|
||||
let data;
|
||||
|
||||
data = {
|
||||
user: user,
|
||||
query: {
|
||||
firstName: args[0].value,
|
||||
lastName: args[1].value,
|
||||
dateOfBirth: args[2].value,
|
||||
activeCommunityID: user.user.activeCommunity
|
||||
}
|
||||
}
|
||||
|
||||
const socket = io.connect(client.config.socket);
|
||||
socket.emit("bot_name_search", data);
|
||||
socket.on("bot_name_search_results", results => {
|
||||
|
||||
if (results.user._id==user._id) {
|
||||
if (results.civilians.length == 0) {
|
||||
return interaction.send({ content: `Name \`${args[0].value} ${args[1].value}\` not found.` });
|
||||
}
|
||||
|
||||
for (let i = 0; i < results.civilians.length; i++) {
|
||||
// Get Drivers Licence Status
|
||||
let licenceStatus;
|
||||
if (results.civilians[i].civilian.licenseStatus == 1) licenceStatus = 'Valid';
|
||||
if (results.civilians[i].civilian.licenceStatus == 2) licenceStatus = 'Revoked';
|
||||
if (results.civilians[i].civilian.licenceStatus == 3) licenceStatus = 'None';
|
||||
// Get Firearm Licence Status
|
||||
let firearmLicence = results.civilians[i].civilian.firearmLicense;
|
||||
if (firearmLicence == undefined || firearmLicence == null) firearmLicence = 'None';
|
||||
if (firearmLicence == '2') firearmLicence = 'Valid';
|
||||
if (firearmLicence == '3') firearmLicence = 'Revoked';
|
||||
let nameResult = new EmbedBuilder()
|
||||
.setColor('#0099ff')
|
||||
.setTitle(`**${results.civilians[i].civilian.firstName} ${results.civilians[i].civilian.lastName} | ${results.civilians[i]._id}**`)
|
||||
.setURL('https://discord.gg/jgUW656v2t')
|
||||
.setAuthor({ name: 'LPS Website Support', iconURL: client.config.IconURL, url: 'https://discord.gg/jgUW656v2t' })
|
||||
.setDescription('Name Search Results')
|
||||
.addFields(
|
||||
{ name: `**First Name**`, value: `\`${results.civilians[i].civilian.firstName}\``, inline: true },
|
||||
{ name: `**Last Name**`, value: `\`${results.civilians[i].civilian.lastName}\``, inline: true },
|
||||
{ name: `**DOB**`, value: `\`${results.civilians[i].civilian.birthday}\``, inline: true },
|
||||
{ name: `**Drivers License**`, value: `\`${licenceStatus}\``, inline: true },
|
||||
{ name: `**Firearm Licence**`, value: `\`${firearmLicence}\``, inline: true },
|
||||
{ name: `**Gender**`, value: `\`${results.civilians[i].civilian.gender}\``, inline: true }
|
||||
)
|
||||
// Check Other details
|
||||
let address = results.civilians[i].civilian.address;
|
||||
let occupation = results.civilians[i].civilian.occupation;
|
||||
let height = results.civilians[i].civilian.height;
|
||||
let weight = results.civilians[i].civilian.weight;
|
||||
let eyeColor = results.civilians[i].civilian.eyeColor;
|
||||
let hairColor = results.civilians[i].civilian.hairColor;
|
||||
if (address != null && address != undefined && address != '') nameResult.addFields({ name: `**Address**`, value: `\`${address}\``, inline: true });
|
||||
if (occupation != null && occupation != undefined && occupation != '') nameResult.addFields({ name: `**Occupation**`, value: `\`${occupation}\``, inline: true });
|
||||
if (height!=null&&height!=undefined&&height!="NaN"&&height!='') {
|
||||
if (results.civilians[i].civilian.heightClassification=='imperial') {
|
||||
let ft = Math.floor(height/12);
|
||||
let inch = height%12;
|
||||
nameResult.addFields({ name: '**Height**', value: `\`${ft}'${inch}"\``, inline: true });
|
||||
} else {
|
||||
nameResult.addFields({ name: '**Height**', value: `\`${height}cm\``, inline: true });
|
||||
}
|
||||
}
|
||||
if (weight!=null&&weight!=undefined&&weight!='') {
|
||||
let units = results.civilians[i].civilian.weightClassification=='imperial' ? 'lbs.' : 'kgs.';
|
||||
nameResult.addFields({ name: '**Weight**', value: `\`${weight}${units}\``, inline: true });
|
||||
}
|
||||
if (eyeColor!=null&&eyeColor!=undefined&&eyeColor!='') nameResult.addFields({name:'**Eye Color**',value:`\`${eyeColor}\``,inline:true});
|
||||
if (hairColor!=null&&hairColor!=undefined&&hairColor!='') nameResult.addFields({name:'**Hair Color**',value:`\`${hairColor}\``,inline:true});
|
||||
nameResult.addFields({name:'**Organ Donor**',value:`\`${results.civilians[i].civilian.organDonor}\``,inline:true});
|
||||
nameResult.addFields({name:'**Veteran**',value:`\`${results.civilians[i].civilian.veteran}\``,inline:true});
|
||||
interaction.send({ embeds: [nameResult] });
|
||||
}
|
||||
}
|
||||
socket.disconnect();
|
||||
});
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const io = require('socket.io-client');
|
||||
|
||||
module.exports = {
|
||||
name: "panic",
|
||||
description: "Enables users panic button",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus == true && !GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.`, flags: (1 << 6) });
|
||||
}
|
||||
|
||||
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles);
|
||||
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command", flags: (1 << 6) });
|
||||
|
||||
let user = await client.dbo.collection("users").findOne({"user.discord.id": interaction.member.user.id}).then(user => user);
|
||||
if (!user) return interaction.send({ content: `You are not logged in. Go to https://linespolice-cad.com/ to login, and connect your Discord account.`, flags: (1 << 6) });
|
||||
if (user.user.activeCommunity == null) return interaction.send({ content: `You must join a community to use this command.`, flags: (1 << 6) });
|
||||
|
||||
// If panic is enabled, disable panic
|
||||
if (user.user.dispatchStatus == 'Panic') {
|
||||
|
||||
const socket = io.connect(client.config.socket);
|
||||
socket.emit('clear_panic', {
|
||||
userID: user._id,
|
||||
communityID: user.user.activeCommunity
|
||||
});
|
||||
|
||||
let myUpdateReq = {
|
||||
userID: user._id,
|
||||
status: '10-8',
|
||||
setBy: 'System',
|
||||
onDuty: null,
|
||||
updateDuty: false
|
||||
};
|
||||
|
||||
socket.emit('bot_update_status', myUpdateReq);
|
||||
socket.on('bot_updated_status', (res) => {
|
||||
if (res.userID == user._id) {
|
||||
interaction.send({ content: `Disabled Panic and set status to \`10-8\`.`, flags: (1 << 6) });
|
||||
socket.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
|
||||
// If panic is disabled, enable panic
|
||||
} else {
|
||||
|
||||
if (user.user.activeCommunity == null) return interaction.send({ content: `You must join a community to use this command.`, flags: (1 << 6) });
|
||||
client.forceUpdateStatus('Panic', user);
|
||||
|
||||
let req = {
|
||||
userID: user._id,
|
||||
userUsername: user.user.username,
|
||||
activeCommunity: user.user.activeCommunity
|
||||
}
|
||||
|
||||
const socket = io.connect(client.config.socket);
|
||||
socket.emit('panic_button_update', req);
|
||||
socket.disconnect();
|
||||
|
||||
let guild = await client.dbo.collection("prefixes").findOne({"server.serverID": GuildDB.serverID}).then(guild => guild);
|
||||
|
||||
if (guild.server.pingOnPanic) {
|
||||
const channel = client.channels.cache.get(interaction.channel_id);
|
||||
channel.send({ content: `Attention <@&${guild.server.pingRole}> \`${user.user.username}\` has activated panic` });
|
||||
}
|
||||
|
||||
return interaction.send({ content: 'Successfully activated Panic', flags: (1 << 6) });
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "ping",
|
||||
description: "check the bots responce",
|
||||
usage: "",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
interaction.send({ content: 'Pong!' });
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "pingonpanic",
|
||||
description: "Get ping on panic status",
|
||||
usage: "",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").MessageCreate} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild);
|
||||
return interaction.send({ content: `Current Ping on Panic Status: \` ${guild.server.pingOnPanic} \`` });
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const io = require('socket.io-client');
|
||||
|
||||
module.exports = {
|
||||
name: "platesearch",
|
||||
description: "Search for a registered Vehicle",
|
||||
usage: "[Plate #]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "platenumber",
|
||||
description: "Vehicle's license plate number",
|
||||
value: "platenumber",
|
||||
type: 3,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles);
|
||||
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
||||
|
||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||
if (!user) return interaction.send({ content: `You are not logged in.` });
|
||||
let data = {
|
||||
user: user,
|
||||
query: {
|
||||
plateNumber: args[0].value,
|
||||
activeCommunityID: user.user.activeCommunity
|
||||
}
|
||||
}
|
||||
const socket = io.connect(client.config.socket);
|
||||
socket.emit('bot_plate_search', data);
|
||||
socket.on('bot_plate_search_results', results => {
|
||||
|
||||
if (results.user._id==user._id) {
|
||||
if (results.vehicles.length == 0) {
|
||||
return interaction.send({ content: `Plate Number \`${args[0].value}\` not found.` });
|
||||
}
|
||||
|
||||
for (let i = 0; i < results.vehicles.length; i++) {
|
||||
let plateResult = new EmbedBuilder()
|
||||
.setColor('#0099ff')
|
||||
.setTitle(`**${results.vehicles[i].vehicle.plate} | ${results.vehicles[i]._id}**`)
|
||||
.setURL('https://discord.gg/jgUW656v2t')
|
||||
.setAuthor({ name: 'LPS Website Support', iconURL: client.config.IconURL, url: 'https://discord.gg/jgUW656v2t' })
|
||||
.setDescription('Plate Search Results')
|
||||
.addFields(
|
||||
{ name: `**Plate #**`, value: `\`${results.vehicles[i].vehicle.plate}\``, inline: true },
|
||||
{ name: `**Vin #**`, value: `\`${results.vehicles[i].vehicle.vin}\``, inline: true },
|
||||
{ name: `**Model**`, value: `\`${results.vehicles[i].vehicle.model}\``, inline: true },
|
||||
{ name: `**Color**`, value: `\`${results.vehicles[i].vehicle.color}\``, inline: true },
|
||||
{ name: `**Owner**`, value: `\`${results.vehicles[i].vehicle.registeredOwner}\``, inline: true },
|
||||
)
|
||||
// Other details
|
||||
let validRegistration = results.vehicles[i].vehicle.validRegistration;
|
||||
let validInsurance = results.vehicles[i].vehicle.validInsurance;
|
||||
let stolen = results.vehicles[i].vehicle.isStolen;
|
||||
if (validRegistration=='1') plateResult.addFields({ name: `**Registration**`, value: `\`Valid\``, inline: true });
|
||||
if (validRegistration=='2') plateResult.addFields({ name: `**Registration**`, value: `\`InValid\``, inline: true });
|
||||
if (validInsurance=='1') plateResult.addFields({ name: `**Insurance**`, value: `\`Valid\``, inline: true });
|
||||
if (validInsurance=='2') plateResult.addFields({ name: `**Insurance**`, value: `\`InValid\``, inline: true });
|
||||
if (stolen=='1') plateResult.addFields({ name: `**Stolen**`, value: `\`No\``, inline: true });
|
||||
if (stolen=='2') plateResult.addFields({ name: `**Stolen**`, value: `\`Yes\``, inline: true });
|
||||
return interaction.send({ embeds: [plateResult] });
|
||||
}
|
||||
}
|
||||
socket.disconnect();
|
||||
});
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "removechannel",
|
||||
description: "Remove channel from allowed channels",
|
||||
usage: "[channel]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: ["remove_role"],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "channel",
|
||||
description: "Channel to remove from allowed channles",
|
||||
value: "channel",
|
||||
type: 7,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").MessageCreate} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
if (args.length==0) return interaction.send({ content: `You must provide a channel.` });
|
||||
let channelid = args[0].value;
|
||||
let channel = client.channels.cache.get(channelid);
|
||||
if (!channel) return interaction.send({ content: `Uh Oh! The channel <#${args[0].value}> connot be found.` });
|
||||
let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild);
|
||||
if (guild.server.hasCustomChannels==false) return interaction.send({ content: `There are no channels to be removed.` });
|
||||
if (!guild.server.allowedChannels.includes(channelid)) return interaction.send({ content: `The channel <#${args[0].value}> is not added to your channels.` });
|
||||
for (let i = 0; i < guild.server.allowedChannels.length; i++) {
|
||||
if (guild.server.allowedChannels[i]==channelid) {
|
||||
if ((guild.server.allowedChannels.length-1)==0) {
|
||||
client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$pull:{"server.allowedChannels":channelid},$set:{"server.hasCustomChannels":false}},function(err, res) {
|
||||
if (err) throw err;
|
||||
return interaction.send({ content: `Successfully removed <#${args[0].value}> from allowed channels! There are no more allowed channels.` });
|
||||
});
|
||||
} else if ((guild.server.allowedChannels.length-1)>0) {
|
||||
client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$pull:{"server.allowedChannels":channelid}},function(err, res) {
|
||||
if (err) throw err;
|
||||
return interaction.send({ content: `Successfully removed <#${args[0].value}> from allowed channels.` });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "removerole",
|
||||
description: "Remove a role allowed to use the bot",
|
||||
usage: "[role]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: ["MANAGE_GUILD"],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "role",
|
||||
description: "Role to remove from allowed roles",
|
||||
value: "role",
|
||||
type: 8,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").MessageCreate} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let roleid = args[0].value;
|
||||
let role = interaction.guild.roles.cache.find(x => x.id == roleid);
|
||||
if (role == undefined) {
|
||||
return interaction.send({ content: `Uh Oh! The role <@&${args[0].value}> connot be found.` });
|
||||
} else {
|
||||
let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild);
|
||||
if (!client.exists(guild.server.hasCustomRoles) || !guild.server.hasCustomRoles) return interaction.send({ content: `There are no roles to be removed.` });
|
||||
if (!guild.server.allowedRoles.includes(roleid)) return interaction.send({ content: `The role <@&${args[0].value}> is not added to your roles.` });
|
||||
for (let i = 0; i < guild.server.allowedRoles.length; i++) {
|
||||
if (guild.server.allowedRoles[i]==roleid) {
|
||||
if ((guild.server.allowedRoles.length-1)==0) {
|
||||
client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$pull:{"server.allowedRoles":roleid},$set:{"server.hasCustomRoles":false}},function(err, res) {
|
||||
if (err) throw err;
|
||||
return interaction.send({ content: `Successfully removed <@&${args[0].value}> from allowed roles! There are no more allowed roles.` });
|
||||
});
|
||||
} else if ((guild.server.allowedRoles.length-1)>0) {
|
||||
client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$pull:{"server.allowedRoles":roleid}},function(err, res) {
|
||||
if (err) throw err;
|
||||
return interaction.send({ content: `Successfully removed <@&${args[0].value}> from allowed roles.` });
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const bitfieldCalculator = require('discord-bitfield-calculator');
|
||||
|
||||
module.exports = {
|
||||
name: "reset_channels",
|
||||
description: "Reset the configured channels for the bot",
|
||||
usage: "[channel]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: ["MANAGE_GUILD"],
|
||||
},
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").MessageCreate} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
const permissions = bitfieldCalculator.permissions(interaction.member.permissions);
|
||||
if (!permissions.includes("MANAGE_GUILD")) return interaction.send({ content: 'You don\'t have the permissions to use this command.' });
|
||||
|
||||
client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$set:{"server.allowedChannels": [], "server.hasCustomChannels": false}},function(err, res) {
|
||||
if (err) throw err;
|
||||
return interaction.send({ content: `Successfully reset all configured channels` });
|
||||
});
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "roles",
|
||||
description: "View allowed roles",
|
||||
usage: "",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").MessageCreate} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild);
|
||||
if (!client.exists(guild.server.hasCustomRoles) || !guild.server.hasCustomRoles) {
|
||||
return interaction.send({ content: 'There are no roles set for the bot.' });
|
||||
}
|
||||
|
||||
let roles = ``;
|
||||
for (let i = 0; i < guild.server.allowedRoles.length; i++) {
|
||||
if (guild.server.allowedRoles[i] == undefined) break;
|
||||
let role = interaction.guild.roles.cache.find(r => r.id == guild.server.allowedRoles[i]);
|
||||
if (roles.length==0) roles += `@${role.name}`;
|
||||
else roles += `\n@${role.name}`;
|
||||
}
|
||||
let rolesEmbed = new EmbedBuilder()
|
||||
.setColor('#0099ff')
|
||||
.setDescription('|**Allowed Roles to use the Bot**')
|
||||
.addFields(
|
||||
{ name: `There are currently **${guild.server.allowedRoles.length}** allowed roles.`, value: `\`${roles}\``, inline: true },
|
||||
)
|
||||
.setFooter({ text: 'LPS Website Support', iconURL: client.config.IconURL, proxyIconURL: 'https://discord.gg/jgUW656v2t' })
|
||||
return interaction.send({ embeds: [rolesEmbed] });
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "setchannel",
|
||||
description: "Add channel to allowed channels",
|
||||
usage: "[channel]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: ["MANAGE_GUILD"],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "channel",
|
||||
description: "Channel to add to allowed channles",
|
||||
value: "channel",
|
||||
type: 7,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").MessageCreate} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let channelid = args[0].value;
|
||||
let channel = client.channels.cache.get(channelid);
|
||||
if (!channel) return interaction.send({ content: `Cannot find that channel.` });
|
||||
if (channel.type=="voice") return interaction.send({ content: `Connot set voice channel to preferred channel.` });
|
||||
if (channel.deleted) return interaction.send({ content: `Connot set deleted channel to preferred channel.` });
|
||||
let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild);
|
||||
if (client.exists(guild.server.allowedChannels)&&guild.server.allowedChannels.includes(channelid)) return interaction.send({ content: `The channel <#${args[0].value}> has already been added.` });
|
||||
client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$push:{"server.allowedChannels":channelid},$set:{"server.hasCustomChannels":true}},function(err, res) {
|
||||
if (err) throw err;
|
||||
return interaction.send({ content: `Successfully added <#${args[0].value}> to allowed channels.` });
|
||||
});
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "setrole",
|
||||
description: "Add a role allowed to use the bot",
|
||||
usage: "[role]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: ["MANAGE_GUILD"],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "role",
|
||||
description: "Role to add to allowed roles",
|
||||
value: "role",
|
||||
type: 8,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").MessageCreate} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let roleid = args[0].value;
|
||||
let role = interaction.guild.roles.cache.find(x => x.id == roleid);
|
||||
if (role == undefined) {
|
||||
return interaction.send({ content: `Uh Oh! The role <@&${args[0].value}> connot be found.` });
|
||||
} else {
|
||||
let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":interaction.guild.id}).then(guild => guild);
|
||||
if (client.exists(guild.server.allowedRoles)&&guild.server.allowedRoles.includes(roleid)) return interaction.send({ content: `The role <@&${args[0].value}> has already been added.` });
|
||||
client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$push:{"server.allowedRoles":roleid},$set:{"server.hasCustomRoles":true}},function(err, res) {
|
||||
if (err) throw err;
|
||||
return interaction.send({ content: `Successfully added <@&${args[0].value}> to allowed roles.` });
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
const { EmbedBuilder } = require("discord.js");
|
||||
require("moment-duration-format");
|
||||
|
||||
module.exports = {
|
||||
name: "stats",
|
||||
description: "Displays current Bot statistics",
|
||||
usage: "",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
const { version } = require("discord.js");
|
||||
const totalGuilds = await client.shard.fetchClientValues("guilds.cache.size").then(results => {
|
||||
return results.reduce((acc, guildCount) => acc + guildCount, 0)
|
||||
});
|
||||
const totalMembers = await client.shard.broadcastEval(c => c.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0)).then(data => data.reduce((acc, memberCount) => acc + memberCount, 0));
|
||||
const stats = new EmbedBuilder()
|
||||
.setColor('#0099ff')
|
||||
.setTitle("Current LPC-Bot Statistics")
|
||||
.setURL(client.config.SupportServer)
|
||||
.setDescription(`**Servers** : \`${totalGuilds}\`\n**Users** : \`${totalMembers}\``)
|
||||
interaction.send({ embeds: [stats] })
|
||||
},
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "togglepingonpanic",
|
||||
description: "Enable or Disable ping on panic",
|
||||
usage: "[true/false] [role]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "toggle",
|
||||
description: "Toggle ping on panic",
|
||||
value: "toggle",
|
||||
type: 5,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "role",
|
||||
description: "Role to ping on panic",
|
||||
value: "role",
|
||||
type: 8,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").MessageCreate} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
if (!args[0].value) {
|
||||
// disable ping on panic and remove ping role
|
||||
client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$set:{"server.pingOnPanic":false,"server.pingRole":null}},function(err, res) {
|
||||
if (err) throw err;
|
||||
return interaction.send({ content: `Successfully disabled ping role on panic.` });
|
||||
});
|
||||
} else if (args[0].value) {
|
||||
let roleid = args[1].value;
|
||||
let role = interaction.guild.roles.cache.find(x => x.id == roleid);
|
||||
if (role == undefined) {
|
||||
return interaction.send({ content: `Uh Oh! The role <@&${args[1].value}> connot be found.` });
|
||||
} else {
|
||||
client.dbo.collection("prefixes").updateOne({"server.serverID":interaction.guild.id},{$set:{"server.pingRole":roleid,"server.pingOnPanic":true}},function(err, res) {
|
||||
if (err) throw err;
|
||||
return interaction.send({ content: `Successfully set <@&${args[1].value}> to be pinged on panic.` });
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
const { EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
|
||||
const io = require('socket.io-client');
|
||||
|
||||
module.exports = {
|
||||
name: "updatelicense",
|
||||
description: "Update Drivers License Status",
|
||||
usage: "[firstName] [lastName] [DOB]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "firstname",
|
||||
description: "Civilian's First Name",
|
||||
value: "firstname",
|
||||
type: 3,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "lastname",
|
||||
description: "Civilian's Last Name",
|
||||
value: "lastname",
|
||||
type: 3,
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
name: "dob",
|
||||
description: "Civilian's DOB (yyyy-mm-dd)",
|
||||
value: "dob",
|
||||
type: 3,
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles);
|
||||
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
||||
|
||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||
if (!user) return interaction.send({ content: `You are not logged in.` });
|
||||
|
||||
let data = {
|
||||
user: user,
|
||||
query: {
|
||||
firstName: args[0].value,
|
||||
lastName: args[1].value,
|
||||
dateOfBirth: args[2].value,
|
||||
activeCommunityID: user.user.activeCommunity
|
||||
}
|
||||
}
|
||||
|
||||
const socket = io.connect(client.config.socket);
|
||||
socket.emit("bot_name_search", data);
|
||||
socket.on("bot_name_search_results", (results) => {
|
||||
if (results.user._id==user._id) {
|
||||
if (results.civilians.length == 0) {
|
||||
return interaction.send({ content: `Name \`${args[0].value} ${args[1].value}\` not found.` });
|
||||
}
|
||||
}
|
||||
|
||||
let nameResult;
|
||||
let row;
|
||||
for (let i = 0; i < results.civilians.length; i++) {
|
||||
// Get Drivers Licence Status
|
||||
let licenseStatus;
|
||||
if (results.civilians[i].civilian.licenseStatus == 1) licenseStatus = 'Valid';
|
||||
if (results.civilians[i].civilian.licenseStatus == 2) licenseStatus = 'Revoked';
|
||||
if (results.civilians[i].civilian.licenseStatus == 3) licenseStatus = 'None';
|
||||
nameResult = new EmbedBuilder()
|
||||
.setColor('#0099ff')
|
||||
.setTitle(`**${results.civilians[i].civilian.firstName} ${results.civilians[i].civilian.lastName} | ${results.civilians[i]._id}**`)
|
||||
.setURL('https://discord.gg/jgUW656v2t')
|
||||
.setAuthor({ name: 'LPS Website Support', iconURL: client.config.IconURL, url: 'https://discord.gg/jgUW656v2t' })
|
||||
.setDescription('Name Search Results')
|
||||
.addFields(
|
||||
{ name: `**First Name**`, value: `\`${results.civilians[i].civilian.firstName}\``, inline: true },
|
||||
{ name: `**Last Name**`, value: `\`${results.civilians[i].civilian.lastName}\``, inline: true },
|
||||
{ name: `**DOB**`, value: `\`${results.civilians[i].civilian.birthday}\``, inline: true },
|
||||
{ name: `**Drivers License**`, value: `\`${licenseStatus}\``, inline: true },
|
||||
{ name: `**Gender**`, value: `\`${results.civilians[i].civilian.gender}\``, inline: true }
|
||||
)
|
||||
row = new ActionRowBuilder()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`license-revoke-${results.civilians[i]._id}`)
|
||||
.setLabel("Revoke")
|
||||
.setStyle(ButtonStyle.Danger),
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`license-reinstate-${results.civilians[i]._id}`)
|
||||
.setLabel("Reinstate")
|
||||
.setStyle(ButtonStyle.Success)
|
||||
)
|
||||
}
|
||||
|
||||
return interaction.send({ embeds: [nameResult], components: [row], flags: (1 << 6) });
|
||||
});
|
||||
},
|
||||
},
|
||||
Interactions: {
|
||||
license: {
|
||||
run: async (client, ButtonInteraction, { GuildDB }) => {
|
||||
const socket = io.connect(client.config.socket);
|
||||
|
||||
let queryString = ButtonInteraction.customId;
|
||||
let query = {
|
||||
_id: "",
|
||||
status: null,
|
||||
bot_request: true
|
||||
};
|
||||
if (queryString.split('-')[1]=='revoke') {
|
||||
query.status = 2;
|
||||
query._id = queryString.split('-')[2];
|
||||
} else if (queryString.split('-')[1]=='reinstate') {
|
||||
query.status = 1;
|
||||
query._id = queryString.split('-')[2];
|
||||
}
|
||||
socket.emit("update_drivers_license_status", query);
|
||||
socket.on("bot_updated_drivers_license_status", (res) => {
|
||||
socket.disconnect();
|
||||
if (!res.success) return ButtonInteraction.update({ content: 'Failed to update license.', embeds: [], components: [] });
|
||||
});
|
||||
return ButtonInteraction.update({ content: 'Successfully updated license.', embeds: [], components: [] });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
const io = require('socket.io-client');
|
||||
|
||||
module.exports = {
|
||||
name: "updatestatus",
|
||||
description: "Change User status",
|
||||
usage: "[status]",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [
|
||||
{
|
||||
name: "status",
|
||||
description: "New Status Value",
|
||||
value: "status",
|
||||
type: 3,
|
||||
required: true,
|
||||
choices: [
|
||||
{ name: '10-8 (In Service)', value: '10-8', }, { name: '10-7 (Out of Service)', value: '10-7', }, { name: '10-6 (Busy)', value: '10-6', },
|
||||
{ name: '10-11 (Traffic Stop)', value: '10-11', }, { name: '10-23 (Arrive on Scene', value: '10-23', }, { name: '10-97 (In Route)', value: '10-97' },
|
||||
{ name: '10-15 (Subject in Custody)', value: '10-15', }, { name: '10-70 (Foot Pursuit)', value: '10-70', }, { name: '10-80 (Vehicle Pursuit)', value: '10-80' },
|
||||
{ name: '10-41 (Log in to CAD)', value: '10-41', }, { name: '10-42 (Log out of CAD)', value: '10-42' },
|
||||
],
|
||||
},
|
||||
],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
|
||||
let useCommand = await client.verifyUseCommand(GuildDB.serverID, interaction.member.roles);
|
||||
if (!useCommand) return interaction.send({ content: "You don't have permission to use this command" });
|
||||
|
||||
let user = await client.dbo.collection("users").findOne({"user.discord.id":interaction.member.user.id}).then(user => user);
|
||||
if (!user) return interaction.send({ content: `You are not logged in <@${interaction.member.user.id}>` });
|
||||
if (user.user.activeCommunity==null) return interaction.send({ content: `You must join a community to use this command.` });
|
||||
let onDuty=null;
|
||||
let updateDuty=false;
|
||||
let status = args[0].value;
|
||||
if (args[0].value=='10-41') {
|
||||
onDuty=true;
|
||||
updateDuty=true;
|
||||
status='Online';
|
||||
}
|
||||
if (args[0].value=='10-42') {
|
||||
onDuty=false;
|
||||
updateDuty=true;
|
||||
status='Offline';
|
||||
}
|
||||
let req={
|
||||
userID: user._id,
|
||||
status: status,
|
||||
setBy: 'Self',
|
||||
onDuty: onDuty,
|
||||
updateDuty: updateDuty
|
||||
};
|
||||
const socket = io.connect(client.config.socket);
|
||||
socket.emit('bot_update_status', req);
|
||||
socket.on('bot_updated_status', (res) => {
|
||||
socket.disconnect();
|
||||
return interaction.send({ content: `Succesfully updated <@${interaction.member.user.id}>'s status to \`${args[0].value}\`` });
|
||||
});
|
||||
return;
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
const { EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: "website",
|
||||
description: "Link to the Lines Police CAD website",
|
||||
usage: "",
|
||||
permissions: {
|
||||
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
|
||||
member: [],
|
||||
},
|
||||
options: [],
|
||||
SlashCommand: {
|
||||
/**
|
||||
*
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {import("discord.js").Message} message
|
||||
* @param {string[]} args
|
||||
* @param {*} param3
|
||||
*/
|
||||
run: async (client, interaction, args, { GuildDB }) => {
|
||||
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
|
||||
return interaction.send({ content: `You are not allowed to use the bot in this channel.` });
|
||||
}
|
||||
return interaction.send({ content: 'Lines Police CAD Website-> https://www.linespolice-cad.com/' });
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"defaultPrefix": "?",
|
||||
"botID": "860298681047056434",
|
||||
"mongoURI": "mongodb+srv://lps_bot:ktSkHml2BU9EIQ0a@heroku-police-cad-dev.j7aom.mongodb.net/heroku_8pc4g86l?retryWrites=true&w=majority",
|
||||
"version": "Beta 1.7.0",
|
||||
"socket": "https://police-cad-dev.herokuapp.com/",
|
||||
"dbo": "heroku_8pc4g86l"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
require('dotenv').config()
|
||||
|
||||
module.exports = {
|
||||
Dev: "PRODUCTION",
|
||||
Version: "3.2.3",
|
||||
Admins: ["362791661274660874"], // Admins of the bot
|
||||
DefaultPrefix: "?",
|
||||
socket: "https://www.linespolice-cad.com/",
|
||||
SupportServer: "https://discord.gg/w2g2FFmHbF", //Support Server Link
|
||||
Token: process.env.token || "", //Discord Bot Token
|
||||
Scopes: ["identify", "guilds", "applications.commands"], //Discord OAuth2 Scopes
|
||||
IconURL: "https://raw.githubusercontent.com/Linesmerrill/police-cad/master/lines-police-cad.png",
|
||||
EmbedColor: "#0099ff",
|
||||
Permissions: 2205281600,
|
||||
Website: "https://linespolice-cad.com",
|
||||
api_url: process.env.API_URL || "",
|
||||
api_token: process.env.API_TOKEN || "",
|
||||
mongoURI: process.env.mongoURI || "mongodb://localhost:27017",
|
||||
dbo: process.env.dbo || "knoldus",
|
||||
Colors: {
|
||||
Red: "#ba0f0f"
|
||||
},
|
||||
Presence: {
|
||||
status: "online", // You can show online, idle, and dnd
|
||||
name: "Grand Theft Auto V", // The message shown
|
||||
type: "PLAYING", // PLAYING, WATCHING, LISTENING, STREAMING
|
||||
},
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
{
|
||||
"defaultPrefix": "?",
|
||||
"botID": "860298681047056434",
|
||||
"mongoURI": "mongodb+srv://lps_bot:ktSkHml2BU9EIQ0a@heroku-police-cad-dev.j7aom.mongodb.net/heroku_8pc4g86l?retryWrites=true&w=majority",
|
||||
"version": "Beta 1.7.0",
|
||||
"socket": "http://localhost:8080",
|
||||
"dbo": "heroku_8pc4g86l"
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module.exports = (client, guild) => {
|
||||
require("../util/RegisterSlashCommands")(client, guild.id);
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
module.exports = async (client, interaction) => {
|
||||
if (interaction.isCommand()) return;
|
||||
|
||||
/*
|
||||
This file hanldes all button interactions from any command
|
||||
*/
|
||||
|
||||
let GuildDB = await client.GetGuild(interaction.guildId);
|
||||
const interactionName = interaction.customId.split('-')[0];
|
||||
let interactionHandler = client.interactionHandlers.get(interactionName);
|
||||
|
||||
interactionHandler.run(client, interaction, GuildDB);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
module.exports = async (client) => {
|
||||
(client.Ready = true),
|
||||
client.user.setActivity(
|
||||
client.config.Presence.name,
|
||||
client.config.Presence.type
|
||||
)
|
||||
client.log(`Successfully Logged in as ${client.user.tag}`); // You can change the text if you want, but DO NOT REMOVE "client.user.tag"
|
||||
client.log(`Ready to serve in ${client.channels.cache.size} channels on ${client.guilds.cache.size} servers, for a total of ${client.users.cache.size} users.`)
|
||||
client.RegisterSlashCommands();
|
||||
};
|
||||
@@ -1,4 +1,8 @@
|
||||
const Bot = require('./LPS').Bot;
|
||||
const { ShardingManager } = require('discord.js');
|
||||
const config = require('./config/config');
|
||||
|
||||
client = new Bot('PRODUCTION', process.env.token, './config');
|
||||
client.main()
|
||||
const manager = new ShardingManager('./bot.js', { token: config.Token });
|
||||
|
||||
manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));
|
||||
|
||||
manager.spawn();
|
||||
Generated
+2113
-1835
File diff suppressed because it is too large.
Load diff
+13
-7
@@ -5,16 +5,22 @@
|
||||
"main": "LPS.js",
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"dev": "nodemon dev.js"
|
||||
"dev": "node dev.js",
|
||||
"dev-active": "nodemon dev.js"
|
||||
},
|
||||
"author": "Braeden Sowinski",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"discord.js": "^12.5.3",
|
||||
"express": "^4.17.1",
|
||||
"mongodb": "^3.6.8",
|
||||
"nodemon": "^2.0.9",
|
||||
"randomstring": "^1.2.1",
|
||||
"socket.io-client": "^4.1.2"
|
||||
"@discordjs/rest": "^1.7.0",
|
||||
"colors": "^1.4.0",
|
||||
"concat-stream": "^2.0.0",
|
||||
"discord-bitfield-calculator": "^1.0.0",
|
||||
"discord.js": "^14.9.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"form-data": "^4.0.0",
|
||||
"moment-duration-format": "^2.3.2",
|
||||
"mongodb": "^4.12.1",
|
||||
"socket.io-client": "^4.1.2",
|
||||
"winston": "^3.8.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
const { Collection, Client, EmbedBuilder, Routes } = require('discord.js');
|
||||
const MongoClient = require('mongodb').MongoClient;
|
||||
const { REST } = require('@discordjs/rest');
|
||||
const Logger = require("../util/Logger");
|
||||
const io = require('socket.io-client');
|
||||
const path = require("path");
|
||||
const fs = require('fs');
|
||||
|
||||
class LinesPoliceCadBot extends Client {
|
||||
|
||||
constructor(options, config) {
|
||||
super(options)
|
||||
|
||||
this.config = config;
|
||||
this.commands = new Collection();
|
||||
this.interactionHandlers = new Collection();
|
||||
this.logger = new Logger(path.join(__dirname, "..", "logs/Logs.log"));
|
||||
|
||||
if (this.config.Token === "") return new TypeError(
|
||||
"The config.js is missing a token, please ensure the token is provided."
|
||||
);
|
||||
|
||||
this.db;
|
||||
this.dbo;
|
||||
this.connectMongo(this.config.mongoURI, this.config.dbo);
|
||||
this.databaseConnected = false;
|
||||
this.LoadCommandsAndInteractionHandlers();
|
||||
this.LoadEvents();
|
||||
|
||||
this.Ready = false;
|
||||
|
||||
this.ws.on("INTERACTION_CREATE", async (interaction) => {
|
||||
if (interaction.type!=3) {
|
||||
let GuildDB = await this.GetGuild(interaction.guild_id);
|
||||
|
||||
const command = interaction.data.name.toLowerCase();
|
||||
const args = interaction.data.options;
|
||||
|
||||
client.log(`Interaction - ${command}`)
|
||||
|
||||
//Easy to send respnose so ;)
|
||||
interaction.guild = await this.guilds.fetch(interaction.guild_id);
|
||||
interaction.send = async (message) => {
|
||||
const rest = new REST({ version: '10' }).setToken(client.config.Token);
|
||||
|
||||
return await rest.post(Routes.interactionCallback(interaction.id, interaction.token), {
|
||||
body: {
|
||||
type: 4,
|
||||
data: message,
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (!this.databaseConnected) {
|
||||
let dbFailedEmbed = new EmbedBuilder()
|
||||
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThe bot has failed to connect to the database 5 times!\nContact the Developers`)
|
||||
.setColor(client.config.Colors.Red);
|
||||
|
||||
return interaction.send({ embeds: [dbFailedEmbed] });
|
||||
}
|
||||
|
||||
let cmd = client.commands.get(command);
|
||||
try {
|
||||
cmd.SlashCommand.run(this, interaction, args, { GuildDB });
|
||||
} catch (err) {
|
||||
this.sendInternalError(interaction, err);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const client = this;
|
||||
}
|
||||
|
||||
async connectMongo(mongoURI, dbo) {
|
||||
let failed = false;
|
||||
|
||||
let dbLogDir = path.join(__dirname, '..', 'logs', 'database-logs.json');
|
||||
let databaselogs;
|
||||
try {
|
||||
databaselogs = JSON.parse(fs.readFileSync(dbLogDir));
|
||||
} catch (err) {
|
||||
databaselogs = {
|
||||
attempts: 0,
|
||||
connected: false,
|
||||
};
|
||||
}
|
||||
|
||||
if (databaselogs.attempts >= 5) {
|
||||
this.error('Failed to connect to mongodb after multiple attempts');
|
||||
return; // prevent further attempts
|
||||
}
|
||||
|
||||
try {
|
||||
// Connect to Mongo database.
|
||||
this.db = await MongoClient.connect(mongoURI, { useUnifiedTopology: true, connectTimeoutMS: 1000 });
|
||||
this.dbo = this.db.db(dbo);
|
||||
this.log('Successfully connected to mongoDB');
|
||||
databaselogs.connected = true;
|
||||
databaselogs.attempts = 0;
|
||||
this.databaseConnected = true;
|
||||
} catch (err) {
|
||||
databaselogs.attempts++;
|
||||
let db = (mongoURI.includes("@") ? mongoURI.split("@")[1] : mongoURI.split("//")[1]).endsWith("/") ? mongoURI.slice(0, -1) : mongoURI;
|
||||
this.error(`Failed to connect to mongodb (mongodb://${db}/${dbo}): attempt ${databaselogs.attempts} - ${err}`);
|
||||
failed = true;
|
||||
}
|
||||
|
||||
// write JSON string to a file
|
||||
fs.writeFileSync(dbLogDir, JSON.stringify(databaselogs));
|
||||
|
||||
if (failed) process.exit(-1);
|
||||
}
|
||||
|
||||
// This is for the 'panic' command when enabling panic
|
||||
// May be used by other interaction
|
||||
async forceUpdateStatus(status, user) {
|
||||
let onDuty = null;
|
||||
let updateDuty = false;
|
||||
|
||||
// If the are off duty, make them on duty + online
|
||||
if (status == '10-41') {
|
||||
onDuty = true;
|
||||
updateDuty = true;
|
||||
status = 'Online';
|
||||
}
|
||||
|
||||
// If they are on duty,
|
||||
if (status == '10-42') {
|
||||
onDuty = false;
|
||||
updateDuty = true;
|
||||
status = 'Offline';
|
||||
}
|
||||
|
||||
let req = {
|
||||
userID: user._id,
|
||||
status: status,
|
||||
setBy: 'Self',
|
||||
onDuty: onDuty,
|
||||
updateDuty: updateDuty
|
||||
};
|
||||
|
||||
const socket = io.connect(this.config.socket);
|
||||
|
||||
socket.emit('bot_update_status', req);
|
||||
socket.on('bot_updated_status', (res) => {
|
||||
if (res.userID == user._id) socket.disconnect(); // ensure success response is for us
|
||||
});
|
||||
}
|
||||
|
||||
exists(n) {return null != n && undefined != n && "" != n}
|
||||
|
||||
LoadCommandsAndInteractionHandlers() {
|
||||
let CommandsDir = path.join(__dirname, '..', 'commands');
|
||||
fs.readdir(CommandsDir, (err, files) => {
|
||||
if (err) this.error(err);
|
||||
else
|
||||
files.forEach((file) => {
|
||||
let cmd = require(CommandsDir + "/" + file);
|
||||
if (!cmd.name || !cmd.description)
|
||||
return this.log(
|
||||
"Unable to load Command: " +
|
||||
file.split(".")[0] +
|
||||
", Reason: File doesn't had run/name/desciption"
|
||||
);
|
||||
this.commands.set(file.split(".")[0].toLowerCase(), cmd);
|
||||
if (this.exists(cmd.Interactions)) {
|
||||
for (let [interaction, handler] of Object.entries(cmd.Interactions)) {
|
||||
this.interactionHandlers.set(interaction, handler);
|
||||
}
|
||||
}
|
||||
this.log("Command Loaded: " + file.split(".")[0]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
LoadEvents() {
|
||||
let EventsDir = path.join(__dirname, '..', 'events');
|
||||
fs.readdir(EventsDir, (err, files) => {
|
||||
if (err) this.log(err);
|
||||
else
|
||||
files.forEach((file) => {
|
||||
const event = require(EventsDir + "/" + file);
|
||||
if (file.split(".")[0] == 'interactionCreate') this.on(file.split(".")[0], i => event(this, i));
|
||||
else this.on(file.split(".")[0], event.bind(null, this));
|
||||
this.logger.log("Event Loaded: " + file.split(".")[0]);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
sendInternalError(Interaction, Error) {
|
||||
this.error(Error);
|
||||
const embed = new EmbedBuilder()
|
||||
.setDescription(`**Internal Error:**\nUh Oh D: Its not you, its me.\nThis command has crashed\nCOntact the Developers`)
|
||||
.setColor(this.config.Colors.Red)
|
||||
|
||||
Interaction.send({ embeds: [embed] });
|
||||
}
|
||||
|
||||
sendTime(Channel, Error) {
|
||||
let embed = new EmbedBuilder()
|
||||
.setColor(this.config.EmbedColor)
|
||||
.setDescription(Error);
|
||||
|
||||
Channel.send({ embeds: [embed] });
|
||||
}
|
||||
|
||||
RegisterSlashCommands() {
|
||||
let p = Promise.resolve()
|
||||
this.guilds.cache.forEach((guild) => {
|
||||
p = p.then(() => {
|
||||
require("../util/RegisterSlashCommands")(this, guild.id);
|
||||
return new Promise((resolve) => {
|
||||
setTimeout(resolve, 500);
|
||||
})
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
async checkRoleStatus(rolesCache, allowedRoles) {
|
||||
if (allowedRoles.length == 0) return true; // If we are in this function, and there are no roles to compare to, return true as if we had the role anyway
|
||||
|
||||
for (let i = 0; i < allowedRoles.length; i++) {
|
||||
if (rolesCache.includes(allowedRoles[i])) return true; // they have at least one matching role
|
||||
else continue;
|
||||
}
|
||||
|
||||
return false; // they have no matching roles.
|
||||
}
|
||||
|
||||
async GetGuild(GuildId) {
|
||||
let guild = await this.dbo.collection("prefixes").findOne({"server.serverID":GuildId}).then(guild => guild);
|
||||
|
||||
// If guild not found, generate guild default
|
||||
if (!guild) {
|
||||
guild = {
|
||||
server: {
|
||||
serverID: GuildId,
|
||||
allowedChannels: [],
|
||||
allowedRoles: [],
|
||||
}
|
||||
}
|
||||
this.dbo.collection("prefixes").insertOne(guild, function(err, res) {
|
||||
if (err) throw err;
|
||||
});
|
||||
}
|
||||
if (guild.server.allowedRoles == undefined) guild.server.allowedRoles = [];
|
||||
let guildData = {
|
||||
allowedChannels: guild.server.allowedChannels,
|
||||
customChannelStatus: guild.server.allowedChannels.length > 0 ? true : false,
|
||||
customRoleStatus: guild.server.allowedRoles.length > 0 ? true : false,
|
||||
allowedRoles: guild.server.allowedRoles,
|
||||
serverID: GuildId
|
||||
}
|
||||
return guildData;
|
||||
}
|
||||
|
||||
/*
|
||||
This command is to verify a user
|
||||
has the correct role to use a
|
||||
command ie. has cop role to use
|
||||
name-search
|
||||
*/
|
||||
async verifyUseCommand(serverID, rolesCache) {
|
||||
let guildDB = await this.GetGuild(serverID);
|
||||
if (!guildDB.customRoleStatus) return true; // There is no role limits, can use command
|
||||
|
||||
// Clear any deleted roles
|
||||
let filteredRoles = [];
|
||||
let update = false;
|
||||
const guild = await this.guilds.cache.get(serverID);
|
||||
for (let i = 0; i < guildDB.allowedRoles.length; i++) {
|
||||
let role = guild.roles.cache.find(role => role.id == guildDB.allowedRoles[i])
|
||||
if (!role) update = true; // this role no longer exists, we need to update, dont add to list
|
||||
else filteredRoles.push(guildDB.allowedRoles[i]); // this role exists, add to list in case of update
|
||||
}
|
||||
|
||||
// If some roles no longer exists, update
|
||||
// or if customRoleStatus is true but no roles exist, update
|
||||
if (update || (filteredRoles.length == 0 && customRoleStatus)) {
|
||||
let newHasCustomRoles = filteredRoles.length > 0;
|
||||
|
||||
await this.dbo.collection("prefixes").updateOne({ 'server.serverID': serverID }, { $set: {
|
||||
'server.allowedRoles': filteredRoles,
|
||||
'server.hasCustomRoles': newHasCustomRoles,
|
||||
}}, (err, res) => {
|
||||
if (err) throw err;
|
||||
});
|
||||
}
|
||||
|
||||
let hasRole = await this.checkRoleStatus(rolesCache, filteredRoles);
|
||||
return hasRole;
|
||||
}
|
||||
|
||||
log(Text) { this.logger.log(Text); }
|
||||
error(Text) { this.logger.error(Text); }
|
||||
|
||||
build() {
|
||||
this.login(this.config.Token);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = LinesPoliceCadBot;
|
||||
@@ -0,0 +1,44 @@
|
||||
const winston = require("winston");
|
||||
const colors = require("colors");
|
||||
|
||||
class Logger {
|
||||
constructor(LoggingFile) {
|
||||
this.logger = winston.createLogger({
|
||||
transports: [new winston.transports.File({ filename: LoggingFile })],
|
||||
});
|
||||
}
|
||||
|
||||
log(Text) {
|
||||
let d = new Date();
|
||||
this.logger.log({
|
||||
level: "info",
|
||||
message:
|
||||
`${d.getHours()}:${
|
||||
d.getMinutes
|
||||
} - ${d.getDate()}:${d.getMonth()}:${d.getFullYear()} | Info: ` + Text,
|
||||
});
|
||||
console.log(
|
||||
colors.green(
|
||||
`${d.getDate()}:${d.getMonth()}:${d.getFullYear()} - ${d.getHours()}:${d.getMinutes()}`
|
||||
) + colors.yellow(" | Info: " + Text)
|
||||
);
|
||||
}
|
||||
|
||||
error(Text) {
|
||||
let d = new Date();
|
||||
this.logger.log({
|
||||
level: "error",
|
||||
message:
|
||||
`${d.getHours()}:${
|
||||
d.getMInutes
|
||||
} - ${d.getDate()}:${d.getMonth()}:${d.getFullYear()} | Error: ` + Text,
|
||||
});
|
||||
console.log(
|
||||
colors.green(
|
||||
`${d.getDate()}:${d.getMonth()}:${d.getFullYear()} - ${d.getHours}:${d.getMinutes()}`
|
||||
) + colors.yellow(" | Error: ") + colors.red(Text)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Logger;
|
||||
@@ -0,0 +1,38 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { Routes } = require('discord.js');
|
||||
const { REST } = require('@discordjs/rest');
|
||||
|
||||
/**
|
||||
* Register slash commands for a guild
|
||||
* @param {require("../structures/LinesPoliceCadBot")} client
|
||||
* @param {string} guild
|
||||
*/
|
||||
module.exports = async function(client, guild) {
|
||||
const commands = [];
|
||||
const commandFiles = fs.readdirSync(path.join(__dirname, "..", "commands")).filter(file => file.endsWith('.js'));
|
||||
|
||||
// Place your client and guild ids here
|
||||
const clientId = client.application.id;
|
||||
const guildId = guild;
|
||||
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`../commands/${file}`);
|
||||
commands.push(command);
|
||||
}
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(client.config.Token);
|
||||
|
||||
try {
|
||||
client.log(`[${guildId}] Started refreshing guild (/) commands.`);
|
||||
|
||||
await rest.put(
|
||||
Routes.applicationGuildCommands(clientId, guildId),
|
||||
{ body: commands },
|
||||
);
|
||||
|
||||
client.log(`[${guildId}] Successfully reloaded guild (/) commands.`);
|
||||
} catch (error) {
|
||||
client.error(error);
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user