make minecraft sub commands use new sub command handler
This commit is contained in:
parent
a42ad16135
commit
a35b423647
@ -1,12 +1,15 @@
|
|||||||
local Discordia = require('discordia')
|
local Discordia = require('discordia')
|
||||||
local json = require('json')
|
local json = require('json')
|
||||||
local http_request = require('../Modules/http.lua')
|
local http_request = require('../Modules/http.lua')
|
||||||
|
local SubCommandHandler = require('../Modules/SubCommandHandler.lua')
|
||||||
Discordia.extensions()
|
Discordia.extensions()
|
||||||
|
|
||||||
local ApplicationCommandOptionTypes = Discordia.enums.appCommandOptionType
|
local ApplicationCommandOptionTypes = Discordia.enums.appCommandOptionType
|
||||||
|
|
||||||
local SlashCommandTools = require('discordia-slash').util.tools()
|
local SlashCommandTools = require('discordia-slash').util.tools()
|
||||||
|
|
||||||
|
local MinecraftSubCommandHandler = SubCommandHandler.new()
|
||||||
|
|
||||||
local MinecraftMainCommand = SlashCommandTools.slashCommand('minecraft', 'Minecraft server related commands')
|
local MinecraftMainCommand = SlashCommandTools.slashCommand('minecraft', 'Minecraft server related commands')
|
||||||
|
|
||||||
local MinecraftStatusSubCommand = SlashCommandTools.subCommand('status', 'Get the Minecraft server status according to the preferred IP address set for this server')
|
local MinecraftStatusSubCommand = SlashCommandTools.subCommand('status', 'Get the Minecraft server status according to the preferred IP address set for this server')
|
||||||
@ -34,8 +37,7 @@ if MinecraftDataFile then
|
|||||||
MinecraftDataFile:close()
|
MinecraftDataFile:close()
|
||||||
end
|
end
|
||||||
|
|
||||||
local SubCommandCallbacks = {}
|
MinecraftSubCommandHandler:AddSubCommand(MinecraftStatusSubCommand.name, function(Interaction, Command, Args)
|
||||||
local function Status(Interaction, Command, Args)
|
|
||||||
local GuildId = Interaction.guild and Interaction.guild.id
|
local GuildId = Interaction.guild and Interaction.guild.id
|
||||||
if not GuildId then
|
if not GuildId then
|
||||||
return Interaction:reply('You cannot use this command outside of a Discord server', true)
|
return Interaction:reply('You cannot use this command outside of a Discord server', true)
|
||||||
@ -91,9 +93,9 @@ local function Status(Interaction, Command, Args)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
return Interaction:reply({embed = EmbedData})
|
return Interaction:reply({embed = EmbedData})
|
||||||
end
|
end)
|
||||||
|
|
||||||
local function SetIp(Interaction, Command, Args)
|
MinecraftSubCommandHandler:AddSubCommand(MinecraftSetIpSubCommand.name, function(Interaction, Command, Args)
|
||||||
local ServerIPStr = Args.ip
|
local ServerIPStr = Args.ip
|
||||||
|
|
||||||
local GuildId = Interaction.guild and Interaction.guild.id
|
local GuildId = Interaction.guild and Interaction.guild.id
|
||||||
@ -114,25 +116,9 @@ local function SetIp(Interaction, Command, Args)
|
|||||||
io.open('minecraft_data.json','w+'):write(json.encode(GlobalMinecraftData)):close()
|
io.open('minecraft_data.json','w+'):write(json.encode(GlobalMinecraftData)):close()
|
||||||
|
|
||||||
return Interaction:reply('Successfully added `'..ServerIP..':'..ServerPort..'` for ServerId='..GuildId)
|
return Interaction:reply('Successfully added `'..ServerIP..':'..ServerPort..'` for ServerId='..GuildId)
|
||||||
end
|
end)
|
||||||
SubCommandCallbacks.status = Status
|
|
||||||
SubCommandCallbacks.setip = SetIp
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function Callback(Interaction, Command, Args)
|
|
||||||
local SubCommandOption = Command.options[1]
|
|
||||||
if SubCommandOption.type == ApplicationCommandOptionTypes.subCommand then
|
|
||||||
local SubCommandName = SubCommandOption.name
|
|
||||||
local SubCommandCallback = SubCommandCallbacks[SubCommandName]
|
|
||||||
local SubCommandArgs = Args[SubCommandName]
|
|
||||||
if SubCommandCallback then
|
|
||||||
SubCommandCallback(Interaction, Command, SubCommandArgs)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Command = MinecraftMainCommand,
|
Command = MinecraftMainCommand,
|
||||||
Callback = Callback
|
Callback = MinecraftSubCommandHandler:GetMainCommandCallback()
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user