134 lines
4.7 KiB
Ruby
134 lines
4.7 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module DiscordInteractions
|
|
module Commands
|
|
module_function
|
|
|
|
def commands
|
|
[
|
|
{
|
|
description: "Manage your API keys",
|
|
name: "apikey",
|
|
type: DiscordConstants::ApplicationCommandTypes::CHAT_INPUT,
|
|
options: [
|
|
{
|
|
type: DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND,
|
|
name: "create",
|
|
description: "Create an API key",
|
|
options: [],
|
|
},
|
|
{
|
|
type: DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND,
|
|
name: "delete",
|
|
description: "Delete an API key",
|
|
options: [
|
|
{
|
|
type: DiscordConstants::ApplicationCommandOptionTypes::STRING,
|
|
name: "key",
|
|
description: "The API key to delete",
|
|
autocomplete: true,
|
|
required: true,
|
|
choices: [],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
type: DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND,
|
|
name: "list",
|
|
description: "List your API keys",
|
|
options: [],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
description: "Manage API keys (developer only)",
|
|
name: "apidev",
|
|
type: DiscordConstants::ApplicationCommandTypes::CHAT_INPUT,
|
|
options: [
|
|
{
|
|
type: DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND,
|
|
name: "list",
|
|
description: "List a user's api keys.",
|
|
options: [
|
|
{
|
|
type: DiscordConstants::ApplicationCommandOptionTypes::USER,
|
|
name: "user",
|
|
description: "The user to list the api keys of.",
|
|
required: true,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
type: DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND,
|
|
name: "disable",
|
|
description: "Disable an api key.",
|
|
options: [
|
|
{
|
|
type: DiscordConstants::ApplicationCommandOptionTypes::STRING,
|
|
name: "key",
|
|
description: "The api key to disable.",
|
|
choices: [],
|
|
required: true,
|
|
},
|
|
{
|
|
type: DiscordConstants::ApplicationCommandOptionTypes::STRING,
|
|
name: "reason",
|
|
description: "The reason for deactivating the key.",
|
|
choices: [],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
type: DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND,
|
|
name: "enable",
|
|
description: "Enable an api key.",
|
|
options: [
|
|
{
|
|
type: DiscordConstants::ApplicationCommandOptionTypes::STRING,
|
|
name: "key",
|
|
description: "The api key to enable.",
|
|
choices: [],
|
|
required: true,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
type: DiscordConstants::ApplicationCommandOptionTypes::SUB_COMMAND,
|
|
name: "stats",
|
|
description: "Get the stats of an api key.",
|
|
options: [
|
|
{
|
|
type: DiscordConstants::ApplicationCommandOptionTypes::STRING,
|
|
name: "key",
|
|
description: "The api key to get the stats of.",
|
|
choices: [],
|
|
required: false,
|
|
},
|
|
{
|
|
type: DiscordConstants::ApplicationCommandOptionTypes::STRING,
|
|
name: "ip",
|
|
description: "The ip to get the stats of.",
|
|
choices: [],
|
|
required: false,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
]
|
|
end
|
|
|
|
def register
|
|
cmd = Cache.redis.get("discord-commands")
|
|
return false if cmd.present? && cmd == commands.to_json
|
|
if Rails.env.development?
|
|
Requests::DiscordGuildCommands.default.update(commands)
|
|
else
|
|
Requests::DiscordGlobalCommands.default.update(commands)
|
|
end
|
|
Cache.redis.set("discord-commands", commands.to_json)
|
|
true
|
|
end
|
|
end
|
|
end
|