-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to set game option defaults
- Loading branch information
1 parent
ad7160c
commit 624a0d5
Showing
6 changed files
with
169 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import BaseCommand, { CommandArgs } from "../interfaces/base_command"; | ||
import { IPCLogger } from "../../logger"; | ||
import { getGuildPreference } from "../../helpers/game_utils"; | ||
import { | ||
getDebugLogHeader, | ||
sendInfoMessage, | ||
} from "../../helpers/discord_utils"; | ||
import MessageContext from "../../structures/message_context"; | ||
import CommandPrechecks from "../../command_prechecks"; | ||
|
||
const logger = new IPCLogger("default"); | ||
|
||
export default class DefaultCommand implements BaseCommand { | ||
preRunChecks = [{ checkFn: CommandPrechecks.competitionPrecheck }]; | ||
|
||
validations = { | ||
minArgCount: 0, | ||
maxArgCount: 0, | ||
arguments: [], | ||
}; | ||
|
||
aliases = ["setdefault", "setdefaults", "defaults"]; | ||
|
||
help = { | ||
name: "default", | ||
description: `Sets the current game option as the defaults (for ${process.env.BOT_PREFIX}reset or per-option resets). This should only be used by experienced users!`, | ||
usage: ",default", | ||
examples: [ | ||
{ | ||
example: "`,default`", | ||
explanation: "Sets the current game option as the defaults.", | ||
}, | ||
], | ||
priority: 130, | ||
}; | ||
|
||
call = async ({ message }: CommandArgs): Promise<void> => { | ||
const guildPreference = await getGuildPreference(message.guildID); | ||
await guildPreference.setAsDefault(); | ||
logger.info(`${getDebugLogHeader(message)} | Set default game options`); | ||
|
||
await sendInfoMessage(MessageContext.fromMessage(message), { | ||
title: "Success!", | ||
description: | ||
"Default game options has been set to the current options!", | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
exports.up = function (knex) { | ||
return knex.schema.createTable("game_option_defaults", (table) => { | ||
table.string("guild_id").notNullable(); | ||
table.string("option_name").notNullable(); | ||
table.json("option_value"); | ||
table.unique(["guild_id", "option_name"]); | ||
}); | ||
}; | ||
|
||
exports.down = function (knex) { | ||
return knex.schema.dropTableIfExists("game_option_defaults"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters