Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New plugin #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion montybot/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ')
Expand All @@ -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,
Expand Down
Binary file added montybot/plugins/descriptive/.tasty.py.swp
Binary file not shown.
Empty file.
49 changes: 49 additions & 0 deletions montybot/plugins/descriptive/descriptiveplugin.py
Original file line number Diff line number Diff line change
@@ -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'
Empty file.
49 changes: 49 additions & 0 deletions montybot/plugins/squirrel/squirrel.py
Original file line number Diff line number Diff line change
@@ -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)