]> git.0d.be Git - botaradio.git/commitdiff
fix: you are not in my channel when joinme #92
authorTerry Geng <gengyanda@gmail.com>
Tue, 10 Mar 2020 00:58:59 +0000 (08:58 +0800)
committerTerry Geng <gengyanda@gmail.com>
Tue, 10 Mar 2020 00:58:59 +0000 (08:58 +0800)
command.py
mumbleBot.py

index 7c97eccb7767e5d450b7231dc3693720b6200e1a..f53fb6a977f0eeb4133888c2a3caf3984d5642ac 100644 (file)
@@ -20,7 +20,7 @@ from media.radio import RadioItem
 log = logging.getLogger("bot")
 
 def register_all_commands(bot):
-    bot.register_command(constants.commands('joinme'), cmd_joinme)
+    bot.register_command(constants.commands('joinme'), cmd_joinme, no_partial_match=False, access_outside_channel=True)
     bot.register_command(constants.commands('user_ban'), cmd_user_ban)
     bot.register_command(constants.commands('user_unban'), cmd_user_unban)
     bot.register_command(constants.commands('url_ban'), cmd_url_ban)
@@ -37,7 +37,7 @@ def register_all_commands(bot):
     bot.register_command(constants.commands('rb_play'), cmd_rb_play)
     bot.register_command(constants.commands('yt_search'), cmd_yt_search)
     bot.register_command(constants.commands('yt_play'), cmd_yt_play)
-    bot.register_command(constants.commands('help'), cmd_help)
+    bot.register_command(constants.commands('help'), cmd_help, no_partial_match=False, access_outside_channel=True)
     bot.register_command(constants.commands('stop'), cmd_stop)
     bot.register_command(constants.commands('clear'), cmd_clear)
     bot.register_command(constants.commands('kill'), cmd_kill)
@@ -62,8 +62,8 @@ def register_all_commands(bot):
     bot.register_command(constants.commands('search'), cmd_search_library)
     bot.register_command(constants.commands('add_from_shortlist'), cmd_shortlist)
     bot.register_command(constants.commands('delete_from_library'), cmd_delete_from_library)
-    bot.register_command(constants.commands('drop_database'), cmd_drop_database, True)
-    bot.register_command(constants.commands('rescan'), cmd_refresh_cache, True)
+    bot.register_command(constants.commands('drop_database'), cmd_drop_database, no_partial_match=True)
+    bot.register_command(constants.commands('rescan'), cmd_refresh_cache, no_partial_match=True)
 
     # Just for debug use
     bot.register_command('rtrms', cmd_real_time_rms, True)
index 03cb41bf662b82c96a2730a3eb47a8ea8e8b8466..e8fc45ee6e36c793308bb3de8b2f7d3b772c84d0 100644 (file)
@@ -184,12 +184,14 @@ class MumbleBot:
         else:
             self.log.debug("update: no new version found.")
 
-    def register_command(self, cmd, handle, no_partial_match=False):
+    def register_command(self, cmd, handle, no_partial_match=False, access_outside_channel=False):
         cmds = cmd.split(",")
         for command in cmds:
             command = command.strip()
             if command:
-                self.cmd_handle[command] = { 'handle': handle, 'partial_match': not no_partial_match}
+                self.cmd_handle[command] = { 'handle': handle,
+                                             'partial_match': not no_partial_match,
+                                             'access_outside_channel': access_outside_channel}
                 self.log.debug("bot: command added: " + command)
 
     def set_comment(self):
@@ -225,12 +227,6 @@ class MumbleBot:
             self.log.info('bot: received command ' + command + ' - ' + parameter + ' by ' + user)
 
             # Anti stupid guy function
-            if not self.is_admin(user) and not var.config.getboolean('bot', 'allow_other_channel_message') \
-                    and self.mumble.users[text.actor]['channel_id'] != self.mumble.users.myself['channel_id']:
-                self.mumble.users[text.actor].send_text_message(
-                    constants.strings('not_in_my_channel'))
-                return
-
             if not self.is_admin(user) and not var.config.getboolean('bot', 'allow_private_message') and text.session:
                 self.mumble.users[text.actor].send_text_message(
                     constants.strings('pm_not_allowed'))
@@ -254,6 +250,15 @@ class MumbleBot:
             try:
                 if command in self.cmd_handle:
                     command_exc = command
+
+                    if not self.cmd_handle[command]['access_outside_channel'] \
+                            and not self.is_admin(user) \
+                            and not var.config.getboolean('bot', 'allow_other_channel_message') \
+                            and self.mumble.users[text.actor]['channel_id'] != self.mumble.users.myself['channel_id']:
+                        self.mumble.users[text.actor].send_text_message(
+                            constants.strings('not_in_my_channel'))
+                        return
+
                     self.cmd_handle[command]['handle'](self, user, text, command, parameter)
                 else:
                     # try partial match
@@ -266,6 +271,16 @@ class MumbleBot:
                     if len(matches) == 1:
                         self.log.info("bot: {:s} matches {:s}".format(command, matches[0]))
                         command_exc = matches[0]
+
+                        if not self.cmd_handle[command]['access_outside_channel'] \
+                                and not self.is_admin(user) \
+                                and not var.config.getboolean('bot', 'allow_other_channel_message') \
+                                and self.mumble.users[text.actor]['channel_id'] != self.mumble.users.myself[
+                            'channel_id']:
+                            self.mumble.users[text.actor].send_text_message(
+                                constants.strings('not_in_my_channel'))
+                            return
+
                         self.cmd_handle[command_exc]['handle'](self, user, text, command_exc, parameter)
                     elif len(matches) > 1:
                         self.mumble.users[text.actor].send_text_message(