plugins/wtf_plugin.py
author Mikael Berthe <mikael@lilotux.net>
Thu, 03 May 2007 19:32:28 +0200
changeset 33 adf562e77977
parent 24 7d7edae239c9
permissions -rw-r--r--
DICT.py: Get rid of tabs (coding style)

#$ neutron_plugin 01
# 2007-05 Mikael Berthe <mikael@lilotux.net>

import re

WTF_FILE = 'static/wtf.txt'

def handler_wtf(type, source, parameters):
    parameters = parameters.rstrip(" ?\n").lstrip()

    # 1 entry = "keyword\tdefinition"
    word = parameters.upper() + "\t"

    if not parameters:
        if type == 'private':
            smsg(type, source, "Gimme an acronym!")
        return

    # Look up the keyword in the wtf file...  We may have several hits.
    reply = ''.join(line for line in file(WTF_FILE) if line.startswith(word))

    if not reply:
        if type == 'private':
            reply = "Sorry, I don't know what " + parameters + " means..."
        else:
            return
    else:
        reply= re.sub("\t+", ": ", reply.rstrip())

    smsg(type, source, reply)

register_command_handler(handler_wtf, 'wtf', 0,
                         'Translates acronyms for you', 'wtf', ['wtf wtf'])

# vim:set et sts=4: