|
|
@ -31,6 +31,13 @@ QUOTE_REMOVED_PATTERN = re.compile(r'''^
|
|
|
|
Successfully\s+deleted\s+Quote\s+
|
|
|
|
Successfully\s+deleted\s+Quote\s+
|
|
|
|
\#(?P<id>\d+)\.$''', re.VERBOSE)
|
|
|
|
\#(?P<id>\d+)\.$''', re.VERBOSE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# $giver, Thank you for gifting a sub to $receiver! So kind <3 !
|
|
|
|
|
|
|
|
SUB_GIFTED_PATTERN = re.compile(r'''^
|
|
|
|
|
|
|
|
(?P<giver>.+),\s+
|
|
|
|
|
|
|
|
Thank\s+you\s+for\s+gifting\s+a\s+sub\s+to\s+
|
|
|
|
|
|
|
|
(?P<receiver>.+)!\s+
|
|
|
|
|
|
|
|
So\s+kind\s+<3\s+!$''', re.VERBOSE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TwitchClient(irc.bot.SingleServerIRCBot):
|
|
|
|
class TwitchClient(irc.bot.SingleServerIRCBot):
|
|
|
|
def __init__(self, config, logger, commands, extra_commands):
|
|
|
|
def __init__(self, config, logger, commands, extra_commands):
|
|
|
@ -42,11 +49,13 @@ class TwitchClient(irc.bot.SingleServerIRCBot):
|
|
|
|
(QUOTE_ADDED_PATTERN, self._add_quote),
|
|
|
|
(QUOTE_ADDED_PATTERN, self._add_quote),
|
|
|
|
(QUOTE_EDITED_PATTERN, self._edit_quote),
|
|
|
|
(QUOTE_EDITED_PATTERN, self._edit_quote),
|
|
|
|
(QUOTE_REMOVED_PATTERN, self._remove_quote),
|
|
|
|
(QUOTE_REMOVED_PATTERN, self._remove_quote),
|
|
|
|
|
|
|
|
(SUB_GIFTED_PATTERN, self._record_gifted_sub),
|
|
|
|
]
|
|
|
|
]
|
|
|
|
self.supported_commands = [
|
|
|
|
self.supported_commands = [
|
|
|
|
(re.compile(r'^!lastquote$'), self._do_lastquote),
|
|
|
|
(re.compile(r'^!lastquote$'), self._do_lastquote),
|
|
|
|
(re.compile(r'^!findquote\s+(?P<q>")?(?P<filter>.+)(?(q)")$'), self._do_findquote),
|
|
|
|
(re.compile(r'^!findquote\s+(?P<q>")?(?P<filter>.+)(?(q)")$'), self._do_findquote),
|
|
|
|
(re.compile(r'^!syncquotes$'), self._do_syncquotes),
|
|
|
|
(re.compile(r'^!syncquotes$'), self._do_syncquotes),
|
|
|
|
|
|
|
|
(re.compile(r'^!syncsubs$'), self._do_syncsubs),
|
|
|
|
(re.compile(r'^!(bella(gram|pics)|insta(gram|bella))$'), self._do_bellagram),
|
|
|
|
(re.compile(r'^!(bella(gram|pics)|insta(gram|bella))$'), self._do_bellagram),
|
|
|
|
(re.compile(r'^!yt\s+(?P<q>")?(?P<query>.+)(?(q)")$'), self._do_yt),
|
|
|
|
(re.compile(r'^!yt\s+(?P<q>")?(?P<query>.+)(?(q)")$'), self._do_yt),
|
|
|
|
(re.compile(r'^!clip\s+(?P<q>")?(?P<filter>.+)(?(q)")$'), self._do_clip),
|
|
|
|
(re.compile(r'^!clip\s+(?P<q>")?(?P<filter>.+)(?(q)")$'), self._do_clip),
|
|
|
@ -138,6 +147,13 @@ class TwitchClient(irc.bot.SingleServerIRCBot):
|
|
|
|
except CommandError as e:
|
|
|
|
except CommandError as e:
|
|
|
|
self.logger.error('Failed to remove quote: %s', e)
|
|
|
|
self.logger.error('Failed to remove quote: %s', e)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _record_gifted_sub(self, tags, send_response, giver, receiver, **kwargs):
|
|
|
|
|
|
|
|
self.logger.info('Recording gifted sub %s -> %s', giver, receiver)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
self.commands.record_gifted_sub(giver, receiver, kwargs.get('time'))
|
|
|
|
|
|
|
|
except CommandError as e:
|
|
|
|
|
|
|
|
self.logger.error('Failed to record gifted sub: %s', e)
|
|
|
|
|
|
|
|
|
|
|
|
def _do_lastquote(self, tags, send_response, **kwargs):
|
|
|
|
def _do_lastquote(self, tags, send_response, **kwargs):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
quote = self.commands.last_quote()
|
|
|
|
quote = self.commands.last_quote()
|
|
|
@ -169,11 +185,27 @@ class TwitchClient(irc.bot.SingleServerIRCBot):
|
|
|
|
except CommandError as e:
|
|
|
|
except CommandError as e:
|
|
|
|
self.logger.error('Failed to get quote messages: %s', e)
|
|
|
|
self.logger.error('Failed to get quote messages: %s', e)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
for message in messages:
|
|
|
|
for message, time in messages:
|
|
|
|
for pattern, action in self.patterns:
|
|
|
|
for pattern, action in self.patterns:
|
|
|
|
m = pattern.match(message)
|
|
|
|
m = pattern.match(message)
|
|
|
|
if m:
|
|
|
|
if m:
|
|
|
|
action(tags, send_response, **m.groupdict())
|
|
|
|
action(tags, send_response, **m.groupdict(), time=time)
|
|
|
|
|
|
|
|
send_response('Sync finished, @{0}'.format(tags['display-name']))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _do_syncsubs(self, tags, send_response, **kwargs):
|
|
|
|
|
|
|
|
if not self._is_mod(tags):
|
|
|
|
|
|
|
|
send_response('Sorry @{0}, you are not allowed to do this'.format(tags['display-name']))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
messages = self.commands.get_gifted_sub_messages()
|
|
|
|
|
|
|
|
except CommandError as e:
|
|
|
|
|
|
|
|
self.logger.error('Failed to get gifted sub messages: %s', e)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
for message, time in messages:
|
|
|
|
|
|
|
|
for pattern, action in self.patterns:
|
|
|
|
|
|
|
|
m = pattern.match(message)
|
|
|
|
|
|
|
|
if m:
|
|
|
|
|
|
|
|
action(tags, send_response, **m.groupdict(), time=time)
|
|
|
|
send_response('Sync finished, @{0}'.format(tags['display-name']))
|
|
|
|
send_response('Sync finished, @{0}'.format(tags['display-name']))
|
|
|
|
|
|
|
|
|
|
|
|
def _do_bellagram(self, tags, send_response, **kwargs):
|
|
|
|
def _do_bellagram(self, tags, send_response, **kwargs):
|
|
|
|