diff --git a/commands/updateStatus.js b/commands/updateStatus.js new file mode 100644 index 0000000..0fd49e4 --- /dev/null +++ b/commands/updateStatus.js @@ -0,0 +1,113 @@ +const { MessageEmbed } = 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: [], + }, + aliases: ["update_status"], + /** + * + * @param {require("../structures/LinesPoliceCadBot")} client + * @param {import("discord.js").Message} message + * @param {string[]} args + * @param {*} param3 + */ + 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 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.user.activeCommunity==null) return message.channel.send(`You must join a community to use this command.`); + if (args.length==0) return message.channel.send(`You must provide a new status.`); + if (!validStatus.includes(args[0])) return message.channel.send(`\`${args[0]}\` is a Invalid Status.`); + 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(client.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(); + }); + }, + SlashCommand: { + 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: 'Panic', value: 'Panic', }, { name: '10-41 (Log in to CAD)', value: '10-41', }, { name: '10-42 (Log out of CAD)', value: '10-42' }, + ], + }, + ], + /** + * + * @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 ${message.author}`); + if (user.user.activeCommunity==null) return message.channel.send(`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) => { + interaction.send(`Succesfully updated <@${interaction.member.user.id}>'s status to \`${args[0].value}\``); + socket.disconnect(); + }); + }, + }, +} \ No newline at end of file