From 5e787f49cef95d169c36d3e27f077cbe71aac6a4 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Sat, 24 Sep 2022 15:56:08 +0100 Subject: [PATCH] packages/ircbot: a bit of refactoring --- packages/servers/ircbot/main.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/servers/ircbot/main.py b/packages/servers/ircbot/main.py index e294a98..87479bb 100644 --- a/packages/servers/ircbot/main.py +++ b/packages/servers/ircbot/main.py @@ -1,23 +1,21 @@ import justirc -NICK = 'smith' - def main(): + config = dict(nick='smith', debug=False) + run_bot(config) + +def run_bot(c): bot = justirc.IRCConnection() - @bot.on('packet') - def new_packet(e): - print(e.packet) - - @bot.on('connected') - def reload_plugins(e): - print('bot has connected') + if c['debug']: + @bot.on('packet') + def new_packet(e): + print(e.packet) @bot.on('connect') def connect(e): - bot.send_line(f'NICK {NICK}') - bot.send_line(f'USER {NICK} 8 * {NICK}') - bot.emit('connected') + bot.send_line(f'NICK {c["nick"]}') + bot.send_line(f'USER {c["nick"]} 8 * {c["nick"]}') @bot.on('welcome') def welcome(e):