diff --git a/montybot/event.py b/montybot/event.py index 163247f..9fc5b7f 100755 --- a/montybot/event.py +++ b/montybot/event.py @@ -11,6 +11,7 @@ from plugins.link_log.link_log import LinkCheckLogPlugin from plugins.taunt_user import SeanzResponse from plugins.taunt_user import AlbertResponse +from plugins.squirrel.squirrel import DisruptiveSquirrelPlugin def _tokenize_channels(raw_str): channels = raw_str.split(' ') @@ -37,7 +38,7 @@ def _print_instr(): else: command_plugins = [PuppyCommandPlugin, CreativeQuitPlugin] taunt_plugins = [SeanzResponse] - message_plugins = [LinkCheckLogPlugin] + message_plugins = [LinkCheckLogPlugin, DisruptiveSquirrelPlugin] reactor.connectTCP('irc.freenode.net', 6667, diff --git a/montybot/plugins/descriptive/.tasty.py.swp b/montybot/plugins/descriptive/.tasty.py.swp new file mode 100644 index 0000000..f37faa8 Binary files /dev/null and b/montybot/plugins/descriptive/.tasty.py.swp differ diff --git a/montybot/plugins/descriptive/__init__.py b/montybot/plugins/descriptive/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/montybot/plugins/descriptive/descriptiveplugin.py b/montybot/plugins/descriptive/descriptiveplugin.py new file mode 100644 index 0000000..caceb9f --- /dev/null +++ b/montybot/plugins/descriptive/descriptiveplugin.py @@ -0,0 +1,49 @@ +# _*_ coding: utf-8 -*- +from ..puppy_plugin.get_puppy import PuppyFetch + + +class DescriptivePlugin(object): + registered_descriptions = ( + 'tasty', + 'lame', + 'funny', + 'amazing', + ) + + @classmethod + def run(cls, user, channel, message, bot_instance, fetcher=PuppyFetch): + """ + Descriptive plugin:: + + 'Some tasty sushi' + """ + if user != bot_instance.nickname: + return + + message_words = message.lower().split() + punctuation_set = set(string.punctuation) + for registered in cls.registered_descriptions: + try: + subject_word = message_words[message_words.index(registered.lower()) + 1] + subject = ''.join(ch for ch in subject if ch not in punctuation_set) + except IndexError: + continue + + bot_instance.handled = True + reply = fetcher.get(subject) + bot_instance.msg(channel, reply) + return reply + + +if __name__ == "__main__": + from mock import Mock + + def mock_msg(chan, msg): + print chan + print msg + + bot_instance = Mock() + bot_instance.msg = mock_msg + + reply = DescriptivePlugin.run('test', '#scoobydoo', "that's some tasty sushi", bot_instance) + assert reply == 'sushi' diff --git a/montybot/plugins/squirrel/__init__.py b/montybot/plugins/squirrel/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/montybot/plugins/squirrel/squirrel.py b/montybot/plugins/squirrel/squirrel.py new file mode 100644 index 0000000..55676c1 --- /dev/null +++ b/montybot/plugins/squirrel/squirrel.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# idea for this stolen from jslabot +# requires puppybot plugin + + +from ..metaclass import PluginMetaClass + +from ..puppy_plugin.get_puppy import PuppyFetch + + + + + +class DisruptiveSquirrelPlugin(object): + __metaclass__ = PluginMetaClass + name = "SQUIRREL!" + + # TODO: Not sure this is properly done (see metaclass) + def __init__(self): + """ Instantiate the squirrel photo fetcher """ + pass + + @classmethod + def run(cls, user, channel, message, bot_instance): + """ """ + instance = cls() + # if it looks like there might be a link we want + if 'squirrel' in message.lower() and user != bot_instance.nickname: + bot_instance.handled = True + instance._run(user, channel, message, bot_instance) + + def _run(self, user, channel, message, bot_instance): + # get a squirrel pancake + squirrel_reply = PuppyFetch.get('squirrel') + bot_instance.msg(channel, squirrel_reply) + +if __name__ == "__main__": + from mock import Mock + + def mock_msg(chan, msg): + print chan + print msg + + bot_instance = Mock() + bot_instance.msg = mock_msg + from ..puppy_plugin.puppy_plugin import PuppyCommandPlugin + pcp = PuppyCommandPlugin.install(bot_instance) + + DisruptiveSquirrelPlugin.run('test', '#scoobydoo', "no squirrels here", bot_instance)