2019-09-18 16:27:41 +00:00
|
|
|
from collections import OrderedDict
|
2019-01-25 21:13:48 +00:00
|
|
|
from datetime import datetime, timezone
|
2018-01-10 22:35:27 +00:00
|
|
|
import logging
|
2017-10-10 18:56:10 +00:00
|
|
|
import ssl
|
2017-11-27 05:10:40 +00:00
|
|
|
import time
|
2019-09-23 19:23:41 +00:00
|
|
|
|
|
|
|
from . import log
|
2019-09-18 16:27:41 +00:00
|
|
|
from . import plugin
|
2017-09-27 21:55:00 +00:00
|
|
|
|
2017-09-27 19:27:24 +00:00
|
|
|
import irc.bot
|
|
|
|
|
2017-11-27 05:10:40 +00:00
|
|
|
|
2017-09-27 19:27:24 +00:00
|
|
|
irc.client.ServerConnection.buffer_class.errors = 'replace'
|
|
|
|
|
2017-11-27 05:10:40 +00:00
|
|
|
|
2017-09-27 19:27:24 +00:00
|
|
|
class Bot(irc.bot.SingleServerIRCBot):
|
2020-05-28 21:51:56 +00:00
|
|
|
internal_commands = {
|
|
|
|
'join': 'join a channel',
|
|
|
|
'quit': 'force the bot to quit',
|
|
|
|
'reload': 'force bot to reload all plugins',
|
|
|
|
'enable': 'enable a plugin',
|
|
|
|
'disable': 'disable a plugin',
|
|
|
|
'op': 'add a user as bot operator',
|
|
|
|
'deop': 'remove a user as bot operator',
|
|
|
|
'ops': 'list all ops',
|
|
|
|
'ban': 'ban a user from using the bot',
|
|
|
|
'unban': 'remove bot ban for user',
|
|
|
|
'banlist': 'currently banned nicks'
|
|
|
|
}
|
|
|
|
|
2017-10-10 18:56:10 +00:00
|
|
|
def __init__(self, channels, nickname, server, **kwargs):
|
2019-02-16 18:46:38 +00:00
|
|
|
self.port = kwargs.get('port', 6667)
|
|
|
|
self.ops = kwargs.get('ops', [])
|
|
|
|
self.plugin_dir = kwargs.get('plugin_dir', 'plugins')
|
|
|
|
self.ssl_required = kwargs.get('ssl_required', False)
|
|
|
|
self.ns_pass = kwargs.get('ns_pass', None)
|
|
|
|
self.nickserv = kwargs.get('nickserv', 'NickServ')
|
|
|
|
self.log_level = kwargs.get('log_level', 'info')
|
2019-09-23 19:23:41 +00:00
|
|
|
self.log_file = kwargs.get('log_file', None)
|
2019-02-16 18:46:38 +00:00
|
|
|
self.server_pass = kwargs.get('server_pass', None)
|
|
|
|
self.cmd_prefix = kwargs.get('cmd_prefix', '!')
|
2019-02-16 18:51:02 +00:00
|
|
|
self.use_prefix_for_plugins = kwargs.get('use_prefix_for_plugins', False)
|
2019-09-30 18:47:55 +00:00
|
|
|
self.disable_help = kwargs.get('disable_help', False)
|
2019-10-02 16:25:38 +00:00
|
|
|
self.banned_users = kwargs.get('banned_users', [])
|
2017-10-10 18:56:10 +00:00
|
|
|
if self.ssl_required:
|
|
|
|
factory = irc.connection.Factory(wrapper=ssl.wrap_socket)
|
2018-02-05 20:33:44 +00:00
|
|
|
irc.bot.SingleServerIRCBot.__init__(self, [(server, self.port, self.server_pass)], nickname, nickname, connect_factory=factory)
|
2017-10-10 18:56:10 +00:00
|
|
|
else:
|
2018-02-05 20:33:44 +00:00
|
|
|
irc.bot.SingleServerIRCBot.__init__(self, [(server, self.port, self.server_pass)], nickname, nickname)
|
2017-09-27 19:27:24 +00:00
|
|
|
self.chanlist = channels
|
|
|
|
self.bot_nick = nickname
|
2019-09-23 19:23:41 +00:00
|
|
|
self.start_logging()
|
2019-09-18 16:27:41 +00:00
|
|
|
self.internal_commands = {self.cmd_prefix + k: v for k,v in self.internal_commands.items()}
|
2019-09-28 01:18:19 +00:00
|
|
|
plugin.load_plugins(self.plugin_dir, use_prefix=self.use_prefix_for_plugins, cmd_prefix=self.cmd_prefix)
|
2018-03-15 19:04:58 +00:00
|
|
|
|
2018-02-05 23:56:38 +00:00
|
|
|
class Message:
|
2019-09-30 18:23:19 +00:00
|
|
|
def __init__(self, bot, channel, nick, botnick, ops, logger, action, privmsg, notice, msg_type, cmd=None, arg=None, text=None, nick_list=None):
|
2019-02-24 00:56:03 +00:00
|
|
|
self.bot = bot
|
2019-01-25 21:13:48 +00:00
|
|
|
self.datetime = datetime.now(timezone.utc)
|
|
|
|
self.timestamp = self.datetime.timestamp()
|
2018-02-05 23:56:38 +00:00
|
|
|
self.channel = channel
|
|
|
|
self.nick = nick
|
|
|
|
self.nick_list = nick_list
|
|
|
|
self.botnick = botnick
|
|
|
|
self.ops = ops
|
|
|
|
self.logger = logger
|
2018-10-24 21:48:55 +00:00
|
|
|
self.action = action
|
|
|
|
self.privmsg = privmsg
|
|
|
|
self.notice = notice
|
2019-09-30 18:23:19 +00:00
|
|
|
self.msg_type = msg_type
|
2018-02-05 23:56:38 +00:00
|
|
|
if cmd:
|
|
|
|
self.cmd = cmd
|
|
|
|
self.arg = arg
|
|
|
|
if text:
|
|
|
|
self.text = text
|
|
|
|
if not (cmd or text):
|
|
|
|
raise TypeError('missing cmd or text parameter')
|
2017-09-27 19:27:24 +00:00
|
|
|
|
2019-09-23 19:23:41 +00:00
|
|
|
def start_logging(self):
|
|
|
|
self.logger = log.logger
|
|
|
|
if self.log_file:
|
|
|
|
log.set_log_file(self.log_file)
|
|
|
|
else:
|
|
|
|
log.set_log_file('{}.log'.format(self.bot_nick))
|
|
|
|
if self.log_level == 'error':
|
2018-01-10 22:35:27 +00:00
|
|
|
level = logging.ERROR
|
2019-09-23 19:23:41 +00:00
|
|
|
elif self.log_level == 'warning':
|
2018-01-10 22:35:27 +00:00
|
|
|
level = logging.WARNING
|
2019-09-23 19:23:41 +00:00
|
|
|
elif self.log_level == 'info':
|
2018-01-10 22:35:27 +00:00
|
|
|
level = logging.INFO
|
2019-09-23 19:23:41 +00:00
|
|
|
elif self.log_level == 'debug':
|
2018-01-10 22:35:27 +00:00
|
|
|
level = logging.DEBUG
|
|
|
|
# Set levels
|
2019-09-23 19:23:41 +00:00
|
|
|
if self.log_level != "off":
|
2018-01-10 22:35:27 +00:00
|
|
|
self.logger.setLevel(level)
|
|
|
|
self.logger.info('Logging started!')
|
|
|
|
|
2017-09-27 19:27:24 +00:00
|
|
|
def on_welcome(self, c, e):
|
2017-10-10 18:56:10 +00:00
|
|
|
if self.ns_pass:
|
2018-01-10 22:35:27 +00:00
|
|
|
self.logger.info('identifying with nickserv')
|
2017-10-10 18:56:10 +00:00
|
|
|
c.privmsg(self.nickserv, 'identify {}'.format(self.ns_pass))
|
2017-09-27 19:27:24 +00:00
|
|
|
for channel in self.chanlist:
|
2018-12-28 19:20:52 +00:00
|
|
|
self.logger.info('joining channel {}'.format(channel.split()[0]))
|
|
|
|
c.join(*channel.split())
|
2017-09-27 19:27:24 +00:00
|
|
|
|
|
|
|
def on_pubmsg(self, c, e):
|
2018-04-10 18:58:33 +00:00
|
|
|
self.process_event(c, e)
|
2017-09-27 19:27:24 +00:00
|
|
|
|
|
|
|
def on_privmsg(self, c, e):
|
2018-04-10 18:58:33 +00:00
|
|
|
self.process_event(c, e)
|
2017-09-27 19:27:24 +00:00
|
|
|
|
2018-01-12 19:17:12 +00:00
|
|
|
def on_action(self, c, e):
|
2018-04-10 18:58:33 +00:00
|
|
|
self.process_event(c, e)
|
2018-01-12 19:17:12 +00:00
|
|
|
|
2019-09-18 16:27:41 +00:00
|
|
|
def call_help(self, nick, op):
|
|
|
|
cmds = {k:v.help_text for k,v in plugin.cmds.items() if not plugin.cmds[k].ops}
|
|
|
|
cmds.update({self.cmd_prefix + 'help': 'returns this output to private message'})
|
2019-09-16 19:27:43 +00:00
|
|
|
if op:
|
2019-09-18 16:27:41 +00:00
|
|
|
cmds.update({k:v.help_text for k,v in plugin.cmds.items() if plugin.cmds[k].ops})
|
|
|
|
cmds.update({k:v for k,v in self.internal_commands.items()})
|
|
|
|
helpout = OrderedDict(sorted(cmds.items()))
|
|
|
|
for h in helpout:
|
|
|
|
self.connection.privmsg(nick, '{} -- {}'.format(h, helpout[h]))
|
2019-09-28 01:18:19 +00:00
|
|
|
time.sleep(.1)
|
2019-09-18 16:42:45 +00:00
|
|
|
self.connection.privmsg(nick, 'List of listeners: {}'.format(', '.join([l for l in plugin.lstnrs])))
|
2019-09-18 16:27:41 +00:00
|
|
|
return None
|
2018-10-24 21:48:55 +00:00
|
|
|
|
2018-04-10 19:02:48 +00:00
|
|
|
def call_internal_commands(self, channel, nick, cmd, text, arg, c):
|
2019-10-14 19:57:38 +00:00
|
|
|
if not cmd.startswith(self.cmd_prefix):
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
cmd = cmd[len(self.cmd_prefix):]
|
2017-09-27 21:55:00 +00:00
|
|
|
output = None
|
2018-04-10 18:58:33 +00:00
|
|
|
if nick in self.ops:
|
|
|
|
op = True
|
|
|
|
else:
|
|
|
|
op = False
|
2019-10-02 16:25:38 +00:00
|
|
|
if cmd == 'join' and op:
|
2019-09-30 18:35:35 +00:00
|
|
|
try:
|
|
|
|
c.join(*arg.split())
|
|
|
|
self.logger.info('joining {} per request of {}'.format(arg, nick))
|
2020-09-23 18:17:59 +00:00
|
|
|
output = plugin.message('{}: joined {}'.format(nick, arg.split()[0]))
|
2019-09-30 18:35:35 +00:00
|
|
|
except:
|
|
|
|
self.logger.exception('issue with join command: {}join #channel <channel key>'.format(self.cmd_prefix))
|
2019-10-02 16:25:38 +00:00
|
|
|
elif cmd == 'quit' and op:
|
2018-01-10 22:35:27 +00:00
|
|
|
self.logger.info('quitting per request of {}'.format(nick))
|
2019-09-30 18:35:35 +00:00
|
|
|
if not arg:
|
|
|
|
arg = "See y'all later!"
|
|
|
|
c.quit(arg)
|
2017-09-27 19:27:24 +00:00
|
|
|
quit()
|
2019-10-02 16:25:38 +00:00
|
|
|
elif cmd == 'help' and not self.disable_help:
|
2019-09-18 16:27:41 +00:00
|
|
|
self.call_help(nick, op)
|
2019-10-02 16:25:38 +00:00
|
|
|
elif cmd == 'reload' and op:
|
2018-01-10 22:35:27 +00:00
|
|
|
self.logger.info('reloading plugins per request of {}'.format(nick))
|
2019-09-28 01:18:19 +00:00
|
|
|
plugin.load_plugins(self.plugin_dir, use_prefix=self.use_prefix_for_plugins, cmd_prefix=self.cmd_prefix)
|
2020-09-23 18:17:59 +00:00
|
|
|
output = plugin.message('Plugins reloaded')
|
2019-10-02 16:25:38 +00:00
|
|
|
elif cmd == 'enable' and op:
|
2019-09-18 16:27:41 +00:00
|
|
|
if arg in plugin.plugins:
|
|
|
|
if plugin.plugins[arg].enabled:
|
2020-09-23 18:17:59 +00:00
|
|
|
output = plugin.message("{}: '{}' already enabled".format(nick, arg))
|
2019-09-18 16:27:41 +00:00
|
|
|
else:
|
|
|
|
plugin.plugins[arg].enable()
|
2020-09-23 18:17:59 +00:00
|
|
|
output = plugin.message("{}: '{}' enabled!".format(nick, arg))
|
2019-09-18 16:27:41 +00:00
|
|
|
else:
|
2020-09-23 18:17:59 +00:00
|
|
|
output = plugin.message("{}: '{}' not found".format(nick, arg))
|
2019-10-02 16:25:38 +00:00
|
|
|
elif cmd == 'disable' and op:
|
2019-09-18 16:27:41 +00:00
|
|
|
if arg in plugin.plugins:
|
|
|
|
if not plugin.plugins[arg].enabled:
|
2020-09-23 18:17:59 +00:00
|
|
|
output = plugin.message("{}: '{}' already disabled".format(nick, arg))
|
2019-09-18 16:27:41 +00:00
|
|
|
else:
|
|
|
|
plugin.plugins[arg].disable()
|
2020-09-23 18:17:59 +00:00
|
|
|
output = plugin.message("{}: '{}' disabled!".format(nick, arg))
|
2019-10-02 16:25:38 +00:00
|
|
|
elif cmd == 'op' and op:
|
2019-10-02 16:04:50 +00:00
|
|
|
for o in arg.split(' '):
|
|
|
|
self.ops.append(o)
|
2020-09-23 18:17:59 +00:00
|
|
|
output = plugin.message('{}: {} added as op'.format(nick, arg))
|
2019-10-02 16:25:38 +00:00
|
|
|
elif cmd == 'deop' and op:
|
2019-10-02 16:04:50 +00:00
|
|
|
for o in arg.split(' '):
|
|
|
|
self.ops = [i for i in self.ops if i != o]
|
2020-09-23 18:17:59 +00:00
|
|
|
output = plugin.message('{}: {} removed as op'.format(nick, arg))
|
2019-10-02 16:25:38 +00:00
|
|
|
elif cmd == 'ops' and op:
|
2020-09-23 18:17:59 +00:00
|
|
|
output = plugin.message('current ops: {}'.format(', '.join(self.ops)))
|
2019-10-02 16:25:38 +00:00
|
|
|
elif cmd == 'ban' and op:
|
|
|
|
for o in arg.split(' '):
|
|
|
|
self.banned_users.append(o)
|
2020-09-23 18:17:59 +00:00
|
|
|
output = plugin.message('{}: banned {}'.format(nick, arg))
|
2019-10-02 16:25:38 +00:00
|
|
|
elif cmd == 'unban' and op:
|
|
|
|
for o in arg.split(' '):
|
|
|
|
self.banned_users = [i for i in self.banned_users if i != o]
|
2020-09-23 18:17:59 +00:00
|
|
|
output = plugin.message('{}: removed ban for {}'.format(nick, arg))
|
2019-10-02 16:25:38 +00:00
|
|
|
elif cmd == 'banlist':
|
2020-09-23 18:17:59 +00:00
|
|
|
output = plugin.message('currently banned: {}'.format(', '.join(self.banned_users)))
|
2018-04-10 18:58:33 +00:00
|
|
|
return output
|
|
|
|
|
2019-09-30 18:23:19 +00:00
|
|
|
def call_plugins(self, privmsg, action, notice, chan, cmd, text, nick_list, nick, arg, msg_type):
|
2018-04-10 18:58:33 +00:00
|
|
|
output = None
|
2019-09-18 16:27:41 +00:00
|
|
|
if cmd in plugin.cmds:
|
2017-10-13 22:22:47 +00:00
|
|
|
try:
|
2019-09-18 16:27:41 +00:00
|
|
|
if plugin.cmds[cmd].ops and nick not in self.ops:
|
|
|
|
if plugin.cmds[cmd].ops_msg:
|
2020-09-23 18:17:59 +00:00
|
|
|
output = plugin.message(plugin.cmds[cmd].ops_msg)
|
2019-09-18 16:27:41 +00:00
|
|
|
elif plugin.cmds[cmd].enabled:
|
2019-02-22 21:07:41 +00:00
|
|
|
self.logger.debug('executing {}'.format(cmd))
|
2019-09-18 16:27:41 +00:00
|
|
|
output = plugin.cmds[cmd].run(self.Message(
|
2019-02-24 00:56:03 +00:00
|
|
|
bot=self,
|
2019-02-16 18:40:10 +00:00
|
|
|
channel=chan,
|
|
|
|
cmd=cmd,
|
|
|
|
nick_list=nick_list,
|
|
|
|
nick=nick,
|
|
|
|
arg=arg,
|
|
|
|
privmsg=privmsg,
|
|
|
|
action=action,
|
|
|
|
notice=notice,
|
|
|
|
botnick=self.bot_nick,
|
|
|
|
ops=self.ops,
|
2019-09-30 18:23:19 +00:00
|
|
|
logger=self.logger,
|
|
|
|
msg_type=msg_type
|
2019-02-16 18:40:10 +00:00
|
|
|
))
|
2019-09-12 17:13:57 +00:00
|
|
|
except Exception:
|
2018-01-10 22:35:27 +00:00
|
|
|
self.logger.exception('issue with command {}'.format(cmd))
|
2017-12-06 18:45:34 +00:00
|
|
|
else:
|
2019-09-18 16:27:41 +00:00
|
|
|
for lstnr in plugin.lstnrs:
|
|
|
|
if plugin.lstnrs[lstnr].enabled:
|
|
|
|
try:
|
|
|
|
self.logger.debug('whispering to listener: {}'.format(lstnr))
|
|
|
|
listen_output = plugin.lstnrs[lstnr].run(self.Message(
|
|
|
|
bot=self,
|
|
|
|
channel=chan,
|
|
|
|
text=text,
|
|
|
|
nick_list=nick_list,
|
|
|
|
nick=nick,
|
|
|
|
privmsg=privmsg,
|
|
|
|
action=action,
|
|
|
|
notice=notice,
|
|
|
|
botnick=self.bot_nick,
|
|
|
|
ops=self.ops,
|
2019-09-30 18:23:19 +00:00
|
|
|
logger=self.logger,
|
|
|
|
msg_type=msg_type
|
2019-09-18 16:27:41 +00:00
|
|
|
))
|
|
|
|
if listen_output:
|
|
|
|
output = listen_output
|
|
|
|
except Exception:
|
|
|
|
self.logger.exception('issue with listener {}'.format(lstnr))
|
2019-02-22 21:55:48 +00:00
|
|
|
if output:
|
|
|
|
self.logger.debug(f'returning output: {output.msg}')
|
2018-04-10 18:58:33 +00:00
|
|
|
return output
|
|
|
|
|
|
|
|
def process_event(self, c, e):
|
|
|
|
nick = e.source.nick
|
2020-05-28 21:51:56 +00:00
|
|
|
if nick == self.bot_nick:
|
|
|
|
pass
|
2020-12-18 16:43:54 +00:00
|
|
|
if e.arguments:
|
|
|
|
text = e.arguments[0]
|
|
|
|
else:
|
|
|
|
text = ''
|
2019-09-30 18:23:19 +00:00
|
|
|
if e.type == 'privmsg' or e.type == 'pubmsg':
|
|
|
|
msg_type = 'message'
|
|
|
|
else:
|
|
|
|
msg_type = e.type
|
2018-04-10 18:58:33 +00:00
|
|
|
if e.target == self.bot_nick:
|
|
|
|
chan = nick
|
|
|
|
nick_list = [nick]
|
|
|
|
else:
|
|
|
|
chan = e.target
|
|
|
|
nick_list = list(self.channels[chan].users())
|
|
|
|
if e.type == 'action':
|
|
|
|
cmd = ''
|
|
|
|
else:
|
|
|
|
cmd = text.split(' ')[0]
|
|
|
|
self.logger.debug(
|
|
|
|
'Message info: channel: {}, nick: {}, cmd: {}, text: {}'.format(chan, nick, cmd, text)
|
|
|
|
)
|
|
|
|
if len(text.split(' ')) > 1:
|
|
|
|
arg = ''.join([i + ' ' for i in text.split(' ')[1:]]).strip()
|
|
|
|
else:
|
|
|
|
arg = ''
|
2018-04-10 19:02:48 +00:00
|
|
|
output = self.call_internal_commands(chan, nick, cmd, text, arg, c)
|
2018-04-10 18:58:33 +00:00
|
|
|
if not output:
|
|
|
|
plugin_info = {
|
|
|
|
'chan': chan,
|
|
|
|
'cmd': cmd,
|
|
|
|
'text': text,
|
|
|
|
'nick_list': nick_list,
|
2018-04-10 19:13:54 +00:00
|
|
|
'nick': nick,
|
2018-10-24 21:48:55 +00:00
|
|
|
'arg': arg,
|
|
|
|
'privmsg': c.privmsg,
|
|
|
|
'action': c.action,
|
|
|
|
'notice': c.notice,
|
2019-09-30 18:23:19 +00:00
|
|
|
'msg_type': msg_type
|
2018-04-10 18:58:33 +00:00
|
|
|
}
|
2018-04-10 19:02:48 +00:00
|
|
|
output = self.call_plugins(**plugin_info)
|
2018-04-10 18:58:33 +00:00
|
|
|
if output:
|
2019-02-22 21:39:16 +00:00
|
|
|
self.logger.debug(f'sending output: {output.msg}')
|
2018-04-10 19:02:48 +00:00
|
|
|
self.process_output(c, chan, output)
|
2017-09-27 21:55:00 +00:00
|
|
|
|
2017-12-06 18:45:34 +00:00
|
|
|
def process_output(self, c, chan, output):
|
2019-02-08 19:25:49 +00:00
|
|
|
if not output.msg:
|
|
|
|
return
|
2017-12-06 18:45:34 +00:00
|
|
|
for msg in output.msg:
|
2019-09-18 16:27:41 +00:00
|
|
|
if output.msg_type == plugin.OutputType.Message:
|
2018-01-10 22:35:27 +00:00
|
|
|
self.logger.debug('output message: {}'.format(msg))
|
2019-03-02 19:02:14 +00:00
|
|
|
try:
|
|
|
|
c.privmsg(chan, msg)
|
|
|
|
except irc.client.MessageTooLong:
|
|
|
|
self.logger.error('output message too long: {}'.format(msg))
|
|
|
|
break
|
2019-09-18 16:27:41 +00:00
|
|
|
elif output.msg_type == plugin.OutputType.Action:
|
2018-01-11 18:32:14 +00:00
|
|
|
self.logger.debug('output action: {}'.format(msg))
|
2019-03-02 19:02:14 +00:00
|
|
|
try:
|
|
|
|
c.action(chan, msg)
|
|
|
|
except irc.client.MessageTooLong:
|
|
|
|
self.logger.error('output message too long: {}'.format(msg))
|
|
|
|
break
|
2018-10-10 17:25:03 +00:00
|
|
|
else:
|
|
|
|
self.logger.warning("Unsupported output type '{}'".format(output.msg_type))
|
2017-12-06 18:45:34 +00:00
|
|
|
time.sleep(.5)
|
2018-04-10 16:54:49 +00:00
|
|
|
|
|
|
|
|
2018-02-05 23:56:38 +00:00
|
|
|
class TwitchBot(Bot):
|
2020-05-28 21:51:56 +00:00
|
|
|
def __init__(self, nickname, channel, token, **kwargs):
|
|
|
|
self.port = kwargs.get('port', 6667)
|
|
|
|
self.ops = kwargs.get('ops', [])
|
|
|
|
self.plugin_dir = kwargs.get('plugin_dir', 'plugins')
|
|
|
|
self.log_level = kwargs.get('log_level', 'info')
|
|
|
|
self.log_file = kwargs.get('log_file', None)
|
|
|
|
self.server_pass = kwargs.get('server_pass', None)
|
|
|
|
self.cmd_prefix = kwargs.get('cmd_prefix', '!')
|
|
|
|
self.use_prefix_for_plugins = kwargs.get('use_prefix_for_plugins', False)
|
|
|
|
self.disable_help = kwargs.get('disable_help', False)
|
|
|
|
self.banned_users = kwargs.get('banned_users', [])
|
2018-02-05 23:56:38 +00:00
|
|
|
self.bot_nick = nickname
|
2019-09-23 19:23:41 +00:00
|
|
|
self.start_logging()
|
2018-02-05 23:56:38 +00:00
|
|
|
self.channel = channel
|
|
|
|
self.logger.info('Joining Twitch Server')
|
2020-05-28 21:51:56 +00:00
|
|
|
irc.bot.SingleServerIRCBot.__init__(self, [('irc.twitch.tv', 6667, 'oauth:'+token)], nickname, nickname)
|
|
|
|
self.internal_commands = {self.cmd_prefix + k: v for k,v in self.internal_commands.items()}
|
|
|
|
plugin.load_plugins(self.plugin_dir, use_prefix=self.use_prefix_for_plugins, cmd_prefix=self.cmd_prefix)
|
2018-04-10 16:54:49 +00:00
|
|
|
|
2018-02-05 23:56:38 +00:00
|
|
|
def on_welcome(self, c, e):
|
|
|
|
self.logger.info('requesting permissions')
|
|
|
|
c.cap('REQ', ':twitch.tv/membership')
|
|
|
|
c.cap('REQ', ':twitch.tv/tags')
|
|
|
|
c.cap('REQ', ':twitch.tv/commands')
|
|
|
|
self.logger.info('Joining channel ' + self.channel)
|
|
|
|
c.join(self.channel)
|