From cc5a45c06b28570c3a891031df874023cafdd65e Mon Sep 17 00:00:00 2001 From: azlux Date: Wed, 27 Jun 2018 01:09:23 +0200 Subject: [PATCH] #19 ignore user not in the same channel execpt the admin --- configuration.default.ini | 2 ++ mumbleBot.py | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/configuration.default.ini b/configuration.default.ini index c680a9c..47143b1 100644 --- a/configuration.default.ini +++ b/configuration.default.ini @@ -19,6 +19,7 @@ ignored_folders = tmp ignored_files = Thumbs.db announce_current_music = True +allow_other_channel_message = False [webinterface] enabled = False @@ -63,6 +64,7 @@ multiple_matches = Track not found! Possible candidates: queue_contents = The next items in the queue are: queue_empty = No more music in the playlist! now_playing = Now playing %s
%s +not_in_my_channel = You're not in my channel, command refused ! help = Command available:
!file [path] diff --git a/mumbleBot.py b/mumbleBot.py index 126cfae..b0ff112 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -129,7 +129,13 @@ class MumbleBot: logging.info(command + ' - ' + parameter + ' by ' + user) - if command == var.config.get('command', 'play_file') and parameter: + if command == var.config.get('command', 'joinme'): + self.mumble.users.myself.move_in(self.mumble.users[text.actor]['channel_id']) + + elif 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_message(var.config.get('strings', 'not_in_my_channel')) + + elif command == var.config.get('command', 'play_file') and parameter: music_folder = var.config.get('bot', 'music_folder') # sanitize "../" and so on path = os.path.abspath(os.path.join(music_folder, parameter)) @@ -166,7 +172,7 @@ class MumbleBot: self.stop() elif command == var.config.get('command', 'kill'): - if self.is_admin(text.actor): + if self.is_admin(user): self.stop() self.exit = True else: @@ -177,9 +183,6 @@ class MumbleBot: if self.channel: self.mumble.channels.find_by_name(self.channel).move_in() - elif command == var.config.get('command', 'joinme'): - self.mumble.users.myself.move_in(self.mumble.users[text.actor]['channel_id']) - elif command == var.config.get('command', 'volume'): if parameter is not None and parameter.isdigit() and 0 <= int(parameter) <= 100: self.volume = float(float(parameter) / 100) @@ -246,8 +249,8 @@ class MumbleBot: msg = var.config.get('strings', 'queue_empty') else: msg = var.config.get('strings', 'queue_contents') + '
' - for (type, path) in var.playlist: - msg += '({}) {}
'.format(type, path) + for (music_type, path) in var.playlist: + msg += '({}) {}
'.format(music_type, path) self.send_msg_channel(msg) @@ -268,9 +271,9 @@ class MumbleBot: self.playing = True def is_admin(self, user): - username = self.mumble.users[user]['name'] list_admin = var.config.get('bot', 'admin').split(';') - if username in list_admin: + print(list_admin) + if user in list_admin: return True else: return False