Пример #1
0
def handle_forgetchan(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 = PlugPersist(event.channel)
    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 %s database" % event.channel)
    else:
        event.reply("no %s item in channel database" % what)
Пример #2
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 = PlugPersist(event.channel)
    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 %s database" % (what, event.channel))
Пример #3
0
def handle_lte(bot, ievent):
    user = getuser(ievent)
    if not user: return ievent.reply(getmessage('unknown_nick'))
    item = LteItem(user)
    args = ievent.rest.upper().split(' ')
    lteusers = PlugPersist('lteusers')
    if not lteusers.data: lteusers.data = {}

    if len(ievent.args) == 3 or len(ievent.args) == 2:
        if args[1] == '0':
            dayitem = LteItem(args[0])
            if user in dayitem.data.ltes.keys():
                del dayitem.data.ltes[user]            
                dayitem.save()
            return ievent.reply(getmessage('lte_removed') % (user, args[0]))
        if args[0] not in ('MO', 'DI', 'MI', 'DO', 'FR', 'SA', 'SO'): 
            #, 'MO', 'TU', 'WE', 'TH', 'FR', 'SA', 'SU'):
            return ievent.reply('LTE syntax: !lte MO 1900')
        item.data.ltes[args[0]] = args
        item.save()
        dayitem = LteItem(args[0])
        eta = " ".join(args[1:])
        eta = re.sub(r'(\d\d):(\d\d)',r'\1\2', eta)
        dayitem.data.ltes[user] = eta
        dayitem.save()
        lteusers.data[user] = time.time()
        lteusers.save()
        ievent.reply(getmessage('lte_set') % (user, eta))

    elif len(ievent.args) == 1:
        if args[0] in ('MO', 'DI', 'MI', 'DO', 'FR', 'SA', 'SO'):
            dayitem = LteItem(args[0])
            if len(dayitem.data.ltes.keys()) > 0:
                reply = 'LTEs für %s: ' % args[0]
                for user in dayitem.data.ltes.keys():
                    reply += '%s [%s] ' % (user, dayitem.data.ltes[user])
                ievent.reply(reply)
        else:
            ievent.reply(getmessage('err_unknown_day') % args[0])
    elif len(ievent.args) == 0:
        reply = []
        for day in weekdays:
            dayitem = LteItem(day)
            if len(dayitem.data.ltes.keys()) > 0:
                #reply += '%s: %s ' % (day, ', '.join(dayitem.data.ltes.keys()))
                reply.append('%s: %s ' % (day, ', '.join(dayitem.data.ltes.keys())))
        ievent.reply(" | ".join(reply))
    else:
        ievent.reply(str(len(ievent.rest.split(' '))))
Пример #4
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: event.missing("<item> and <match>") ; return
    what = what.lower()
    items = PlugPersist(event.channel)
    if not items.data: items.data = LazyDict()
    if items.data.has_key(what):
        for i in range(len(items.data[what])):
            if match in items.data[what][i]:
                del items.data[what][i]                
                items.save()
                break
    event.reply("item removed from %s database" % event.channel)
Пример #5
0
def handle_learnchan(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 = PlugPersist(event.channel)
    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 %s database" % (what, event.channel))
Пример #6
0
def handle_definechan(bot, event):
    """" arguments: <item> <description> - set an information item. """
    if not event.rest: event.missing("<item> <description>") ; return
    
    if event.rest.startswith('"'):
        result = re.search(r'"(.*?)" (.*)$', event.rest)
    else:
        result = re.search(r'(.*?) (.*)$', event.rest)
    try:
        what = result.group(0)
        description = result.group(1)
    except ValueError: event.missing("<item> <description>") ; return
    what = what.lower()
    items = PlugPersist(event.channel)
    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] = [description]
    items.save()
    event.reply("definition for %s updated" % (what, event.channel))
Пример #7
0
def handle_forgetchan(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 = PlugPersist(event.channel)
    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 %s database" % event.channel)
    else: event.reply("no %s item in channel database" % what)
Пример #8
0
def handle_forget(bot, event):
    """" set an information item. """
    if not event.rest:
        event.missing("<item> and <match>")
        return
    try:
        (what, match) = event.rest.split(" and ", 2)
    except ValueError:
        event.missing("<item> and <match>")
        return
    what = what.lower()
    items = PlugPersist(event.channel)
    if not items.data: items.data = LazyDict()
    if items.data.has_key(what):
        for i in range(len(items.data[what])):
            if match in items.data[what][i]:
                del items.data[what][i]
                items.save()
                break
    event.reply("item removed from %s database" % event.channel)
Пример #9
0
        {'value':None,'location':'back_door','name':"back_door",'description':""}
    ],
    'temperature':[],
    'barometer':[],
    'humidity':[],
    'beverage_supply':[],
    'power_consumption':[],
    'wind':[],
    'network_connections':[],
    'account_balance':[],
    'total_member_count':[],
    'people_now_present':[]
#radiation   #This is a super complex one. :/

})
sensorlist.save()

statussensors = PlugPersist('statussensors')
statussensors.save()

currentstatus = PlugPersist('currentstatus', False)

shared_data = {}
server = None
graphite = None
outputthread = None

## dummy callbacks to make sure plugin gets loaded on startup
def dummycb(bot, event): pass
callbacks.add("START", dummycb)
Пример #10
0
# command function are the bot that the event occured on and the event that
# triggered the command. Think the code speaks for itself here ;]


def handle_relayclone(bot, event):
    """ clone relays from one channel to the other. """
    new = event.origin or event.channel
    try:
        old = event.args[0]
    except IndexError, ex:
        event.missing('<old target>')
        return
    try:
        relay.data[new] = list(relay.data[old])
        del relay.data[old]
        relay.save()
    except KeyError:
        event.reply("i didn't join the %s wave" % old)
        return
    except Exception, ex:
        handle_exception()
    event.done()


cmnds.add('relay-clone', handle_relayclone, 'OPER')
examples.add('relay-clone', 'clone relay of old wave to the new',
             'relay-clone googlewave.com!w+Pu4YwndxA')


def handle_relay(bot, event):
    """ [<botname>] <type> <target> .. open a relay to a user. all input from us will be relayed. """