From 2e9ce67586f7e3a013f33579aba072aaba73ccfe Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 8 Aug 2018 10:33:33 +0100 Subject: [PATCH] Also track BitBot's words in words.py --- modules/words.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/words.py b/modules/words.py index 68971f24..d77e75a7 100644 --- a/modules/words.py +++ b/modules/words.py @@ -5,6 +5,8 @@ class Module(object): self.bot = bot bot.events.on("received").on("message").on("channel" ).hook(self.channel_message) + bot.events.on("self").on("message").on("channel" + ).hook(self.self_channel_message) bot.events.on("received").on("command").on("words" ).hook(self.words, channel_only=True, usage="", help= @@ -18,14 +20,14 @@ class Module(object): help="Show who has used a tracked word the most", usage="") - def channel_message(self, event): + def _channel_message(self, user, event): words = list(filter(None, event["message_split"])) word_count = len(words) user_words = event["channel"].get_user_setting( - event["user"].nickname, "words", 0) + user.nickname, "words", 0) user_words += word_count - event["channel"].set_user_setting(event["user"].nickname, + event["channel"].set_user_setting(user.nickname, "words", user_words) tracked_words = set(event["server"].get_setting( @@ -33,9 +35,14 @@ class Module(object): for word in words: if word.lower() in tracked_words: setting = "word-%s" % word - word_count = event["user"].get_setting(setting, 0) + word_count = user.get_setting(setting, 0) word_count += 1 - event["user"].set_setting(setting, word_count) + user.set_setting(setting, word_count) + def channel_message(self, event): + self._channel_message(event["user"], event) + def self_channel_message(self, event): + self._channel_message(event["server"].get_user( + event["server"].nickname), event) def words(self, event): if event["args_split"]: