Skip to content

Commit

Permalink
Add the ability to turn off Twitch Chat replies (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
aw-was-here committed Jun 7, 2023
1 parent 1e2f788 commit f95f08a
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 13 deletions.
7 changes: 6 additions & 1 deletion docs/help/howdoi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 <output/webserver.html>`_ page.

Stop autoposting the track info in Twitch chat?
-----------------------------------------------

1. Under Settings -> Twitch Chat, set the announce template to be empty.
2. Save
3 changes: 3 additions & 0 deletions docs/output/twitchbot.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 36 additions & 4 deletions nowplaying/resources/twitchchat_ui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<x>10</x>
<y>30</y>
<width>624</width>
<height>81</height>
<height>71</height>
</rect>
</property>
<layout class="QFormLayout" name="settings_layout">
Expand Down Expand Up @@ -100,7 +100,7 @@
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<y>100</y>
<width>103</width>
<height>25</height>
</rect>
Expand All @@ -116,7 +116,7 @@
<property name="geometry">
<rect>
<x>240</x>
<y>120</y>
<y>100</y>
<width>381</width>
<height>25</height>
</rect>
Expand All @@ -135,7 +135,7 @@
<property name="geometry">
<rect>
<x>140</x>
<y>120</y>
<y>100</y>
<width>83</width>
<height>25</height>
</rect>
Expand Down Expand Up @@ -231,6 +231,22 @@
</item>
</layout>
</widget>
<widget class="QCheckBox" name="replies_checkbox">
<property name="geometry">
<rect>
<x>10</x>
<y>140</y>
<width>321</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Use Twitch 'Replies' when answering commands</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</widget>
<resources/>
<connections>
Expand Down Expand Up @@ -346,5 +362,21 @@
</hint>
</hints>
</connection>
<connection>
<sender>enable_checkbox</sender>
<signal>toggled(bool)</signal>
<receiver>replies_checkbox</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>95</x>
<y>11</y>
</hint>
<hint type="destinationlabel">
<x>180</x>
<y>149</y>
</hint>
</hints>
</connection>
</connections>
</ui>
7 changes: 6 additions & 1 deletion nowplaying/twitch/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
26 changes: 19 additions & 7 deletions nowplaying/upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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 '''
Expand Down

0 comments on commit f95f08a

Please sign in to comment.