Example #1
0
def handle_forget(bot, event):
    """" arguments: <item> and <matchstring> - set an information item. """
    if not event.rest:
        event.missing("<item> and <match>")
        return
    try:
        (what, match) = event.rest.split(" and ", 2)
    except ValueError:
        what = event.rest
        match = None
    what = what.lower()
    items = GlobalPersist("learndb")
    got = False
    if not items.data: items.data = LazyDict()
    if items.data.has_key(what):
        if match == None:
            del items.data[what]
            got = True
        else:
            for i in range(len(items.data[what])):
                if match in items.data[what][i]:
                    del items.data[what][i]
                    got = True
                    break
    if got:
        items.save()
        event.reply("item removed from global database")
    else:
        event.reply("no %s item in global database" % what)
Example #2
0
def handle_learntoglobal(bot, event):
    """ argument: <searchtxt>  - search the items the bot has learned. """
    items = PlugPersist(event.channel)
    globalitems = GlobalPersist("learndb")
    for i in items.data.keys():
        if not globalitems.data.has_key(i): globalitems.data[i] = []
        globalitems.data[i].extend(items.data)
    globalitems.save()
    event.reply("%s items copy to the global database. " % len(items.data))
Example #3
0
def handle_definetoglobal(bot, event):
    """ argument: <searchtxt>  - search the items the bot has defineed. """
    items = PlugPersist(event.channel)
    globalitems = GlobalPersist("definedb")
    for i in items.data.keys():
        if not globalitems.data.has_key(i): globalitems.data[i] = []
        globalitems.data[i].extend(items.data)
    globalitems.save()
    event.reply("%s items copy to the global database. " % len(items.data))
Example #4
0
def handle_learn(bot, event):
    """" arguments: <item> is <description> - set an information item. """
    if not event.rest: event.missing("<item> is <description>") ; return
    try: (what, description) = event.rest.split(" is ", 1)
    except ValueError: event.missing("<item> is <description>") ; return
    what = what.lower()
    items = GlobalPersist("learndb")
    if not items.data: items.data = LazyDict()
    if not items.data.has_key(what): items.data[what] = []
    if description not in items.data[what]: items.data[what].append(description)
    items.save()
    event.reply("%s item added to global database" % what)
Example #5
0
def handle_learn(bot, event):
    """" arguments: <item> is <description> - set an information item. """
    if not event.rest:
        event.missing("<item> is <description>")
        return
    try:
        (what, description) = event.rest.split(" is ", 1)
    except ValueError:
        event.missing("<item> is <description>")
        return
    what = what.lower()
    items = GlobalPersist("learndb")
    if not items.data: items.data = LazyDict()
    if not items.data.has_key(what): items.data[what] = []
    if description not in items.data[what]:
        items.data[what].append(description)
    items.save()
    event.reply("%s item added to global database" % what)
Example #6
0
def handle_forget(bot, event):
    """" arguments: <item> and <matchstring> - set an information item. """
    if not event.rest: event.missing("<item> and <match>") ; return
    try: (what, match) = event.rest.split(" and ", 2)
    except ValueError: what = event.rest ; match = None
    what = what.lower()
    items = GlobalPersist("definedb")
    got = False
    if not items.data: items.data = LazyDict()
    if items.data.has_key(what):
        if match == None: del items.data[what] ; got = True
        else:
            for i in range(len(items.data[what])):
                if match in items.data[what][i]:
                    del items.data[what][i]                
                    got = True
                    break
    if got: items.save() ; event.reply("item removed from global database")
    else: event.reply("no %s item in global database" % what)
Example #7
0
def handle_define(bot, event):
    """" arguments: <item> <description> - set an information item. """
    if not event.rest: 
        event.missing("<item> <description>") ; return

    if event.rest.startswith('"'):
        result = re.match(r'"(.*?)" (.*)$', event.rest)
    else:
        result = re.match(r'(.*?) (.*)$', event.rest)
    if result == None:
        return handle_whatis(bot, event)
    else:
        what = result.group(1)
        description = result.group(2)
    what = what.lower()
    items = GlobalPersist("definedb")
    if not items.data: items.data = LazyDict()
    if not items.data.has_key(what): items.data[what] = []
    if description not in items.data[what]: items.data[what].append(description)
    items.save()
    if event.channel == "#c-base":
        bot.say(event.channel, "definition for %s updated" % what)
    else:
        event.reply("definition for %s updated" % what)