From db45096944a6a92e55708076f5854f741d144e35 Mon Sep 17 00:00:00 2001 From: Lartza Date: Tue, 19 Jun 2018 13:43:25 +0300 Subject: [PATCH] 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