help.py: online documentation (use .help)

This commit is contained in:
Ryan Hitchman 2009-11-18 20:20:59 -07:00
parent 5f1ac6254e
commit e3bb74a365
12 changed files with 41 additions and 9 deletions

View File

@ -26,6 +26,9 @@ class Input(object):
def reply(self, msg):
self.say(self.nick + ': ' + msg)
def pm(self, msg):
self.conn.msg(self.nick, msg)
def run(func, input):
ac = func.func_code.co_argcount

View File

@ -57,6 +57,11 @@ def babel_gen(inp):
@hook.command
def babel(inp):
".babel <sentence> -- translates <sentence> through multiple languages"
if not inp:
return babel.__doc__
try:
return list(babel_gen(inp))[-1][2]
except IOError, e:
@ -65,6 +70,11 @@ def babel(inp):
@hook.command
def babelext(inp):
".babelext <sentence> -- like .babel, but with more detailed output"
if not inp:
return babelext.__doc__
try:
babels = list(babel_gen(inp))
except IOError, e:

View File

@ -13,7 +13,10 @@ MAX_STEPS = 1000000
@hook.command
def bf(inp):
"""Runs a Brainfuck program."""
".bf <prog> -- executes brainfuck program <prog>"""
if not inp:
return bf.__doc__
program = re.sub('[^][<>+-.,]', '', inp)

View File

@ -6,6 +6,11 @@ from util import hook
@hook.command('god')
@hook.command
def bible(inp):
".bible <passage> -- gets <passage> from the Bible (ESV)"
if not inp:
return bible.__doc__
base_url = 'http://www.esvapi.org/v2/rest/passageQuery?key=IP&' \
'output-format=plain-text&include-heading-horizontal-lines&' \
'include-headings=false&include-passage-horizontal-lines=false&' \

View File

@ -31,7 +31,7 @@ def nrolls(count, n):
@hook.command
def dice(inp):
".dice <diceroll> - simulates dicerolls, e.g. .dice 2d20-d5+4 roll 2 " \
".dice <diceroll> -- simulates dicerolls, e.g. .dice 2d20-d5+4 roll 2 " \
"D20s, subtract 1D5, add 4"
if not inp.strip():
return dice.__doc__

View File

@ -3,9 +3,9 @@ from pycparser.cdecl import explain_c_declaration
@hook.command('explain')
def explain(inp):
".explain <c expression> -- gives an explanation of x expression"
".explain <c expression> -- gives an explanation of C expression"
if not inp:
return ""
return explain.__doc__
try:
result = explain_c_declaration(inp.rstrip())

View File

@ -15,5 +15,6 @@ def sha1(inp):
@hook.command
def hash(inp):
".hash <text> -- returns hashes of <text>"
return ', '.join(x + ": " + getattr(hashlib, x)(inp).hexdigest()
for x in 'md5 sha1 sha256'.split())

View File

@ -5,5 +5,9 @@ from util import hook
@hook.command
def profile(inp):
".profile <username> -- links to <username>'s profile on SA"
if not inp:
return profile.__doc__
return 'http://forums.somethingawful.com/member.php?action=getinfo' + \
'&username=' + '+'.join(inp.split())

View File

@ -9,6 +9,11 @@ re_lineends = re.compile(r'[\r\n]*')
@hook.command
def py(inp):
".py <prog> -- executes python code <prog>"
if not inp:
return py.__doc__
res = urllib.urlopen("http://eval.appspot.com/eval?statement=%s" %
urllib.quote(inp.strip(), safe='')).readlines()
if len(res) == 0:

View File

@ -32,7 +32,7 @@ def seeninput(bot, input):
@hook.command
def seen(bot, input):
".seen <nick> - Tell when a nickname was last in active in irc"
".seen <nick> -- Tell when a nickname was last in active in irc"
if len(input.msg) < 6:
return seen.__doc__

View File

@ -48,7 +48,7 @@ def tellinput(bot, input):
@hook.command
def showtells(bot, input):
".showtells - View all pending tell messages (sent in PM)."
".showtells -- view all pending tell messages (sent in PM)."
dbpath = os.path.join(bot.persist_dir, dbname)
conn = dbconnect(dbpath)
@ -69,14 +69,14 @@ def showtells(bot, input):
conn.commit()
else:
input.msg(input.nick, "You have no pending tells.")
input.pm("You have no pending tells.")
conn.close()
@hook.command
def tell(bot, input):
".tell <nick> <message> - Relay <message> to <nick> the next time he talks"
".tell <nick> <message> -- relay <message> to <nick> when <nick> is around"
if len(input.msg) < 6:
return tell.__doc__

View File

@ -26,7 +26,8 @@ def unescape_xml(string):
@hook.command
def twitter(inp):
".twitter <user>/<user> <n>/<id> - gets last/<n>th tweet from <user>/gets tweet <id>"
".twitter <user>/<user> <n>/<id>/#<hashtag> -- gets last/<n>th tweet from"\
"<user>/gets tweet <id>/gets random tweet with #<hashtag>"
inp = inp.strip()
if not inp:
return twitter.__doc__