From: Christian Heller Date: Sun, 17 Jan 2016 21:43:35 +0000 (+0100) Subject: Some more refactoring / de-globalizing. X-Git-Url: https://plomlompom.com/repos/error?a=commitdiff_plain;h=61948f17eafecaae17078d916ba2193983eaa339;p=plomlombot-irc.git Some more refactoring / de-globalizing. --- diff --git a/plomlombot.py b/plomlombot.py index 1e904fa..efd8474 100644 --- a/plomlombot.py +++ b/plomlombot.py @@ -79,15 +79,15 @@ class IO: line) return line -def init_session(): - print("CONNECTING TO " + SERVERNET) - io = IO(SERVERNET, PORT, TIMEOUT) - io.send_line("NICK " + NICKNAME) - io.send_line("USER " + USERNAME + " 0 * : ") - io.send_line("JOIN " + CHANNEL) +def init_session(servernet, port, timeout, nickname, username, channel): + print("CONNECTING TO " + servernet) + io = IO(servernet, port, timeout) + io.send_line("NICK " + nickname) + io.send_line("USER " + username + " 0 * : ") + io.send_line("JOIN " + channel) return io -def lineparser_loop(): +def lineparser_loop(io, nickname): def act_on_privmsg(tokens): @@ -128,7 +128,7 @@ def lineparser_loop(): if rune != ":": receiver += rune target = sender - if receiver != NICKNAME: + if receiver != nickname: target = receiver msg = str.join(" ", tokens[3:])[1:] url_check(msg) @@ -143,11 +143,11 @@ def lineparser_loop(): act_on_privmsg(tokens) if tokens[0] == "PING": io.send_line("PONG " + tokens[1]) - while 1: try: - io = init_session() - lineparser_loop() + io = init_session(SERVERNET, PORT, TIMEOUT, NICKNAME, USERNAME, + CHANNEL) + lineparser_loop(io, NICKNAME) except ExceptionForRestart: io.socket.close() continue