2008-02-21 07:06:33 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""
|
|
|
|
info.py - Phenny Information Module
|
|
|
|
Copyright 2008, Sean B. Palmer, inamidst.com
|
|
|
|
Licensed under the Eiffel Forum License 2.
|
|
|
|
|
|
|
|
http://inamidst.com/phenny/
|
|
|
|
"""
|
|
|
|
|
|
|
|
def doc(phenny, input):
|
2012-01-03 14:27:55 -05:00
|
|
|
"""Shows a command's documentation, and possibly an example."""
|
|
|
|
name = input.group(1)
|
|
|
|
name = name.lower()
|
2008-02-21 07:06:33 -05:00
|
|
|
|
2012-01-03 14:27:55 -05:00
|
|
|
if name in phenny.doc:
|
|
|
|
phenny.reply(phenny.doc[name][0])
|
|
|
|
if phenny.doc[name][1]:
|
|
|
|
phenny.say('e.g. ' + phenny.doc[name][1])
|
2008-04-26 10:54:35 -04:00
|
|
|
doc.rule = ('$nick', '(?i)(?:help|doc) +([A-Za-z]+)(?:\?+)?$')
|
|
|
|
doc.example = '$nickname: doc tell?'
|
2008-02-21 07:06:33 -05:00
|
|
|
doc.priority = 'low'
|
|
|
|
|
|
|
|
def commands(phenny, input):
|
2012-01-03 14:27:55 -05:00
|
|
|
# This function only works in private message
|
|
|
|
if input.sender.startswith('#'): return
|
|
|
|
names = ', '.join(sorted(phenny.doc.keys()))
|
|
|
|
phenny.say('Commands I recognise: ' + names + '.')
|
|
|
|
phenny.say(("For help, do '%s: help example?' where example is the " +
|
|
|
|
"name of the command you want help for.") % phenny.nick)
|
2008-02-21 07:06:33 -05:00
|
|
|
commands.commands = ['commands']
|
|
|
|
commands.priority = 'low'
|
|
|
|
|
|
|
|
def help(phenny, input):
|
2012-01-03 14:27:55 -05:00
|
|
|
response = (
|
|
|
|
"Hey there, I'm a friendly bot for this channel. Say \".commands\" " +
|
|
|
|
"to me in private for a list of my commands or check out my wiki " +
|
|
|
|
"page at %s. My owner is %s."
|
|
|
|
) % (phenny.config.helpurl, phenny.config.owner)
|
|
|
|
#phenny.reply(response)
|
|
|
|
phenny.say(response)
|
2010-11-12 10:34:22 -05:00
|
|
|
#help.rule = ('$nick', r'(?i)help(?:[?!]+)?$')
|
|
|
|
help.commands = ['help']
|
2008-02-21 07:06:33 -05:00
|
|
|
help.priority = 'low'
|
|
|
|
|
2008-02-29 10:36:18 -05:00
|
|
|
def stats(phenny, input):
|
2012-01-03 14:27:55 -05:00
|
|
|
"""Show information on command usage patterns."""
|
|
|
|
commands = {}
|
|
|
|
users = {}
|
|
|
|
channels = {}
|
2008-02-29 10:36:18 -05:00
|
|
|
|
2012-02-18 03:30:01 -05:00
|
|
|
ignore = set(['f_note', 'startup', 'message', 'noteuri', 'logger',
|
|
|
|
'snarfuri', 'measure', 'messageAlert'])
|
2012-01-03 14:27:55 -05:00
|
|
|
for (name, user), count in list(phenny.stats.items()):
|
|
|
|
if name in ignore: continue
|
|
|
|
if not user: continue
|
2008-02-29 10:36:18 -05:00
|
|
|
|
2012-01-03 14:27:55 -05:00
|
|
|
if not user.startswith('#'):
|
|
|
|
try: users[user] += count
|
|
|
|
except KeyError: users[user] = count
|
|
|
|
else:
|
|
|
|
try: commands[name] += count
|
|
|
|
except KeyError: commands[name] = count
|
2008-02-29 10:36:18 -05:00
|
|
|
|
2012-01-03 14:27:55 -05:00
|
|
|
try: channels[user] += count
|
|
|
|
except KeyError: channels[user] = count
|
2008-02-29 10:36:18 -05:00
|
|
|
|
2012-01-03 14:27:55 -05:00
|
|
|
comrank = sorted([(b, a) for (a, b) in commands.items()], reverse=True)
|
|
|
|
userank = sorted([(b, a) for (a, b) in users.items()], reverse=True)
|
|
|
|
charank = sorted([(b, a) for (a, b) in channels.items()], reverse=True)
|
2008-02-29 10:36:18 -05:00
|
|
|
|
2012-01-03 14:27:55 -05:00
|
|
|
# most heavily used commands
|
|
|
|
creply = 'most used commands: '
|
|
|
|
for count, command in comrank[:10]:
|
|
|
|
creply += '%s (%s), ' % (command, count)
|
|
|
|
phenny.say(creply.rstrip(', '))
|
2008-02-29 10:36:18 -05:00
|
|
|
|
2012-01-03 14:27:55 -05:00
|
|
|
# most heavy users
|
|
|
|
reply = 'power users: '
|
|
|
|
for count, user in userank[:10]:
|
|
|
|
reply += '%s (%s), ' % (user, count)
|
|
|
|
phenny.say(reply.rstrip(', '))
|
2008-02-29 10:36:18 -05:00
|
|
|
|
2012-01-03 14:27:55 -05:00
|
|
|
# most heavy channels
|
|
|
|
chreply = 'power channels: '
|
|
|
|
for count, channel in charank[:3]:
|
|
|
|
chreply += '%s (%s), ' % (channel, count)
|
|
|
|
phenny.say(chreply.rstrip(', '))
|
2008-02-29 10:36:18 -05:00
|
|
|
stats.commands = ['stats']
|
|
|
|
stats.priority = 'low'
|
|
|
|
|
2008-02-21 07:06:33 -05:00
|
|
|
if __name__ == '__main__':
|
2012-01-03 14:27:55 -05:00
|
|
|
print(__doc__.strip())
|