update/add panic control

This commit is contained in:
SowinskiBraeden committed 2022-03-09 16:45:14 -08:00
1 parent 76467288f5
commit 441bb0672c
4 files changed
+157 -3

No files matched your search

+118
View File
@@ -0,0 +1,118 @@
const { MessageEmbed } = 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: [],
},
aliases: ["enablepanic"],
/**
*
* @param {require("../structures/LinesPoliceCadBot")} client
* @param {import("discord.js").Message} message
* @param {string[]} args
* @param {*} param3
*/
run: async (client, message) => {
let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user);
if (!user) return message.channel.send(`You are not logged in.`);
if (user.user.activeCommunity==null) return message.channel.send(`You must join a community to use this command.`);
const socket = io.connect(client.config.socket);
// If panic is enabled, disable panic
if (user.user.dispatchStatus=='Panic') {
let myReq = {
userID: user._id,
communityID: user.user.activeCommunity
};
socket.emit('clear_panic', myReq);
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) => {
message.channel.send(`Disabled Panic ${message.author} and set status to \`10-8\`.`);
socket.disconnect();
});
return;
// If panic is disabled, enable panic
} else {
client.forceUpdateStatus(message.channel, message.author.id, 'Panic');
let req = {
userID: user._id,
userUsername: user.user.username,
activeCommunity: user.user.activeCommunity
}
socket.emit('panic_button_update', req);
socket.disconnect();
let guild = await client.dbo.collection("prefixes").findOne({"server.serverID":message.guild.id}).then(guild => guild);
if (guild.server.pingOnPanic) return message.channel.send(`Attention <@&${guild.server.pingRole}>! \`${user.user.username}\` has activated panic`);
return;
}
},
SlashCommand: {
options: [],
/**
*
* @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(`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(`You are not logged in.`);
if (user.user.activeCommunity==null) return interaction.send(`You must join a community to use this command.`);
const socket = io.connect(client.config.socket);
// If panic is enabled, disable panic
if (user.user.dispatchStatus=='Panic') {
let myReq = {
userID: user._id,
communityID: user.user.activeCommunity
};
socket.emit('clear_panic', myReq);
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) => {
interaction.send(`Disabled Panic <@${interaction.member.user.id}> and set status to \`10-8\`.`);
socket.disconnect();
});
return;
// If panic is disabled, enable panic
} else {
client.forceUpdateStatus(interaction, interaction.member.user.id, 'Panic');
let req = {
userID: user._id,
userUsername: user.user.username,
activeCommunity: user.user.activeCommunity
}
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) return message.channel.send(`Attention <@&${guild.server.pingRole}>! \`${user.user.username}\` has activated panic`);
return;
}
},
},
}
+2 -2
View File
@@ -18,7 +18,7 @@ module.exports = {
* @param {*} param3 * @param {*} param3
*/ */
run: async (client, message, args) => { run: async (client, message, args) => {
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 validStatus=['10-8','10-7','10-6','10-11','10-23','10-97','10-15','10-70','10-80', '10-41', '10-42'];
let user = await client.dbo.collection("users").findOne({"user.discord.id":message.author.id}).then(user => user); let user = await client.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 (!user) return message.channel.send(`You are not logged in ${message.author}`);
if (user.user.activeCommunity==null) return message.channel.send(`You must join a community to use this command.`); if (user.user.activeCommunity==null) return message.channel.send(`You must join a community to use this command.`);
@@ -63,7 +63,7 @@ module.exports = {
{ 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-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-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-15 (Subject in Custody)', value: '10-15', }, { name: '10-70 (Foot Pursuit)', value: '10-70', }, { name: '10-80 (Vehicle Pursuit)', value: '10-80' },
{ name: 'Panic', value: 'Panic', }, { name: '10-41 (Log in to CAD)', value: '10-41', }, { name: '10-42 (Log out of CAD)', value: '10-42' }, { name: '10-41 (Log in to CAD)', value: '10-41', }, { name: '10-42 (Log out of CAD)', value: '10-42' },
], ],
}, },
], ],
+1 -1
View File
@@ -56,7 +56,7 @@ module.exports = async (client, message) => {
return client.sendError( return client.sendError(
message.channel, message.channel,
"Missing Permissions!" + GuildDB.DJ "Missing Permissions!" + GuildDB.DJ
? " You need the `DJ` role to access this command." ? " You need the correct role to access this command."
: "" : ""
); );
cmd.run(client, message, args, { GuildDB }); cmd.run(client, message, args, { GuildDB });
+36
View File
@@ -2,6 +2,7 @@ const { Collection, Client, MessageEmbed } = require('discord.js');
const CommandHandler = require('../commands').Commands; const CommandHandler = require('../commands').Commands;
const MongoClient = require('mongodb').MongoClient; const MongoClient = require('mongodb').MongoClient;
const Logger = require("../util/Logger"); const Logger = require("../util/Logger");
const io = require('socket.io-client');
const path = require("path"); const path = require("path");
const fs = require('fs'); const fs = require('fs');
@@ -75,6 +76,41 @@ class LinesPoliceCadBot extends Client {
this.log('Successfully connected to mongoDB'); this.log('Successfully connected to mongoDB');
} }
// This is for the 'panic' command when enabling panic
// May be used by other interaction
async forceUpdateStatus(sendObject, userID, status) {
let validStatus=['10-8','10-7','10-6','10-11','10-23','10-97','10-15','10-70','10-80', '10-41', '10-42', 'Panic'];
let user = await this.dbo.collection("users").findOne({"user.discord.id":userID}).then(user => user);
if (!user) return returnMessage(`You are not logged in <@${userID}>`);
if (user.user.activeCommunity==null) return returnMessage(`You must join a community to use this command.`);
if (!validStatus.includes(status)) return returnMessage(`\`${status}\` is a Invalid Status.`);
let onDuty=null;
let updateDuty=false;
if (status=='10-41') {
onDuty=true;
updateDuty=true;
status='Online';
}
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) => {
sendObject.send(`Succesfully updated status to \`${status}\` <@${userID}>`);
socket.disconnect();
});
}
exists(n){return null!=n&&null!=n&&""!=n} exists(n){return null!=n&&null!=n&&""!=n}
LoadCommands() { LoadCommands() {