Added the option to !opt-in/opt-out [onlinebot only]

Fixed command & event threading
Events are now threaded by event_type (i.e. all buddy_logon events get ran in the same one)
Added default preferences
Fixed recipe loading for multiple installs (i.e. on different machines)
This commit is contained in:
2021-08-27 13:58:47 +02:00
parent d0c8c1744c
commit c04f76c0db
24 changed files with 258 additions and 122 deletions
+17 -16
View File
@@ -86,7 +86,7 @@ class CommandService:
al = access_levels.get(command_key, None)
if al is not None and al != access_level.lower():
print(handler)
raise Exception("Different access levels specified for forms of command '%s'" % command_key)
raise Exception(f"Different access levels specified for forms of command '{command_key}'")
access_levels[command_key] = access_level
self.register(handler, cmd_name, params, access_level, description, inst.module_name, help_text,
@@ -182,10 +182,10 @@ class CommandService:
"""
if value in self.channels:
self.logger.error("Could not register command channel '%s': command channel already registered" % value)
self.logger.error(f"Could not register command channel '{value}': command channel already registered")
return
self.logger.debug("Registering command channel '%s'" % value)
self.logger.debug(f"Registering command channel '{value}'")
self.channels[value] = label
def is_command_channel(self, channel):
@@ -228,11 +228,11 @@ class CommandService:
command_alias = self.command_alias_service.check_for_alias(command_str)
if alias_depth_count > 20:
raise Exception("Command alias infinite recursion detected for command '%s'" % message)
raise Exception(f"Command alias infinite recursion detected for command '{message}'")
cmd_configs = self.get_command_configs(command_str, channel)
access_level = self.access_service.get_access_level(char_id)
sender = SenderObj(char_id, self.character_service.resolve_char_to_name(char_id, "Unknown(%d)" % char_id),
sender = SenderObj(char_id, self.character_service.resolve_char_to_name(char_id, f"Unknown({char_id:d})"),
access_level)
if cmd_configs:
# given a list of cmd_configs that are enabled, see if one has regex that matches incoming command_str
@@ -245,7 +245,7 @@ class CommandService:
if response is not None:
reply(response)
except Exception as e:
self.logger.error("error processing command: %s" % message, e)
self.logger.error(f"error processing command: {message}", e)
self.relay_hub_service.send_message("access_denied_logger", sender,
f"[ERROR] {sender.name}: {message}",
f"[ERROR] {sender.name}: {message}")
@@ -262,16 +262,17 @@ class CommandService:
reply(self.format_help_text(command_str, help_text))
else:
# the command is known, but no help is returned, therefore user does not have access to command
if access_level['label'] != "all":
self.relay_hub_service.send_message("access_denied_logger", sender,
f"[DENIED] {sender.name}: {message}",
f"[DENIED] {sender.name}: {message}")
self.bot.send_mass_message(char_id, self.getresp("global", "access_denied"))
self.access_denied_response(message, sender, cmd_config, reply)
# if access_level['label'] != "all":
# self.relay_hub_service.send_message("access_denied_logger", sender,
# f"[DENIED] {sender.name}: {message}",
# f"[DENIED] {sender.name}: {message}")
# self.bot.send_mass_message(char_id, self.getresp("global", "access_denied"))
else:
self.handle_unknown_command(command_str, command_args, channel, sender, reply)
except Exception as e:
self.logger.error("error processing command: %s" % message, e)
sender = SenderObj(char_id, self.character_service.resolve_char_to_name(char_id, "Unknown(%d)" % char_id),
self.logger.error(f"error processing command: {message}", e)
sender = SenderObj(char_id, self.character_service.resolve_char_to_name(char_id, f"Unknown({char_id:d})"),
0)
self.relay_hub_service.send_message("access_denied_logger", sender, f"[ERROR] {sender.name}: {message}",
f"[ERROR] {sender.name}: {message}")
@@ -426,7 +427,7 @@ class CommandService:
False)
t: Thread = Thread(target=i, daemon=True)
t.run()
t.start()
def handle_private_channel_message(self, conn: Conn, packet: server_packets.PrivateChannelMessage):
if not self.setting_service.get("accept_commands_from_slave_bots").get_value() and conn.id != "main":
@@ -449,7 +450,7 @@ class CommandService:
lambda msg: self.bot.send_private_channel_message(msg, private_channel_id=conn.char_id,
conn_id=conn.id),
conn,
False), daemon=True).run()
False), daemon=True).start()
def handle_public_channel_message(self, conn: Conn, packet: server_packets.PublicChannelMessage):
if not self.setting_service.get("accept_commands_from_slave_bots").get_value() and conn.id != "main":
@@ -472,7 +473,7 @@ class CommandService:
packet.char_id,
lambda msg: self.bot.send_org_message(msg, conn_id=conn.id),
conn,
False), daemon=True).run()
False), daemon=True).start()
def trim_command_symbol(self, s):
symbol = self.setting_service.get("symbol").get_value()