diff options
| author | 2016-04-05 18:43:17 +0100 | |
|---|---|---|
| committer | 2016-04-05 18:43:17 +0100 | |
| commit | 27c0de701cf2414a3e49326aeee9df618865cca2 (patch) | |
| tree | 64e486a3511b15c0e05eddc6cc645c52cde237c6 | |
| parent | fixed a crash-causing bug in lastfm when userplaycount isn't present. (diff) | |
added words.py for keeping track of how many words people have said.
| -rw-r--r-- | modules/words.py | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/words.py b/modules/words.py new file mode 100644 index 00000000..c0c8169b --- /dev/null +++ b/modules/words.py @@ -0,0 +1,32 @@ + + +class Module(object): + def __init__(self, bot): + self.bot = bot + bot.events.on("received").on("message").on("channel" + ).hook(self.channel_message) + bot.events.on("received").on("command").on("words" + ).hook(self.words, channel_only=True) + + def channel_message(self, event): + word_count = len(list(filter(None, event["message_split" + ]))) + words = event["user"].get_setting("words", {}) + if not event["channel"].name in words: + words[event["channel"].name] = 0 + words[event["channel"].name] += word_count + event["user"].set_setting("words", words) + + def words(self, event): + if event["args_split"]: + target = event["server"].get_user(event["args_split" + ][0]) + else: + target = event["user"] + words = target.get_setting("words", {}) + this_channel = words.get(event["target"].name, 0) + total = 0 + for channel in words: + total += words[channel] + event["stdout"].write("%s has used %d words (%d in %s)" % ( + target.nickname, total, this_channel, event["target"].name)) |
