|
|
@ -33,10 +33,11 @@ QUOTE_REMOVED_PATTERN = re.compile(r'''^
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TwitchClient(irc.bot.SingleServerIRCBot):
|
|
|
|
class TwitchClient(irc.bot.SingleServerIRCBot):
|
|
|
|
def __init__(self, config, logger, commands):
|
|
|
|
def __init__(self, config, logger, commands, extra_commands):
|
|
|
|
self.config = config
|
|
|
|
self.config = config
|
|
|
|
self.logger = logger
|
|
|
|
self.logger = logger
|
|
|
|
self.commands = commands
|
|
|
|
self.commands = commands
|
|
|
|
|
|
|
|
self.extra_commands = extra_commands
|
|
|
|
self.patterns = [
|
|
|
|
self.patterns = [
|
|
|
|
(QUOTE_ADDED_PATTERN, self._add_quote),
|
|
|
|
(QUOTE_ADDED_PATTERN, self._add_quote),
|
|
|
|
(QUOTE_EDITED_PATTERN, self._edit_quote),
|
|
|
|
(QUOTE_EDITED_PATTERN, self._edit_quote),
|
|
|
@ -49,7 +50,9 @@ class TwitchClient(irc.bot.SingleServerIRCBot):
|
|
|
|
(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),
|
|
|
|
(re.compile(r'^!reload$'), self._do_reload),
|
|
|
|
(re.compile(r'^!command\s+set\s+(?P<q1>")?(?P<cmd>.+?)(?(q1)")\s+'
|
|
|
|
|
|
|
|
r'(?P<q2>")?(?P<resp>.+)(?(q2)")$'), self._do_command_set),
|
|
|
|
|
|
|
|
(re.compile(r'^!command\s+unset\s+(?P<q>")?(?P<cmd>.+)(?(q)")$'), self._do_command_unset),
|
|
|
|
]
|
|
|
|
]
|
|
|
|
server = self.config['IRC'].get('server')
|
|
|
|
server = self.config['IRC'].get('server')
|
|
|
|
port = self.config['IRC'].getint('port')
|
|
|
|
port = self.config['IRC'].getint('port')
|
|
|
@ -82,6 +85,10 @@ class TwitchClient(irc.bot.SingleServerIRCBot):
|
|
|
|
def on_whisper(self, connection, event):
|
|
|
|
def on_whisper(self, connection, event):
|
|
|
|
self._process_message(connection, event)
|
|
|
|
self._process_message(connection, event)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _is_mod(self, tags):
|
|
|
|
|
|
|
|
badges = [b.split('/')[0] for b in tags['badges'].split(',')]
|
|
|
|
|
|
|
|
return bool(set(badges).intersection(['admin', 'broadcaster', 'moderator']))
|
|
|
|
|
|
|
|
|
|
|
|
def _send_response(self, connection, event, msg):
|
|
|
|
def _send_response(self, connection, event, msg):
|
|
|
|
if event.target.startswith('#'):
|
|
|
|
if event.target.startswith('#'):
|
|
|
|
connection.privmsg(event.target, msg)
|
|
|
|
connection.privmsg(event.target, msg)
|
|
|
@ -97,7 +104,7 @@ class TwitchClient(irc.bot.SingleServerIRCBot):
|
|
|
|
m = pattern.match(message)
|
|
|
|
m = pattern.match(message)
|
|
|
|
if m:
|
|
|
|
if m:
|
|
|
|
action(tags, send_response, **m.groupdict())
|
|
|
|
action(tags, send_response, **m.groupdict())
|
|
|
|
for cmd, resp in self.config['Extra Commands'].items():
|
|
|
|
for cmd, resp in self.extra_commands.items():
|
|
|
|
if cmd == message:
|
|
|
|
if cmd == message:
|
|
|
|
send_response(resp)
|
|
|
|
send_response(resp)
|
|
|
|
|
|
|
|
|
|
|
@ -149,9 +156,8 @@ class TwitchClient(irc.bot.SingleServerIRCBot):
|
|
|
|
send_response('One time, Lilia said this... #{id}: "{text}" [{game}] [{date}]'.format(**quote))
|
|
|
|
send_response('One time, Lilia said this... #{id}: "{text}" [{game}] [{date}]'.format(**quote))
|
|
|
|
|
|
|
|
|
|
|
|
def _do_syncquotes(self, tags, send_response, **kwargs):
|
|
|
|
def _do_syncquotes(self, tags, send_response, **kwargs):
|
|
|
|
master_user_id = self.config['Twitch'].getint('master_user_id')
|
|
|
|
if not self._is_mod(tags):
|
|
|
|
if int(tags['user-id']) != master_user_id:
|
|
|
|
send_response('Sorry @{0}, you are not allowed to do this'.format(tags['display-name']))
|
|
|
|
respond('Sorry @{0}, you are not allowed to do this'.format(tags['display-name']))
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
messages = self.commands.get_quote_messages()
|
|
|
|
messages = self.commands.get_quote_messages()
|
|
|
@ -163,6 +169,7 @@ class TwitchClient(irc.bot.SingleServerIRCBot):
|
|
|
|
m = pattern.match(message)
|
|
|
|
m = pattern.match(message)
|
|
|
|
if m:
|
|
|
|
if m:
|
|
|
|
action(tags, send_response, **m.groupdict())
|
|
|
|
action(tags, send_response, **m.groupdict())
|
|
|
|
|
|
|
|
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):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -188,10 +195,28 @@ class TwitchClient(irc.bot.SingleServerIRCBot):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
send_response('{0}: {1}'.format(result['title'], result['url']))
|
|
|
|
send_response('{0}: {1}'.format(result['title'], result['url']))
|
|
|
|
|
|
|
|
|
|
|
|
def _do_reload(self, tags, send_response, **kwargs):
|
|
|
|
def _do_command_set(self, tags, send_response, cmd, resp, **kwargs):
|
|
|
|
master_user_id = self.config['Twitch'].getint('master_user_id')
|
|
|
|
if not self._is_mod(tags):
|
|
|
|
if int(tags['user-id']) != master_user_id:
|
|
|
|
send_response('Sorry @{0}, you are not allowed to do this'.format(tags['display-name']))
|
|
|
|
respond('Sorry @{0}, you are not allowed to do this'.format(tags['display-name']))
|
|
|
|
|
|
|
|
return
|
|
|
|
return
|
|
|
|
self.config.remove_section('Extra Commands')
|
|
|
|
try:
|
|
|
|
self.config.read('settings.cfg')
|
|
|
|
self.extra_commands[cmd] = resp
|
|
|
|
|
|
|
|
self.extra_commands.save()
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
self.logger.error('Failed to update extra commands: %s', e)
|
|
|
|
|
|
|
|
send_response('Sorry @{0}, failed to set the command'.format(tags['display-name']))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
send_response('Command {0} set, @{1}'.format(cmd, tags['display-name']))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _do_command_unset(self, tags, send_response, cmd, **kwargs):
|
|
|
|
|
|
|
|
if not self._is_mod(tags):
|
|
|
|
|
|
|
|
send_response('Sorry @{0}, you are not allowed to do this'.format(tags['display-name']))
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
self.extra_commands.pop(cmd, None)
|
|
|
|
|
|
|
|
self.extra_commands.save()
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
self.logger.error('Failed to update extra commands: %s', e)
|
|
|
|
|
|
|
|
send_response('Sorry @{0}, failed to unset the command'.format(tags['display-name']))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
send_response('Command {0} unset, @{1}'.format(cmd, tags['display-name']))
|
|
|
|