From bec6d3de62c60aae5f23f79520ebff68653f90b6 Mon Sep 17 00:00:00 2001 From: Allen Wittenauer Date: Tue, 6 Jun 2023 08:15:03 -0700 Subject: [PATCH] Add the ability to turn off Twitch Chat replies --- docs/help/howdoi.rst | 7 ++++- docs/output/twitchbot.rst | 3 ++ nowplaying/resources/twitchchat_ui.ui | 40 ++++++++++++++++++++++++--- nowplaying/twitch/chat.py | 7 ++++- nowplaying/upgrade.py | 26 ++++++++++++----- 5 files changed, 70 insertions(+), 13 deletions(-) diff --git a/docs/help/howdoi.rst b/docs/help/howdoi.rst index e6d85c94..78b7542a 100644 --- a/docs/help/howdoi.rst +++ b/docs/help/howdoi.rst @@ -13,7 +13,7 @@ The Twitch commands are all read directly from files. So copying one file to an Change the time Twitch announcements happen? -------------------------------------------- -Under Settings,Twitch Chat, there is an 'Announce Delay' field that takes number of seconds to wait before announcing to chat. To things to keep in mind: +Under Settings -> Twitch Chat there is an 'Announce Delay' field that takes number of seconds to wait before announcing to chat. To things to keep in mind: 1. It takes partial seconds, so `.5` would be half of a second. 2. This delay is **in addition** to the write delay under General. Therefore if Write Delay is 5 seconds and Twitch Chat Announce Delay is 5 seconds, it should be approximately 10 seconds from the track being switched out before the message goes out. @@ -32,3 +32,8 @@ Put artist graphics on my OBS/SLOBS/SE.Live/etc? Configure a ``Browser Source`` for your scene and put in one of the Supported URLs that is listed on the `Webserver `_ page. +Stop autoposting the track info in Twitch chat? +----------------------------------------------- + +1. Under Settings -> Twitch Chat, set the announce template to be empty. +2. Save diff --git a/docs/output/twitchbot.rst b/docs/output/twitchbot.rst index 2648e2d8..36ee27e1 100644 --- a/docs/output/twitchbot.rst +++ b/docs/output/twitchbot.rst @@ -103,6 +103,9 @@ Twitch Chat Configuration #. Check Enable #. To have the bot announce new tracks in chat, select the template. +By default, the bot will respond to user commands in the form of Twitch Replies. If you +would prefer the bot just post a message, uncheck the Replies option. + You are now ready to set permissions on user interactive commands. Setting Permissions diff --git a/nowplaying/resources/twitchchat_ui.ui b/nowplaying/resources/twitchchat_ui.ui index 29feb984..a6ecf8b9 100644 --- a/nowplaying/resources/twitchchat_ui.ui +++ b/nowplaying/resources/twitchchat_ui.ui @@ -22,7 +22,7 @@ 10 30 624 - 81 + 71 @@ -100,7 +100,7 @@ 10 - 120 + 100 103 25 @@ -116,7 +116,7 @@ 240 - 120 + 100 381 25 @@ -135,7 +135,7 @@ 140 - 120 + 100 83 25 @@ -231,6 +231,22 @@ + + + + 10 + 140 + 321 + 20 + + + + Use Twitch 'Replies' when answering commands + + + true + + @@ -346,5 +362,21 @@ + + enable_checkbox + toggled(bool) + replies_checkbox + setEnabled(bool) + + + 95 + 11 + + + 180 + 149 + + + diff --git a/nowplaying/twitch/chat.py b/nowplaying/twitch/chat.py index 23e99343..87aec84e 100644 --- a/nowplaying/twitch/chat.py +++ b/nowplaying/twitch/chat.py @@ -398,6 +398,9 @@ async def _post_template(self, msg=None, template=None, moremetadata=None): #py ''' take a template, fill it in, and post it ''' if not template: return + if not self.chat: + logging.debug('Twitch chat is not configured?!?') + return metadata = await self.metadb.read_last_meta_async() if not metadata: metadata = {} @@ -423,7 +426,7 @@ async def _post_template(self, msg=None, template=None, moremetadata=None): #py if not self.chat.is_connected(): logging.error('Twitch chat is not connected. Not sending message.') return - if msg: + if msg and self.config.cparser.value('twitchbot/usereplies', type=bool): try: await msg.reply(content) except: #pylint: disable=bare-except @@ -537,6 +540,7 @@ def clear_table(widget): widget.announce_lineedit.setText(config.cparser.value('twitchbot/announce')) widget.commandchar_lineedit.setText(config.cparser.value('twitchbot/commandchar')) widget.announce_delay_lineedit.setText(config.cparser.value('twitchbot/announcedelay')) + widget.replies_checkbox.setChecked(config.cparser.value('twitchbot/usereplies', type=bool)) @staticmethod def save(config, widget, subprocesses): #pylint: disable=unused-argument @@ -567,6 +571,7 @@ def reset_commands(widget, config): config.cparser.setValue('twitchbot/commandchar', widget.commandchar_lineedit.text()) config.cparser.setValue('twitchbot/announcedelay', widget.announce_delay_lineedit.text()) + config.cparser.setValue('twitchbot/usereplies', widget.replies_checkbox.isChecked()) reset_commands(widget.command_perm_table, config.cparser) diff --git a/nowplaying/upgrade.py b/nowplaying/upgrade.py index e3052a6b..c76d1106 100644 --- a/nowplaying/upgrade.py +++ b/nowplaying/upgrade.py @@ -107,7 +107,7 @@ def upgrade(self): QStandardPaths.CacheLocation)[0]).joinpath('web.db') webdb.unlink(missing_ok=True) - oldversstr = config.value('settings/configversion', defaultValue='3.0.0') + oldversstr: str = config.value('settings/configversion', defaultValue='3.0.0') thisverstr = nowplaying.version.__VERSION__ #pylint: disable=no-member oldversion = nowplaying.upgradeutils.Version(oldversstr) @@ -137,10 +137,25 @@ def upgrade(self): if int(oldversstr[0]) < 4 and config.value('settings/input') == 'm3u': upgrade_m3u(config=rawconfig, testdir=self.testdir) + if oldversion < nowplaying.upgradeutils.Version('4.0.5'): + oldusereplies = rawconfig.value('twitchbot/usereplies') + if not oldusereplies: + logging.debug('Setting twitchbot to use replies by default') + config.setValue('twitchbot/usereplies', True) + + self._oldkey_to_newkey(rawconfig, config, mapping) + + config.setValue('settings/configversion', thisverstr) + config.sync() + + @staticmethod + def _oldkey_to_newkey(oldconfig, newconfig, mapping): + ''' remap keys ''' for oldkey, newkey in mapping.items(): logging.debug('processing %s - %s', oldkey, newkey) + newval = None try: - newval = rawconfig.value(newkey) + newval = oldconfig.value(newkey) except: # pylint: disable=bare-except pass @@ -149,20 +164,17 @@ def upgrade(self): continue try: - oldval = rawconfig.value(oldkey) + oldval = oldconfig.value(oldkey) except: # pylint: disable=bare-except logging.debug('%s vs %s: skipped, no new value', oldkey, newkey) continue if oldval: logging.debug('Setting %s from %s', newkey, oldkey) - config.setValue(newkey, oldval) + newconfig.setValue(newkey, oldval) else: logging.debug('%s does not exist', oldkey) - config.setValue('settings/configversion', thisverstr) - config.sync() - class UpgradeTemplates(): ''' Upgrade templates '''