From ad7e0f11aca3d4300eb7b854c100ff4973f9403f Mon Sep 17 00:00:00 2001 From: "Vgr E. Barry" Date: Tue, 17 Jan 2017 12:52:21 -0500 Subject: [PATCH] Ignore messages received before the bot is fully set up --- src/handler.py | 11 ++++++++++- wolfbot.py | 5 ++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/handler.py b/src/handler.py index 1589b2c..110b8a2 100644 --- a/src/handler.py +++ b/src/handler.py @@ -6,10 +6,11 @@ import sys import threading import time import traceback +import functools import botconfig import src.settings as var -from src import decorators, wolfgame, channels, hooks, users, errlog as log, stream_handler as alog +from src import decorators, wolfgame, events, channels, hooks, users, errlog as log, stream_handler as alog from src.messages import messages from src.utilities import reply @@ -106,6 +107,14 @@ def connect_callback(cli): ping_server_timer(cli) + def setup_handler(evt, var, target): + target.client.command_handler["privmsg"] = on_privmsg + target.client.command_handler["notice"] = functools.partial(on_privmsg, notice=True) + + events.remove_listener("who_end", setup_handler) + + events.add_listener("who_end", setup_handler) + def mustregain(cli, server, bot_nick, nick, msg): nonlocal regaincount diff --git a/wolfbot.py b/wolfbot.py index 6aea6fc..12e2113 100755 --- a/wolfbot.py +++ b/wolfbot.py @@ -18,7 +18,6 @@ # THE SOFTWARE. import traceback -import functools import sys import os @@ -53,8 +52,8 @@ from src import handler def main(): src.plog("Connecting to {0}:{1}{2}".format(botconfig.HOST, "+" if botconfig.USE_SSL else "", botconfig.PORT)) cli = IRCClient( - {"privmsg": handler.on_privmsg, - "notice": functools.partial(handler.on_privmsg, notice=True), + {"privmsg": lambda *s: None, + "notice": lambda *s: None, "": handler.unhandled}, host=botconfig.HOST, port=botconfig.PORT,