From fb2cd452e963b8bc048161036903cd82d3b113f0 Mon Sep 17 00:00:00 2001 From: "Sean B. Palmer" Date: Mon, 10 Mar 2008 19:58:28 +0000 Subject: [PATCH] Some documentation and minor fixes. --- modules/admin.py | 5 +++++ modules/calc.py | 2 ++ modules/clock.py | 7 ++++++- modules/codepoints.py | 4 ++++ modules/head.py | 8 ++++++-- modules/info.py | 1 + modules/search.py | 4 ++++ modules/tell.py | 3 ++- modules/weather.py | 3 +++ phenny | 1 + 10 files changed, 34 insertions(+), 4 deletions(-) diff --git a/modules/admin.py b/modules/admin.py index de2a7a7..24b8fb6 100755 --- a/modules/admin.py +++ b/modules/admin.py @@ -8,22 +8,27 @@ http://inamidst.com/phenny/ """ def join(phenny, input): + """Join the specified channel. This is an admin-only command.""" # Can only be done in privmsg by an admin if input.sender.startswith('#'): return if input.admin: phenny.write(['JOIN'], input.group(2)) join.commands = ['join'] join.priority = 'low' +join.example = '.join #example' def part(phenny, input): + """Part the specified channel. This is an admin-only command.""" # Can only be done in privmsg by an admin if input.sender.startswith('#'): return if input.admin: phenny.write(['PART'], input.group(2)) part.commands = ['part'] part.priority = 'low' +part.example = '.part #example' def quit(phenny, input): + """Quit from the server. This is an owner-only command.""" # Can only be done in privmsg by the owner if input.sender.startswith('#'): return if input.owner: diff --git a/modules/calc.py b/modules/calc.py index 8e7caea..9a3b174 100755 --- a/modules/calc.py +++ b/modules/calc.py @@ -28,6 +28,7 @@ subs = [ ] def calc(phenny, input): + """Use the Frink online calculator.""" q = input.group(2) if not q: return phenny.say('0?') @@ -63,6 +64,7 @@ def calc(phenny, input): phenny.say(q + ' = ' + result) else: phenny.reply("Sorry, can't calculate that.") calc.commands = ['calc'] +calc.example = '.calc 5 + 3' if __name__ == '__main__': print __doc__.strip() diff --git a/modules/clock.py b/modules/clock.py index 9e38d7b..2ef6b21 100755 --- a/modules/clock.py +++ b/modules/clock.py @@ -186,7 +186,7 @@ TimeZones.update(TZ1) @deprecated def f_time(self, origin, match, args): - """.t [ ] - Returns the current time""" + """Returns the current time.""" tz = match.group(2) or 'GMT' # Personal time zones, because they're rad @@ -231,8 +231,11 @@ def f_time(self, origin, match, args): msg = time.strftime("%a, %d %b %Y %H:%M:%S " + str(tz), timenow) self.msg(origin.sender, msg) f_time.commands = ['t'] +f_time.name = 't' +f_time.example = '.t UTC' def beats(phenny, input): + """Shows the internet time in Swatch beats.""" beats = ((time.time() + 3600) % 86400) / 86.4 beats = int(math.floor(beats)) phenny.say('@%03i' % beats) @@ -243,6 +246,7 @@ def divide(input, by): return (input / by), (input % by) def yi(phenny, input): + """Shows whether it is currently yi or not.""" quadraels, remainder = divide(int(time.time()), 1753200) raels = quadraels * 4 extraraels, remainder = divide(remainder, 432000) @@ -255,6 +259,7 @@ yi.priority = 'low' # d8uv d8uv d8uv d8uv d8uv d8uv d8uv def tock(phenny, input): + """Shows the time from the USNO's atomic clock.""" u = urllib.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') info = u.info() u.close() diff --git a/modules/codepoints.py b/modules/codepoints.py index 89ea078..797fada 100755 --- a/modules/codepoints.py +++ b/modules/codepoints.py @@ -65,6 +65,7 @@ def codepoint_extended(arg): yield about(u, cp, name) def u(phenny, input): + """Look up unicode information.""" arg = input.bytes[3:] # phenny.msg('#inamidst', '%r' % arg) if not arg: @@ -115,11 +116,14 @@ def u(phenny, input): phenny.reply(' '.join('U+%04X' % ord(c) for c in text)) else: phenny.reply('Sorry, your input is too long!') u.commands = ['u'] +u.example = '.u 203D' def bytes(phenny, input): + """Show the input as pretty printed bytes.""" b = input.bytes phenny.reply('%r' % b[b.find(' ') + 1:]) bytes.commands = ['bytes'] +bytes.example = '.bytes \xe3\x8b\xa1' if __name__ == '__main__': print __doc__.strip() diff --git a/modules/head.py b/modules/head.py index 10a5337..2552d6f 100755 --- a/modules/head.py +++ b/modules/head.py @@ -67,7 +67,9 @@ def f_title(self, origin, match, args): uri = (uri or '').encode('utf-8') if not uri and hasattr(self, 'last_seen_uri'): - uri = self.last_seen_uri + uri = self.last_seen_uri.get('#swhack') + if not uri: + return phenny.msg(origin.sender, 'I need a URI to give the title of...') if not ':' in uri: uri = 'http://' + uri @@ -140,7 +142,9 @@ f_title.commands = ['title'] def noteuri(phenny, input): uri = input.group(1).encode('utf-8') - phenny.bot.last_seen_uri = uri + if not hasattr(phenny.bot, 'last_seen_uri'): + phenny.bot.last_seen_uri = {} + phenny.bot.last_seen_uri[input.sender] = uri noteuri.rule = r'.*(http://[^<> "]+)[,.]?' noteuri.priority = 'low' diff --git a/modules/info.py b/modules/info.py index 932ac2f..a40a34f 100755 --- a/modules/info.py +++ b/modules/info.py @@ -41,6 +41,7 @@ help.rule = ('$nick', r'(?i)help(?:[?!]+)?$') help.priority = 'low' def stats(phenny, input): + """Show information on command usage patterns.""" commands = {} users = {} channels = {} diff --git a/modules/search.py b/modules/search.py index 856d3db..fbd6596 100755 --- a/modules/search.py +++ b/modules/search.py @@ -48,6 +48,7 @@ def formatnumber(n): return ''.join(parts) def g(phenny, input): + """Queries Google for the specified input.""" query = input.group(2) if not query: return phenny.reply('.g what?') @@ -57,8 +58,10 @@ def g(phenny, input): else: phenny.reply("No results found for '%s'." % query) g.commands = ['g'] g.priority = 'high' +g.example = '.g swhack' def gc(phenny, input): + """Returns the number of Google results for the specified input.""" query = input.group(2) if not query: return phenny.reply('.gc what?') @@ -66,6 +69,7 @@ def gc(phenny, input): phenny.say(query + ': ' + num) gc.commands = ['gc'] gc.priority = 'high' +gc.example = '.gc extrapolate' r_query = re.compile( r'\+?"[^"\\]*(?:\\.[^"\\]*)*"|\[[^]\\]*(?:\\.[^]\\]*)*\]|\S+' diff --git a/modules/tell.py b/modules/tell.py index e4af264..dc8ea46 100755 --- a/modules/tell.py +++ b/modules/tell.py @@ -40,7 +40,8 @@ def dumpReminders(fn, data): for remindon in data[tellee]: line = '\t'.join((tellee,) + remindon) f.write(line + '\n') - f.close() + try: f.close() + except IOError: pass return True def setup(self): diff --git a/modules/weather.py b/modules/weather.py index 77f0fd0..787551c 100755 --- a/modules/weather.py +++ b/modules/weather.py @@ -84,6 +84,9 @@ def f_weather(self, origin, match, args): if args[0].startswith('.weather '): return icao_code = match.group(2) + if not icao_code: + return self.msg(origin.sender, 'Try .weather London, for example?') + if (not len(icao_code) == 4) or \ (len(icao_code) > 1 and icao_code[0] in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' and icao_code[1] in 'abcdefghijklmnopqrstuvwxyz'): diff --git a/phenny b/phenny index 8b3748a..0137239 100755 --- a/phenny +++ b/phenny @@ -29,6 +29,7 @@ def create_default_config(fn): host = 'irc.example.net' channels = ['#example', '#test'] owner = 'yournickname' + # serverpass = 'yourserverpassword' # These are people who will be able to use admin.py's functions... admins = [owner, 'someoneyoutrust']