Skip to content

Commit

Permalink
Update force stop to stop in outside servers
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroclutch committed May 21, 2024
1 parent 889bb26 commit 3364751
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions commands/mod/forcestop.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import BotCommand from '../../types/command/BotCommand.js'
import { GAMEBOT_PERMISSIONS } from '../../config/types.js'
import { ApplicationCommandOptionType } from 'discord.js'
import logger from 'gamebot/logger'

export default new BotCommand({
name: 'forcestop',
Expand All @@ -8,10 +10,26 @@ export default new BotCommand({
category: 'mod',
permissions: [GAMEBOT_PERMISSIONS.MOD],
dmCommand: false,
args: [],
run: function(msg, _args) {
args: [{
key: 'channel',
description: 'The channel ID to force stop the game in. If not provided, the game in the current channel will be stopped.',
required: false,
type: ApplicationCommandOptionType.Channel
}],
run: async function(msg, args) {
const id = args[0]
if(msg.channel.game) {
msg.channel.game.end()
} else if(id) {
try {
let isEnded = await msg.client.shard.broadcastEval((c, context) => c.gameManager.games.has(context.id) ? (c.gameManager.games.get(context.id).end() || true) : null, { context: { id } })
if(isEnded) {
msg.channel.send(`Game ended successfully in channel <#${id}>.`)
}
} catch(e) {
logger.error(e)
msg.channel.send(`Failed to end game in channel <#${id}>.`)
}
} else {
msg.channel.send('There is no game running in this channel.')
}
Expand Down

0 comments on commit 3364751

Please sign in to comment.