From ec9a1256d9000b036f5c69b3c5b83fe5f05cf71c Mon Sep 17 00:00:00 2001 From: gpkvt Date: Tue, 23 Aug 2022 14:13:58 +0200 Subject: [PATCH] Added config commands --- CHANGELOG.md | 8 +++++++ README.md | 8 ++++--- tts.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 73 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d40c9b..db08426 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to this project will be documented in this file. If there is a `Changed` section please read carefully, as this often means that you will need to adapt your `config.yml`, otherwise the bot might fail to start. +## [1.4.0] - 2022-08-23 + +### Added 1.4.0 + +* `!usermap` command added +* `!delay` command added +* Darkmode added + ## [1.3.2] - 2022-08-19 ### Fixed 1.3.2 diff --git a/README.md b/README.md index 77ad4d7..166f8f9 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,8 @@ Additional commands (broadcaster and mods only) are: * `!ton`: Turn TTS back on * `!dtts `: Disable TTS for the given user * `!ptts `: Allow TTS for the given user +* `!usermap `: Add an entry to the usermapping in `config.yml` +* `!delay `: Adjust the `clearmsg_timeout` in `config.yml` ### Additional features @@ -241,13 +243,13 @@ This project is licensed under the GPLv3 License - see [LICENSE](https://gitlab. ### Libraries -* [Python Software Foundation and contributors](https://www.python.org/) +* [Python](https://www.python.org/) +* [jQuery](https://jquery.org/) +* [Bootstrap](https://getbootstrap.com/) * [PyYAML](https://pyyaml.org/) * [requests](https://requests.readthedocs.io/en/latest/) * [fuzzywuzzy](https://github.com/seatgeek/fuzzywuzzy) * [pyinstaller](https://pyinstaller.org/) -* [OpenJS Foundation and jQuery contributors](https://jquery.org/) -* [Twitter Inc. and Bootstrap contributors](https://getbootstrap.com/) ## Disclaimer diff --git a/tts.py b/tts.py index f7ff5b1..1edaf2a 100644 --- a/tts.py +++ b/tts.py @@ -236,6 +236,14 @@ class IRC: logging.debug("!ptts command detected") self.Commands.ptts(self, msg) + elif msg.startswith('!usermap'): + logging.info('!usermap command detected') + self.Commands.usermap(self, msg) + + elif msg.startswith('!delay'): + logging.info('!delay command detected') + self.Commands.delay(self, msg) + elif msg.startswith('!toff'): logging.info('TTS is now turned off') msg_queue.clear() @@ -593,6 +601,57 @@ class IRC: return True + def delay(self, msg): + """ !delay command + + Adjust the delay setting in config.yml + + :param str msg: The IRC message triggering the command + """ + + try: + delay = msg.split(' ')[1] + except: # pylint: disable=bare-except + delay = False + + if delay: + with open('config.yml','r', encoding='utf-8') as yamlfile: + cur_yaml = yaml.safe_load(yamlfile) + cur_yaml['irc']['clearmsg_timeout'] = int(delay) + + if cur_yaml: + with open('config.yml','w', encoding='utf-8') as yamlfile: + yaml.safe_dump(cur_yaml, yamlfile) + load_config() + + + def usermap(self, msg): + """ !usermap command + + Adds new entries to usermapping in config.yml + + :param str msg: The IRC message triggering the command + """ + + try: + msg = msg.replace('!usermap ', '') + splitmsg = msg.split(" ") + username, *mappingname = splitmsg + mappingname = ' '.join(mappingname) + except: # pylint: disable=bare-except + username = False + mappingname = False + + if username and mappingname: + with open('config.yml','r', encoding='utf-8') as yamlfile: + cur_yaml = yaml.safe_load(yamlfile) + cur_yaml['usermapping'].update({username: mappingname}) + + if cur_yaml: + with open('config.yml','w', encoding='utf-8') as yamlfile: + yaml.safe_dump(cur_yaml, yamlfile) + load_config() + def quickvote(self, msg): """ !quickvote command @@ -1108,7 +1167,7 @@ if __name__ == "__main__": if sys.argv[1:]: if sys.argv[1] == "--version": print('Simple TTS Bot') - print('Version 1.3.2') + print('Version 1.4.0') sys.exit(1) main()