From 2531c6f446da6368ee9e97bfd39281f25be21114 Mon Sep 17 00:00:00 2001 From: issork Date: Wed, 6 Dec 2023 13:42:05 +0100 Subject: [PATCH] fixed CommandHandler --- addons/gift/command_handler.gd | 13 +++++++------ example/Example.gd | 8 ++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/addons/gift/command_handler.gd b/addons/gift/command_handler.gd index 89a7d55..3f1eb80 100644 --- a/addons/gift/command_handler.gd +++ b/addons/gift/command_handler.gd @@ -79,12 +79,13 @@ func handle_command(sender_data : SenderData, msg : String, whisper : bool = fal if(user_perm_flags & cmd_data.permission_level == 0): cmd_no_permission.emit(command, sender_data, cmd_data, arg_ary) return - if(arg_ary.size() == 0): - cmd_data.func_ref.call(CommandInfo.new(sender_data, command, whisper)) - else: - cmd_data.func_ref.call(CommandInfo.new(sender_data, command, whisper), arg_ary) - elif (cmd_data.min_args > 0): - cmd_invalid_argcount.emit(command, sender_data, cmd_data, arg_ary) + if(arg_ary.size() == 0): + if (cmd_data.min_args > 0): + cmd_invalid_argcount.emit(command, sender_data, cmd_data, arg_ary) + return + cmd_data.func_ref.call(CommandInfo.new(sender_data, command, whisper)) + else: + cmd_data.func_ref.call(CommandInfo.new(sender_data, command, whisper), arg_ary) func get_perm_flag_from_tags(tags : Dictionary) -> int: var flag = 0 diff --git a/example/Example.gd b/example/Example.gd index f0e9aa3..239aa74 100644 --- a/example/Example.gd +++ b/example/Example.gd @@ -61,14 +61,14 @@ func _ready() -> void: # Add a list command that accepts between 1 and infinite args. cmd_handler.add_command("list", list, -1, 1) - # For the cmd handler to receive the messages, we have to forward them. + # For the chat example to work, we forward the messages received to the put_chat function. + irc.chat_message.connect(put_chat) + + # We also have to forward the messages to the command handler to handle them. irc.chat_message.connect(cmd_handler.handle_command) # If you also want to accept whispers, connect the signal and bind true as the last arg. irc.whisper_message.connect(cmd_handler.handle_command.bind(true)) - # For the chat example to work, we forward the messages received to the put_chat function. - irc.chat_message.connect(put_chat) - # When we press enter on the chat bar or press the send button, we want to execute the send_message # function. %LineEdit.text_submitted.connect(send_message.unbind(1))