Skip to content

Commit

Permalink
Added docstrings to all the commands, and set made hippybot rewrite t…
Browse files Browse the repository at this point in the history
…he docs to substitute it it's own name
  • Loading branch information
Devon Jones committed Mar 10, 2013
1 parent cc3bb3e commit bba40c5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions hippybot/bot.py
Expand Up @@ -60,6 +60,10 @@ def __init__(self, config):
for channel in self._channels:
self.join_room(channel, config['connection']['nickname'])

self._at_name = u"@%s " % (config['connection']['nickname'].replace(" ",""),)
self._at_short_name = u"@%s " % (config['connection']['nickname']
.split(' ')[0].lower(),)

plugins = config.get('plugins', {}).get('load', [])
if plugins:
plugins = plugins.strip().split('\n')
Expand All @@ -68,9 +72,6 @@ def __init__(self, config):

self.load_plugins()

self._at_name = u"@%s " % (config['connection']['nickname'].replace(" ",""),)
self._at_short_name = u"@%s " % (config['connection']['nickname']
.split(' ')[0].lower(),)

def from_bot(self, mess):
"""Helper method to test if a message was sent from this bot.
Expand Down Expand Up @@ -178,6 +179,10 @@ def _idle_ping(self):
self._last_send_time = time.time()
self.send_message(' ')

def rewrite_docstring(self, m):
if m.__doc__ and m.__doc__.find("@NickName") > -1:
m.__func__.__doc__ = m.__doc__.replace("@NickName", self._at_name)

@botcmd
def load_plugins(self, mess=None, args=None):
"""Internal handler and bot command to dynamically load and reload
Expand Down Expand Up @@ -211,6 +216,7 @@ def load_plugins(self, mess=None, args=None):
plugin, command
))
continue
self.rewrite_docstring(m)
funcs.append((command, m))

# Check for commands that don't need to be directed at
Expand Down
4 changes: 4 additions & 0 deletions hippybot/plugins/rot13.py
Expand Up @@ -5,4 +5,8 @@ class Plugin(object):
"""
@directcmd
def rot13(self, mess, args):
"""
ROT13 the message
Format: @NickName rot13 <message>
"""
return args.encode('rot13')
4 changes: 4 additions & 0 deletions hippybot/plugins/udefine.py
Expand Up @@ -17,6 +17,10 @@ class Plugin(object):

@directcmd
def udefine(self, mess, args):
"""
Returns the Urban Dictionary definition of the passed in word
Format: @NickName udefine <word>
"""
term = args.strip()
req = requests.get(UD_SEARCH_URI, params={'term': term})
data = req.content
Expand Down

0 comments on commit bba40c5

Please sign in to comment.