make sub command handler for easier sub commands
This commit is contained in:
parent
a479e88823
commit
a42ad16135
41
src/modules/SubCommandHandler.lua
Normal file
41
src/modules/SubCommandHandler.lua
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
--I LOVE USELESS CLASSES!
|
||||||
|
local Discordia = require('discordia')
|
||||||
|
|
||||||
|
local ApplicationCommandOptionTypes = Discordia.enums.appCommandOptionType
|
||||||
|
|
||||||
|
local SubCommandHandler = {}
|
||||||
|
SubCommandHandler.__index = SubCommandHandler
|
||||||
|
|
||||||
|
function SubCommandHandler.new()
|
||||||
|
local self = setmetatable({}, SubCommandHandler)
|
||||||
|
|
||||||
|
self.SubCommandCallbacks = {}
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function SubCommandHandler:AddSubCommand(SubCommandName, SubCommandCallback)
|
||||||
|
if self.SubCommandCallbacks[SubCommandName] then
|
||||||
|
return print('no can do')
|
||||||
|
end
|
||||||
|
|
||||||
|
self.SubCommandCallbacks[SubCommandName] = SubCommandCallback
|
||||||
|
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function SubCommandHandler:GetMainCommandCallback()
|
||||||
|
return function(Interaction, Command, Args)
|
||||||
|
local SubCommandOption = Command.options[1]
|
||||||
|
if SubCommandOption.type == ApplicationCommandOptionTypes.subCommand then
|
||||||
|
local SubCommandName = SubCommandOption.name
|
||||||
|
local SubCommandCallback = self.SubCommandCallbacks[SubCommandName]
|
||||||
|
local SubCommandArgs = Args[SubCommandName]
|
||||||
|
if SubCommandCallback then
|
||||||
|
SubCommandCallback(Interaction, Command, SubCommandArgs)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return SubCommandHandler
|
Loading…
Reference in New Issue
Block a user