Added config commands

This commit is contained in:
gpkvt 2022-08-23 14:13:58 +02:00
parent 487387a3cb
commit ec9a1256d9
3 changed files with 73 additions and 4 deletions

View File

@ -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

View File

@ -173,6 +173,8 @@ Additional commands (broadcaster and mods only) are:
* `!ton`: Turn TTS back on
* `!dtts <username>`: Disable TTS for the given user
* `!ptts <username>`: Allow TTS for the given user
* `!usermap <username> <spoken name>`: Add an entry to the usermapping in `config.yml`
* `!delay <int>`: 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

61
tts.py
View File

@ -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()