tweak info and wadsworth module formatting
parent
56f116732d
commit
7ded434a61
110
modules/info.py
110
modules/info.py
|
@ -8,84 +8,84 @@ http://inamidst.com/phenny/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def doc(phenny, input):
|
def doc(phenny, input):
|
||||||
"""Shows a command's documentation, and possibly an example."""
|
"""Shows a command's documentation, and possibly an example."""
|
||||||
name = input.group(1)
|
name = input.group(1)
|
||||||
name = name.lower()
|
name = name.lower()
|
||||||
|
|
||||||
if name in phenny.doc:
|
if name in phenny.doc:
|
||||||
phenny.reply(phenny.doc[name][0])
|
phenny.reply(phenny.doc[name][0])
|
||||||
if phenny.doc[name][1]:
|
if phenny.doc[name][1]:
|
||||||
phenny.say('e.g. ' + phenny.doc[name][1])
|
phenny.say('e.g. ' + phenny.doc[name][1])
|
||||||
doc.rule = ('$nick', '(?i)(?:help|doc) +([A-Za-z]+)(?:\?+)?$')
|
doc.rule = ('$nick', '(?i)(?:help|doc) +([A-Za-z]+)(?:\?+)?$')
|
||||||
doc.example = '$nickname: doc tell?'
|
doc.example = '$nickname: doc tell?'
|
||||||
doc.priority = 'low'
|
doc.priority = 'low'
|
||||||
|
|
||||||
def commands(phenny, input):
|
def commands(phenny, input):
|
||||||
# This function only works in private message
|
# This function only works in private message
|
||||||
if input.sender.startswith('#'): return
|
if input.sender.startswith('#'): return
|
||||||
names = ', '.join(sorted(phenny.doc.keys()))
|
names = ', '.join(sorted(phenny.doc.keys()))
|
||||||
phenny.say('Commands I recognise: ' + names + '.')
|
phenny.say('Commands I recognise: ' + names + '.')
|
||||||
phenny.say(("For help, do '%s: help example?' where example is the " +
|
phenny.say(("For help, do '%s: help example?' where example is the " +
|
||||||
"name of the command you want help for.") % phenny.nick)
|
"name of the command you want help for.") % phenny.nick)
|
||||||
commands.commands = ['commands']
|
commands.commands = ['commands']
|
||||||
commands.priority = 'low'
|
commands.priority = 'low'
|
||||||
|
|
||||||
def help(phenny, input):
|
def help(phenny, input):
|
||||||
response = (
|
response = (
|
||||||
"Hey there, I'm a friendly bot for this channel. Say \".commands\" " +
|
"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 " +
|
"to me in private for a list of my commands or check out my wiki " +
|
||||||
"page at %s. My owner is %s."
|
"page at %s. My owner is %s."
|
||||||
) % (phenny.config.helpurl, phenny.config.owner)
|
) % (phenny.config.helpurl, phenny.config.owner)
|
||||||
#phenny.reply(response)
|
#phenny.reply(response)
|
||||||
phenny.say(response)
|
phenny.say(response)
|
||||||
#help.rule = ('$nick', r'(?i)help(?:[?!]+)?$')
|
#help.rule = ('$nick', r'(?i)help(?:[?!]+)?$')
|
||||||
help.commands = ['help']
|
help.commands = ['help']
|
||||||
help.priority = 'low'
|
help.priority = 'low'
|
||||||
|
|
||||||
def stats(phenny, input):
|
def stats(phenny, input):
|
||||||
"""Show information on command usage patterns."""
|
"""Show information on command usage patterns."""
|
||||||
commands = {}
|
commands = {}
|
||||||
users = {}
|
users = {}
|
||||||
channels = {}
|
channels = {}
|
||||||
|
|
||||||
ignore = set(['f_note', 'startup', 'message', 'noteuri'])
|
ignore = set(['f_note', 'startup', 'message', 'noteuri'])
|
||||||
for (name, user), count in list(phenny.stats.items()):
|
for (name, user), count in list(phenny.stats.items()):
|
||||||
if name in ignore: continue
|
if name in ignore: continue
|
||||||
if not user: continue
|
if not user: continue
|
||||||
|
|
||||||
if not user.startswith('#'):
|
if not user.startswith('#'):
|
||||||
try: users[user] += count
|
try: users[user] += count
|
||||||
except KeyError: users[user] = count
|
except KeyError: users[user] = count
|
||||||
else:
|
else:
|
||||||
try: commands[name] += count
|
try: commands[name] += count
|
||||||
except KeyError: commands[name] = count
|
except KeyError: commands[name] = count
|
||||||
|
|
||||||
try: channels[user] += count
|
try: channels[user] += count
|
||||||
except KeyError: channels[user] = count
|
except KeyError: channels[user] = count
|
||||||
|
|
||||||
comrank = sorted([(b, a) for (a, b) in commands.items()], reverse=True)
|
comrank = sorted([(b, a) for (a, b) in commands.items()], reverse=True)
|
||||||
userank = sorted([(b, a) for (a, b) in users.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)
|
charank = sorted([(b, a) for (a, b) in channels.items()], reverse=True)
|
||||||
|
|
||||||
# most heavily used commands
|
# most heavily used commands
|
||||||
creply = 'most used commands: '
|
creply = 'most used commands: '
|
||||||
for count, command in comrank[:10]:
|
for count, command in comrank[:10]:
|
||||||
creply += '%s (%s), ' % (command, count)
|
creply += '%s (%s), ' % (command, count)
|
||||||
phenny.say(creply.rstrip(', '))
|
phenny.say(creply.rstrip(', '))
|
||||||
|
|
||||||
# most heavy users
|
# most heavy users
|
||||||
reply = 'power users: '
|
reply = 'power users: '
|
||||||
for count, user in userank[:10]:
|
for count, user in userank[:10]:
|
||||||
reply += '%s (%s), ' % (user, count)
|
reply += '%s (%s), ' % (user, count)
|
||||||
phenny.say(reply.rstrip(', '))
|
phenny.say(reply.rstrip(', '))
|
||||||
|
|
||||||
# most heavy channels
|
# most heavy channels
|
||||||
chreply = 'power channels: '
|
chreply = 'power channels: '
|
||||||
for count, channel in charank[:3]:
|
for count, channel in charank[:3]:
|
||||||
chreply += '%s (%s), ' % (channel, count)
|
chreply += '%s (%s), ' % (channel, count)
|
||||||
phenny.say(chreply.rstrip(', '))
|
phenny.say(chreply.rstrip(', '))
|
||||||
stats.commands = ['stats']
|
stats.commands = ['stats']
|
||||||
stats.priority = 'low'
|
stats.priority = 'low'
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(__doc__.strip())
|
print(__doc__.strip())
|
||||||
|
|
|
@ -14,4 +14,3 @@ wadsworth.commands = ['wadsworth']
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print(__doc__.strip())
|
print(__doc__.strip())
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue