From db45096944a6a92e55708076f5854f741d144e35 Mon Sep 17 00:00:00 2001 From: Lartza Date: Tue, 19 Jun 2018 13:43:25 +0300 Subject: [PATCH 1/4] Config writing, store volume changes. Closes #21 --- mumbleBot.py | 7 ++++++- util.py | 5 +++++ variables.py | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mumbleBot.py b/mumbleBot.py index f716a90..9ebbe9f 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -184,6 +184,7 @@ class MumbleBot: self.volume = float(float(parameter) / 100) self.send_msg_channel(var.config.get('strings', 'change_volume') % ( int(self.volume * 100), self.mumble.users[text.actor]['name'])) + var.config.set('bot', 'volume', self.volume) else: self.send_msg_channel(var.config.get('strings', 'current_volume') % int(self.volume * 100)) @@ -372,6 +373,9 @@ class MumbleBot: time.sleep(0.01) time.sleep(0.5) + if self.exit: + util.write_config() + def stop(self): if self.thread: var.current_music = None @@ -408,8 +412,9 @@ if __name__ == '__main__': parser.add_argument("-c", "--channel", dest="channel", type=str, help="Default channel for the bot") args = parser.parse_args() + var.configfile = args.config config = configparser.ConfigParser(interpolation=None, allow_no_value=True) - parsed_configs = config.read(['configuration.default.ini', args.config], encoding='latin-1') + parsed_configs = config.read(['configuration.default.ini', var.configfile], encoding='latin-1') if len(parsed_configs) == 0: print('Could not read configuration from file \"{}\"'.format(args.config), file=sys.stderr) diff --git a/util.py b/util.py index c569fea..8df6dfc 100644 --- a/util.py +++ b/util.py @@ -66,6 +66,11 @@ def zipdir(zippath, zipname_prefix=None): return zipname +def write_config(): + with open(var.configfile, 'w') as f: + var.config.write(f) + + class Dir(object): def __init__(self, path): self.name = os.path.basename(path.strip('/')) diff --git a/variables.py b/variables.py index b31c6d4..be2ea54 100644 --- a/variables.py +++ b/variables.py @@ -3,4 +3,5 @@ playlist = [] user = "" music_folder = "" is_proxified = False +configfile = None config = None From 2746e4acaea1577820660ffe34d5413230c2dc9a Mon Sep 17 00:00:00 2001 From: Lartza Date: Tue, 19 Jun 2018 13:50:03 +0300 Subject: [PATCH 2/4] Fix getting username config variable --- mumbleBot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mumbleBot.py b/mumbleBot.py index 9ebbe9f..2f0b512 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -85,11 +85,11 @@ class MumbleBot: password = var.config.get("server", "password") if args.user: - user = args.user + username = args.user else: - user = var.config.get("bot", "user") + username = var.config.get("bot", "username") - self.mumble = pymumble.Mumble(host, user=user, port=port, password=password, + self.mumble = pymumble.Mumble(host, user=username, port=port, password=password, debug=var.config.getboolean('debug', 'mumbleConnection')) self.mumble.callbacks.set_callback("text_received", self.message_received) From 92c3ae4347a29d6db62336eed9f8719087f23e1b Mon Sep 17 00:00:00 2001 From: Lartza Date: Tue, 19 Jun 2018 13:53:04 +0300 Subject: [PATCH 3/4] Missing repeat command in config --- configuration.default.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/configuration.default.ini b/configuration.default.ini index 2e89aee..e580191 100644 --- a/configuration.default.ini +++ b/configuration.default.ini @@ -39,6 +39,7 @@ kill = kill stop_and_getout = oust joinme = joinme queue = queue +repeat = repeat [radio] ponyville = http://192.99.131.205:8000/stream.mp3 From 8e09635526dc39f93311e8ab6a3c4e185d5e50f0 Mon Sep 17 00:00:00 2001 From: Lartza Date: Tue, 19 Jun 2018 13:56:14 +0300 Subject: [PATCH 4/4] Config values need to be strings --- mumbleBot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mumbleBot.py b/mumbleBot.py index 2f0b512..e8657a2 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -184,7 +184,7 @@ class MumbleBot: self.volume = float(float(parameter) / 100) self.send_msg_channel(var.config.get('strings', 'change_volume') % ( int(self.volume * 100), self.mumble.users[text.actor]['name'])) - var.config.set('bot', 'volume', self.volume) + var.config.set('bot', 'volume', str(self.volume)) else: self.send_msg_channel(var.config.get('strings', 'current_volume') % int(self.volume * 100))