Some documentation and minor fixes.

master
Sean B. Palmer 2008-03-10 19:58:28 +00:00
parent 5cad6661c9
commit fb2cd452e9
10 changed files with 34 additions and 4 deletions

View File

@ -8,22 +8,27 @@ http://inamidst.com/phenny/
""" """
def join(phenny, input): def join(phenny, input):
"""Join the specified channel. This is an admin-only command."""
# Can only be done in privmsg by an admin # Can only be done in privmsg by an admin
if input.sender.startswith('#'): return if input.sender.startswith('#'): return
if input.admin: if input.admin:
phenny.write(['JOIN'], input.group(2)) phenny.write(['JOIN'], input.group(2))
join.commands = ['join'] join.commands = ['join']
join.priority = 'low' join.priority = 'low'
join.example = '.join #example'
def part(phenny, input): def part(phenny, input):
"""Part the specified channel. This is an admin-only command."""
# Can only be done in privmsg by an admin # Can only be done in privmsg by an admin
if input.sender.startswith('#'): return if input.sender.startswith('#'): return
if input.admin: if input.admin:
phenny.write(['PART'], input.group(2)) phenny.write(['PART'], input.group(2))
part.commands = ['part'] part.commands = ['part']
part.priority = 'low' part.priority = 'low'
part.example = '.part #example'
def quit(phenny, input): def quit(phenny, input):
"""Quit from the server. This is an owner-only command."""
# Can only be done in privmsg by the owner # Can only be done in privmsg by the owner
if input.sender.startswith('#'): return if input.sender.startswith('#'): return
if input.owner: if input.owner:

View File

@ -28,6 +28,7 @@ subs = [
] ]
def calc(phenny, input): def calc(phenny, input):
"""Use the Frink online calculator."""
q = input.group(2) q = input.group(2)
if not q: if not q:
return phenny.say('0?') return phenny.say('0?')
@ -63,6 +64,7 @@ def calc(phenny, input):
phenny.say(q + ' = ' + result) phenny.say(q + ' = ' + result)
else: phenny.reply("Sorry, can't calculate that.") else: phenny.reply("Sorry, can't calculate that.")
calc.commands = ['calc'] calc.commands = ['calc']
calc.example = '.calc 5 + 3'
if __name__ == '__main__': if __name__ == '__main__':
print __doc__.strip() print __doc__.strip()

View File

@ -186,7 +186,7 @@ TimeZones.update(TZ1)
@deprecated @deprecated
def f_time(self, origin, match, args): def f_time(self, origin, match, args):
""".t [ <timezone> ] - Returns the current time""" """Returns the current time."""
tz = match.group(2) or 'GMT' tz = match.group(2) or 'GMT'
# Personal time zones, because they're rad # 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) msg = time.strftime("%a, %d %b %Y %H:%M:%S " + str(tz), timenow)
self.msg(origin.sender, msg) self.msg(origin.sender, msg)
f_time.commands = ['t'] f_time.commands = ['t']
f_time.name = 't'
f_time.example = '.t UTC'
def beats(phenny, input): def beats(phenny, input):
"""Shows the internet time in Swatch beats."""
beats = ((time.time() + 3600) % 86400) / 86.4 beats = ((time.time() + 3600) % 86400) / 86.4
beats = int(math.floor(beats)) beats = int(math.floor(beats))
phenny.say('@%03i' % beats) phenny.say('@%03i' % beats)
@ -243,6 +246,7 @@ def divide(input, by):
return (input / by), (input % by) return (input / by), (input % by)
def yi(phenny, input): def yi(phenny, input):
"""Shows whether it is currently yi or not."""
quadraels, remainder = divide(int(time.time()), 1753200) quadraels, remainder = divide(int(time.time()), 1753200)
raels = quadraels * 4 raels = quadraels * 4
extraraels, remainder = divide(remainder, 432000) extraraels, remainder = divide(remainder, 432000)
@ -255,6 +259,7 @@ yi.priority = 'low'
# d8uv d8uv d8uv d8uv d8uv d8uv d8uv # d8uv d8uv d8uv d8uv d8uv d8uv d8uv
def tock(phenny, input): 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') u = urllib.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl')
info = u.info() info = u.info()
u.close() u.close()

View File

@ -65,6 +65,7 @@ def codepoint_extended(arg):
yield about(u, cp, name) yield about(u, cp, name)
def u(phenny, input): def u(phenny, input):
"""Look up unicode information."""
arg = input.bytes[3:] arg = input.bytes[3:]
# phenny.msg('#inamidst', '%r' % arg) # phenny.msg('#inamidst', '%r' % arg)
if not arg: if not arg:
@ -115,11 +116,14 @@ def u(phenny, input):
phenny.reply(' '.join('U+%04X' % ord(c) for c in text)) phenny.reply(' '.join('U+%04X' % ord(c) for c in text))
else: phenny.reply('Sorry, your input is too long!') else: phenny.reply('Sorry, your input is too long!')
u.commands = ['u'] u.commands = ['u']
u.example = '.u 203D'
def bytes(phenny, input): def bytes(phenny, input):
"""Show the input as pretty printed bytes."""
b = input.bytes b = input.bytes
phenny.reply('%r' % b[b.find(' ') + 1:]) phenny.reply('%r' % b[b.find(' ') + 1:])
bytes.commands = ['bytes'] bytes.commands = ['bytes']
bytes.example = '.bytes \xe3\x8b\xa1'
if __name__ == '__main__': if __name__ == '__main__':
print __doc__.strip() print __doc__.strip()

View File

@ -67,7 +67,9 @@ def f_title(self, origin, match, args):
uri = (uri or '').encode('utf-8') uri = (uri or '').encode('utf-8')
if not uri and hasattr(self, 'last_seen_uri'): 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: if not ':' in uri:
uri = 'http://' + uri uri = 'http://' + uri
@ -140,7 +142,9 @@ f_title.commands = ['title']
def noteuri(phenny, input): def noteuri(phenny, input):
uri = input.group(1).encode('utf-8') 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.rule = r'.*(http://[^<> "]+)[,.]?'
noteuri.priority = 'low' noteuri.priority = 'low'

View File

@ -41,6 +41,7 @@ help.rule = ('$nick', r'(?i)help(?:[?!]+)?$')
help.priority = 'low' help.priority = 'low'
def stats(phenny, input): def stats(phenny, input):
"""Show information on command usage patterns."""
commands = {} commands = {}
users = {} users = {}
channels = {} channels = {}

View File

@ -48,6 +48,7 @@ def formatnumber(n):
return ''.join(parts) return ''.join(parts)
def g(phenny, input): def g(phenny, input):
"""Queries Google for the specified input."""
query = input.group(2) query = input.group(2)
if not query: if not query:
return phenny.reply('.g what?') return phenny.reply('.g what?')
@ -57,8 +58,10 @@ def g(phenny, input):
else: phenny.reply("No results found for '%s'." % query) else: phenny.reply("No results found for '%s'." % query)
g.commands = ['g'] g.commands = ['g']
g.priority = 'high' g.priority = 'high'
g.example = '.g swhack'
def gc(phenny, input): def gc(phenny, input):
"""Returns the number of Google results for the specified input."""
query = input.group(2) query = input.group(2)
if not query: if not query:
return phenny.reply('.gc what?') return phenny.reply('.gc what?')
@ -66,6 +69,7 @@ def gc(phenny, input):
phenny.say(query + ': ' + num) phenny.say(query + ': ' + num)
gc.commands = ['gc'] gc.commands = ['gc']
gc.priority = 'high' gc.priority = 'high'
gc.example = '.gc extrapolate'
r_query = re.compile( r_query = re.compile(
r'\+?"[^"\\]*(?:\\.[^"\\]*)*"|\[[^]\\]*(?:\\.[^]\\]*)*\]|\S+' r'\+?"[^"\\]*(?:\\.[^"\\]*)*"|\[[^]\\]*(?:\\.[^]\\]*)*\]|\S+'

View File

@ -40,7 +40,8 @@ def dumpReminders(fn, data):
for remindon in data[tellee]: for remindon in data[tellee]:
line = '\t'.join((tellee,) + remindon) line = '\t'.join((tellee,) + remindon)
f.write(line + '\n') f.write(line + '\n')
f.close() try: f.close()
except IOError: pass
return True return True
def setup(self): def setup(self):

View File

@ -84,6 +84,9 @@ def f_weather(self, origin, match, args):
if args[0].startswith('.weather '): return if args[0].startswith('.weather '): return
icao_code = match.group(2) 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 \ if (not len(icao_code) == 4) or \
(len(icao_code) > 1 and icao_code[0] in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' and (len(icao_code) > 1 and icao_code[0] in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' and
icao_code[1] in 'abcdefghijklmnopqrstuvwxyz'): icao_code[1] in 'abcdefghijklmnopqrstuvwxyz'):

1
phenny
View File

@ -29,6 +29,7 @@ def create_default_config(fn):
host = 'irc.example.net' host = 'irc.example.net'
channels = ['#example', '#test'] channels = ['#example', '#test']
owner = 'yournickname' owner = 'yournickname'
# serverpass = 'yourserverpassword'
# These are people who will be able to use admin.py's functions... # These are people who will be able to use admin.py's functions...
admins = [owner, 'someoneyoutrust'] admins = [owner, 'someoneyoutrust']