def handle_bd(bot, ievent):
    """ bd [<nr|user>] .. show birthday of month or user """
    if not ievent.rest:    
        handle_checkbd(bot, ievent)
        return
    try:
        int(ievent.args[0])
        handle_checkbd2(bot, ievent)
        return
    except (IndexError, ValueError):
        who = ievent.args[0].lower()
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("don't know userhost of %s" % who)
        return
    name = users.getname(userhost)
    if not name:
        ievent.reply("can't find user for %s" % userhost)
        return
    s = create_session()
    bd = s.query(Birthday).filter(Birthday.name==name).first()
    if bd:
        ievent.reply('birthday of %s is %s' % (who, bd.birthday))
    else:
        ievent.reply('no birthday know for %s' % name)
Exemple #2
0
def handle_addshop(bot, ievent):
    """ shop-add <username> <item> .. add items to shop list of <username>"""
    if len(ievent.args) < 2:
        ievent.missing('<username> <item>')
        return
    else:
        who = ievent.args[0]
        what = ' '.join(ievent.args[1:])
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't find userhost of %s" % who)
        return
    # get username of use giviing the command
    username = users.getname(ievent.userhost)
    # get username of person we want to knwo the shop list of
    whoname = users.getname(userhost)
    if not whoname:
        ievent.reply("can't find user for %s" % userhost)
        return
    if users.permitted(userhost, username, 'shop'):
        shops[whoname] = what
        shops.save()
        ievent.reply('shop item added')
    else:
        ievent.reply("%s does not share shopping list with %s" % (who, \
username))
def handle_age(bot, ievent):
    """ age <nick> .. show age of user """
    try:
        who = ievent.args[0].lower()
    except IndexError:
        ievent.missing('<nick>')
        return
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("don't know userhost of %s" % who)
        return
    name = users.getname(userhost)
    if not name:
        ievent.reply("can't find user for %s" % userhost)
        return
    s = create_session()
    bd = s.query(Birthday).filter(Birthday.name==name).first()
    try:
        birthday = bd.birthday
    except (TypeError, AttributeError):
        ievent.reply("can't find birthday data for %s" % who)
        return
    btime = strtotime(birthday)
    if btime == None:
        ievent.reply("can't make a date out of %s" % birthday)
        return
    age = int(time.time()) - int(btime)
    ievent.reply("age of %s is %s" % (who, elapsedstring(age, ywd=True)))
Exemple #4
0
def handle_ignore(bot, ievent):

    """ ignore nick for number of seconds. """

    try:
        (nick, nrseconds) = ievent.args
        nrseconds = int(nrseconds)
    except ValueError:
        ievent.missing('<nick> <seconds>')
        return

    userhost = getwho(bot, nick)

    if not userhost:
        ievent.reply("can't get userhost of %s" % nick)
        return

    allowed = users.allowed(userhost, 'OPER', log=False)

    if allowed:
        ievent.reply("can't ignore OPER")
        return

    addignore(userhost, nrseconds)
    ievent.reply("ignoring %s for %s seconds" % (nick, nrseconds))
Exemple #5
0
def handle_merge(bot, ievent):
    """ user-merge <name> <nick> .. merge the userhost into a already \
        existing user """
    if len(ievent.args) != 2:
        ievent.missing('<name> <nick>')
        return  
    name, nick = ievent.args
    name = name.lower()
    if users.gotperm(name, 'OPER') and not users.allowed(ievent.userhost, \
'OPER'):
        ievent.reply("only OPER perm can merge with OPER user")
        return
    if name == 'owner' and not bot.ownercheck(ievent, "can merge with owner \
user"):
         return 
    if not users.exist(name):
        ievent.reply("we have no user %s" % name)
        return
    userhost = getwho(bot, nick)
    if not userhost:
        ievent.reply("can't find userhost of %s" % nick)
        return
    username = users.getname(userhost)
    if username:
        ievent.reply('we already have a user with userhost %s (%s)' % \
(userhost, username))
        return
    result = 0
    try:
        result = users.merge(name, userhost)
    except Exception, ex:
        ievent.reply("ERROR: %s" % str(ex))
        return
Exemple #6
0
def handle_throttleset(bot, ievent):
    try:
        (nick, cpm) = ievent.args
    except ValueError:
        ievent.missing('<nick> <commands per minute>')
        return
    uh = getwho(bot, nick)
    if not uh:
        ievent.reply("can't find userhost of %s" % nick)
        return
    perms = users.getperms(uh)
    if 'OPER' in perms:
        ievent.reply("can't throttle a OPER")
        return
    try:
        cpm = float(cpm)
        if cpm == 0:
            ievent.reply("cpm can't be zero")
            return
        state['level'][uh] = cpm
        state['cpm'][uh] = 0
        state.save()
    except ValueError:
        ievent.reply('%s is not an integer' % cpm)
        return
    try:
        bot.throttle.remove(uh)
    except ValueError:
        pass
    ievent.reply('cpm set to %s for %s' % (cpm, uh))
Exemple #7
0
def handle_settodo(bot, ievent):
    """ todo-set <name> <txt> .. add a todo to another user's todo list"""
    try:
        who = ievent.args[0]
        what = ' '.join(ievent.args[1:])
    except IndexError:
        ievent.missing('<nick> <what>')
        return
    if not what:
        ievent.missing('<nick> <what>')
        return
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't find userhost for %s" % who)
        return
    whouser = users.getname(userhost)
    if not whouser:
        ievent.reply("can't find user for %s" % userhost)
        return
    name = users.getname(ievent.userhost)
    if not users.permitted(userhost, name, 'todo'):
        ievent.reply("%s doesn't permit todo sharing for %s " % \
(who, name))
        return
    what = "%s: %s" % (ievent.nick, what)
    ttime = strtotime(what)
    nr = 0
    if not ttime == None:
        ievent.reply('time detected ' + time.ctime(ttime))
        what = striptime(what)
        alarmnr = alarms.add(bot.name, who, ttime, what)
        nr = todo.add(whouser, what, ttime, alarmnr=alarmnr)
    else:
        nr = todo.add(whouser, what, 0)
    ievent.reply('todo item %s added' % nr)
Exemple #8
0
def handle_addshop(bot, ievent):
    """ shop-add <username> <item> .. add items to shop list of <username>"""
    if len(ievent.args) < 2:
        ievent.missing('<username> <item>')
        return
    else:
        who = ievent.args[0]
        what = ' '.join(ievent.args[1:])
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't find userhost of %s" % who)
        return
    # get username of use giviing the command
    username = users.getname(ievent.userhost)
    # get username of person we want to knwo the shop list of
    whoname = users.getname(userhost)
    if not whoname:
        ievent.reply("can't find user for %s" % userhost)
        return
    if users.permitted(userhost, username, 'shop'):
        shops[whoname] = what
        shops.save()
        ievent.reply('shop item added')
    else:
        ievent.reply("%s does not share shopping list with %s" % (who, \
username))
Exemple #9
0
def handle_throttleset(bot, ievent):
    try:
        (nick, cpm) = ievent.args
    except ValueError:
        ievent.missing('<nick> <commands per minute>')
        return
    uh = getwho(bot, nick)
    if not uh:
        ievent.reply("can't find userhost of %s" % nick)
        return
    perms = users.getperms(uh)
    if 'OPER' in perms:
        ievent.reply("can't throttle a OPER")
        return
    try:
        cpm = float(cpm)
        if cpm == 0:
            ievent.reply("cpm can't be zero")
            return
        state['level'][uh] = cpm
        state['cpm'][uh] = 0
        state.save()
    except ValueError:
        ievent.reply('%s is not an integer' % cpm)
        return
    try:
        bot.throttle.remove(uh)
    except ValueError:
        pass
    ievent.reply('cpm set to %s for %s' % (cpm, uh))
Exemple #10
0
def handle_to(bot, ievent):
    """ direct pipeline output to <nick> """
    if not ievent.inqueue:
        ievent.reply('use to in a pipeline')
        return
    try:
        nick = ievent.args[0]
    except IndexError:
        ievent.reply('to <nick>')
        return
    if nick == 'me':
        nick = ievent.nick
    if not getwho(bot, nick):
        ievent.reply("don't know %s" % nick)
        return
    result = waitforqueue(ievent.inqueue, 5)
    if result:
        ievent.reply("%s sends you this:" % ievent.nick, nick=nick)
        ievent.reply(result, nick=nick, dot=True)
        if len(result) == 1:
            ievent.reply('1 element sent')
        else:
            ievent.reply('%s elements sent' % len(result))
    else:
        ievent.reply('nothing to send')
Exemple #11
0
def handle_settodo(bot, ievent):
    """ todo-set <name> <txt> .. add a todo to another user's todo list"""
    try:
        who = ievent.args[0]
        what = ' '.join(ievent.args[1:])
    except IndexError:
        ievent.missing('<nick> <what>')
        return
    if not what:
        ievent.missing('<nick> <what>')
        return
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't find userhost for %s" % who)
        return
    whouser = users.getname(userhost)
    if not whouser:
        ievent.reply("can't find user for %s" % userhost)
        return
    name = users.getname(ievent.userhost)
    if not users.permitted(userhost, name, 'todo'):
        ievent.reply("%s doesn't permit todo sharing for %s " % \
(who, name))
        return
    what = "%s: %s" % (ievent.nick, what)
    ttime = strtotime(what)
    nr = 0
    if not ttime  == None:
        ievent.reply('time detected ' + time.ctime(ttime))
        what = striptime(what)
        alarmnr = alarms.add(bot.name, who, ttime, what)
        nr = todo.add(whouser, what, ttime, alarmnr=alarmnr)
    else:
        nr = todo.add(whouser, what, 0)
    ievent.reply('todo item %s added' % nr)
Exemple #12
0
def handle_meet(bot, ievent):
    """ user-meet <nick> .. introduce a new user to the bot """
    try:
        nick = ievent.args[0].lower()
    except IndexError:
        ievent.missing('<nick>')
        return
    if users.exist(nick):
        ievent.reply('there is already a user with username %s' % nick)
        return
    userhost = getwho(bot, nick)
    if not userhost:
        ievent.reply("can't find userhost of %s" % nick)
        return
    username = users.getname(userhost)
    if username:
        ievent.reply('we already have a user with userhost %s (%s)' % \
(userhost, username))
        return
    result = 0
    try:
        result = users.add(nick.lower(), [userhost, ], ['USER', ])
    except Exception, ex:
        ievent.reply('ERROR: %s' % str(ex))
        return
def timebomb(bot, ievent):
    # check if we have ops
    if ievent.channel not in bot.state['opchan']:
        bot.action(
            ievent.channel,
            "bends over and farts in %s's general direction." % ievent.nick)
        return
    # check if we are already running a bomb
    if bomb.data:
        bot.action(ievent.channel,
                   "points at the bulge in %s's pants." % bomb.data[0])
        return
    try:
        userhost = getwho(bot, ievent.args[0])
    except IndexError:
        ievent.reply('timebomb requires victim, see !help timebomb.')
        return
    # check if the victim userhost exists on this channel
    if not userhost:
        ievent.reply('no %s here.' % ievent.args[0])
        return
    else:
        user = ievent.args[0]
    # if bot gets targeted, switch target to caller
    if ievent.args[0].lower() == bot.nick.lower():
        userhost = ievent.ruserhost
        user = ievent.nick
    # define wires
    wires = ['blue', 'black', 'red', 'green', 'purple', 'white', 'silver']
    # determine number of wires and pick random colors
    shuffle(wires)
    mywires = wires[0:randint(2, len(wires) - 1)]
    counter = 18 + 2 * len(mywires) + randint(1, 12)
    # determine time to mark instance
    instancetime = time()
    # plant bomb: (name to kick, which wires to choose from, which wire disarms, userhost)
    bomb.data = [
        user, mywires, mywires[randint(0,
                                       len(mywires) - 1)], userhost,
        instancetime
    ]
    ievent.reply(
        '%s places a bomb in %s\'s pants, the timer reads %s seconds. You see the wires :%s'
        % (ievent.nick, user, counter, str(mywires)))
    # wait for timer to expire
    sleep(counter)

    # check if persist data still exists (no cut event) and kick if so.
    if bomb.data:
        # data from different instance, dont cut
        if not bomb.data[-1] == instancetime:
            return
        else:
            #kick victim
            bot.sendraw('KICK %s %s :%s' %
                        (ievent.channel, bomb.data[0], 'B000000M!'))
            #ievent.reply('user: %s, userhost: %s' % (bomb.data[0], bomb.data[3]))
            bomb.data = []
Exemple #14
0
def handle_throttleget(bot, ievent):
    if not ievent.rest:
        ievent.missing("<nick>")
        return
    nick = ievent.rest
    uh = getwho(bot, nick)
    if not uh:
        ievent.reply("can't find userhost of %s" % nick)
        return
    try:
        ievent.reply("cpm of %s is %s" % (uh, state['level'][uh]))
    except KeyError:
        pass
Exemple #15
0
def handle_throttleget(bot, ievent):
    if not ievent.rest:
        ievent.missing("<nick>")
        return
    nick = ievent.rest
    uh = getwho(bot, nick)
    if not uh:
        ievent.reply("can't find userhost of %s" % nick)
        return
    try:
        ievent.reply("cpm of %s is %s" % (uh, state['level'][uh]))
    except KeyError:
        pass
Exemple #16
0
def handle_throttleremove(bot, ievent):
    if not ievent.rest:
        ievent.missing('<nick>')
        return
    uh = getwho(bot, ievent.rest)
    if not uh:
        ievent.reply("can't find userhost of %s" % ievent.rest)
        return
    try:
        bot.throttle.remove(uh)
        state['cpm'][uh] = 0
        state.save()
        ievent.reply('throttle on %s removed' % uh)
    except (KeyError, ValueError):
        pass
Exemple #17
0
def handle_u(bot, ievent):
    """ u <nick> .. show userhost entry in cache. """

    try:
        nick = ievent.args[0]
    except IndexError:
        ievent.missing('<nick>')
        return

    result = getwho(bot, nick)

    if result:
        ievent.reply(result)
    else:
        ievent.reply("can't get userhost for %s" % nick)
Exemple #18
0
def handle_throttleremove(bot, ievent):
    if not ievent.rest:
        ievent.missing('<nick>')
        return
    uh = getwho(bot, ievent.rest)
    if not uh:
        ievent.reply("can't find userhost of %s" % ievent.rest)
        return
    try:
        bot.throttle.remove(uh)
        state['cpm'][uh] = 0
        state.save()
        ievent.reply('throttle on %s removed' % uh)
    except (KeyError, ValueError):
        pass
Exemple #19
0
def timebomb(bot, ievent):
    # check if we have ops
    if ievent.channel not in bot.state['opchan']:
        bot.action(ievent.channel, "bends over and farts in %s's general direction." % ievent.nick)
        return
    # check if we are already running a bomb
    if bomb.data:
        bot.action(ievent.channel ,"points at the bulge in %s's pants." % bomb.data[0])
        return
    try:
        userhost = getwho(bot, ievent.args[0])
    except IndexError:
        ievent.reply('timebomb requires victim, see !help timebomb.')
        return
    # check if the victim userhost exists on this channel
    if not userhost:
         ievent.reply('no %s here.' % ievent.args[0])
         return
    else:
        user = ievent.args[0]
    # if bot gets targeted, switch target to caller
    if ievent.args[0].lower() == bot.nick.lower():
         userhost = ievent.ruserhost 
         user = ievent.nick
    # define wires 
    wires = ['blue','black','red','green','purple','white','silver'];
    # determine number of wires and pick random colors
    shuffle(wires)
    mywires = wires[0:randint(2,len(wires)-1)]
    counter = 18 + 2 * len(mywires) + randint(1,12)
    # determine time to mark instance
    instancetime = time()
    # plant bomb: (name to kick, which wires to choose from, which wire disarms, userhost)
    bomb.data = [user, mywires, mywires[randint(0,len(mywires)-1)], userhost, instancetime]
    ievent.reply('%s places a bomb in %s\'s pants, the timer reads %s seconds. You see the wires :%s' % (ievent.nick, user, counter, str(mywires)))
    # wait for timer to expire
    sleep(counter)
    
    # check if persist data still exists (no cut event) and kick if so.
    if bomb.data:
        # data from different instance, dont cut
        if not bomb.data[-1] == instancetime:
           return
        else: 
            #kick victim
            bot.sendraw('KICK %s %s :%s' % (ievent.channel, bomb.data[0], 'B000000M!'))
            #ievent.reply('user: %s, userhost: %s' % (bomb.data[0], bomb.data[3]))
            bomb.data = []
Exemple #20
0
def handle_u(bot, ievent):

    """ u <nick> .. show userhost entry in cache. """

    try:
        nick = ievent.args[0]
    except IndexError:
        ievent.missing('<nick>')
        return

    result = getwho(bot, nick)

    if result:
        ievent.reply(result)
    else:
        ievent.reply("can't get userhost for %s" % nick)
Exemple #21
0
def handle_getname(bot, ievent):
    """ user-getname <nick> .. fetch name of nick """
    try:
        nick = ievent.args[0]
    except IndexError:
        ievent.missing("<nick>")
        return
    userhost = getwho(bot, nick)
    if not userhost:
        ievent.reply("can't find userhost of %s" % nick)
        return
    name = users.getname(userhost)
    if not name:
        ievent.reply("can't find user for %s" % userhost)
        return
    ievent.reply(name)
Exemple #22
0
def handle_ban_add(bot, ievent):
    if not ievent.args:
        ievent.missing('<nick>')
        return
    if ievent.args[0].lower() == bot.nick.lower():
        ievent.reply('not going to ban myself')
        return
    userhost = getwho(bot, ievent.args[0])
    if userhost:
        host = userhost.split('@')[-1].lower()
        if host == get_bothost(bot):
            ievent.reply('not going to ban myself')
            return
        bot.sendraw('MODE %s +b *!*@%s' % (ievent.channel, host))
        ievent.reply('banned %s' % (host, ))
    else:
        ievent.reply('can not get userhost of %s' % ievent.args[0])
def handle_ban_add(bot, ievent):
    if not ievent.args:
        ievent.missing('<nick>')
        return
    if ievent.args[0].lower() == bot.nick.lower():
        ievent.reply('not going to ban myself')
        return
    userhost = getwho(bot, ievent.args[0])
    if userhost:
        host = userhost.split('@')[-1].lower()
        if host == get_bothost(bot):
            ievent.reply('not going to ban myself')
            return
        bot.sendraw('MODE %s +b *!*@%s' % (ievent.channel, host))
        ievent.reply('banned %s' % (host, ))
    else:
        ievent.reply('can not get userhost of %s' % ievent.args[0])
Exemple #24
0
def handle_kickban_add(bot, ievent):
    if not ievent.args:
        ievent.missing('<nick> [<reason>]')
        return
    if ievent.args[0].lower() == bot.nick.lower():
        ievent.reply('not going to kickban myself')
        return
    userhost = getwho(bot, ievent.args[0])
    reason = len(ievent.args) > 1 and ' '.join(ievent.args[1:]) or 'Permban requested, bye'
    if userhost:
        host = userhost.split('@')[-1].lower()
        if host == get_bothost(bot):
            ievent.reply('not going to kickban myself')
            return
        bot.sendraw('MODE %s +b *!*@%s' % (ievent.channel, host))
        bot.sendraw('KICK %s %s :%s' % (ievent.channel, ievent.args[0], reason))
    else:
        ievent.reply('can not get userhost of %s' % ievent.args[0])
Exemple #25
0
def handle_delshop(bot, ievent):
    """ shop-del <username> <listofnrs> .. delete items of someone elses \
        shop list """
    if len(ievent.args) < 2:
        ievent.missing('<username> <listofnrs>')
        return
    else:
        who = ievent.args[0]
    try:
        nrs = []
        for i in ievent.args[1:]:
            nrs.append(int(i))
    except ValueError:
        ievent.reply('%s is not an integer' % i)
        return
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't find userhost of %s" % who)
        return
    username = users.getname(ievent.userhost)
    whoname = users.getname(userhost)
    if not whoname:
        ievent.reply("can't find user for %s" % userhost)
        return
    if users.permitted(userhost, username, 'shop'):
        try:
            shop = shops[whoname]
        except KeyError:
            ievent.reply('nothing to shop ;]')
            return
        nrs.sort()
        nrs.reverse()
        for i in range(len(shop)-1, -1 , -1):
            if i in nrs:
                try:
                    del shop[i]
                except IndexError:
                    pass
        shops.save()
        ievent.reply('shop item deleted')
    else:
        ievent.reply("%s does not share shopping list with %s" % (who, \
username))
def handle_ignoredel(bot, ievent):
    """ remove nick from ignore list. """

    try:
        nick = ievent.args[0]
    except IndexError:
        ievent.missing('<nick>')
        return

    userhost = getwho(bot, nick)

    if not userhost:
        ievent.reply("can't get userhost of %s" % nick)
        return

    if delignore(userhost):
        ievent.reply("ignore for %s removed" % nick)
    else:
        ievent.reply("can't remove ignore of %s" % nick)
Exemple #27
0
def handle_delshop(bot, ievent):
    """ shop-del <username> <listofnrs> .. delete items of someone elses \
        shop list """
    if len(ievent.args) < 2:
        ievent.missing('<username> <listofnrs>')
        return
    else:
        who = ievent.args[0]
    try:
        nrs = []
        for i in ievent.args[1:]:
            nrs.append(int(i))
    except ValueError:
        ievent.reply('%s is not an integer' % i)
        return
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't find userhost of %s" % who)
        return
    username = users.getname(ievent.userhost)
    whoname = users.getname(userhost)
    if not whoname:
        ievent.reply("can't find user for %s" % userhost)
        return
    if users.permitted(userhost, username, 'shop'):
        try:
            shop = shops[whoname]
        except KeyError:
            ievent.reply('nothing to shop ;]')
            return
        nrs.sort()
        nrs.reverse()
        for i in range(len(shop) - 1, -1, -1):
            if i in nrs:
                try:
                    del shop[i]
                except IndexError:
                    pass
        shops.save()
        ievent.reply('shop item deleted')
    else:
        ievent.reply("%s does not share shopping list with %s" % (who, \
username))
def handle_kickban_add(bot, ievent):
    if not ievent.args:
        ievent.missing('<nick> [<reason>]')
        return
    if ievent.args[0].lower() == bot.nick.lower():
        ievent.reply('not going to kickban myself')
        return
    userhost = getwho(bot, ievent.args[0])
    reason = len(ievent.args) > 1 and ' '.join(
        ievent.args[1:]) or 'Permban requested, bye'
    if userhost:
        host = userhost.split('@')[-1].lower()
        if host == get_bothost(bot):
            ievent.reply('not going to kickban myself')
            return
        bot.sendraw('MODE %s +b *!*@%s' % (ievent.channel, host))
        bot.sendraw('KICK %s %s :%s' %
                    (ievent.channel, ievent.args[0], reason))
    else:
        ievent.reply('can not get userhost of %s' % ievent.args[0])
Exemple #29
0
def handle_ignoredel(bot, ievent):

    """ remove nick from ignore list. """

    try:
        nick = ievent.args[0]
    except IndexError:
        ievent.missing('<nick>')
        return

    userhost = getwho(bot, nick)

    if not userhost:
        ievent.reply("can't get userhost of %s" % nick)
        return

    if delignore(userhost):
        ievent.reply("ignore for %s removed" % nick)
    else:
        ievent.reply("can't remove ignore of %s" % nick)
Exemple #30
0
def handle_gettodo(bot, ievent):
    """ todo-get <nick> .. get todo of another user """
    try:
        who = ievent.args[0]
    except IndexError:
        ievent.missing('<nick>')
        return
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't find userhost for %s" % who)
        return
    whouser = users.getname(userhost)
    if not whouser:
        ievent.reply("can't find user for %s" % userhost)
        return
    name = users.getname(ievent.userhost)
    if not users.permitted(userhost, name, 'todo'):
        ievent.reply("%s doesn't permit todo sharing for %s " % (who, name))
        return
    todoos = todo.get(whouser)
    saytodo(bot, ievent, todoos)
Exemple #31
0
def handle_remind(bot, ievent):
    """ remind <nick> <txt> .. add a remind """
    try:
        who = ievent.args[0]
        txt = ' '.join(ievent.args[1:])
    except IndexError:
        ievent.missing('<nick> <txt>')
        return
    if not txt:
        ievent.missing('<nick> <txt>')
        return
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't find userhost for %s" % who)
        return
    else:
        if ievent.jabber:
            remind.add(userhost, (who, ievent.userhost, txt, time.time()))
        else:
            remind.add(userhost, (who, ievent.nick, txt, time.time()))
        ievent.reply("remind for %s added" % who)
Exemple #32
0
def handle_gettodo(bot, ievent):
    """ todo-get <nick> .. get todo of another user """
    try:
        who = ievent.args[0]
    except IndexError:
        ievent.missing('<nick>')
        return
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't find userhost for %s" % who)
        return
    whouser = users.getname(userhost)
    if not whouser:
        ievent.reply("can't find user for %s" % userhost)
        return
    name = users.getname(ievent.userhost)
    if not users.permitted(userhost, name, 'todo'):
        ievent.reply("%s doesn't permit todo sharing for %s " % (who, name))
        return
    todoos = todo.get(whouser)
    saytodo(bot, ievent, todoos)
Exemple #33
0
def handle_getshop(bot, ievent):
    """ shop-get <name> .. get items of someone elses shop list """
    if not ievent.rest:
        ievent.missing('<username>')
        return
    who = ievent.rest
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't find userhost of %s" % who)
        return
    username = users.getname(ievent.userhost)
    whoname = users.getname(userhost)
    if not whoname:
        ievent.reply("can't find user for %s" % userhost)
        return
    if users.permitted(userhost, username, 'shop'):
        shop = shops[whoname]
        sayshop(bot, ievent, shop)
    else:
        ievent.reply("%s does not share shopping list with %s" % (who, \
username))
Exemple #34
0
def handle_getshop(bot, ievent):
    """ shop-get <name> .. get items of someone elses shop list """
    if not ievent.rest:
        ievent.missing('<username>')
        return
    who = ievent.rest
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't find userhost of %s" % who)
        return
    username = users.getname(ievent.userhost)
    whoname = users.getname(userhost)
    if not whoname:
        ievent.reply("can't find user for %s" % userhost)
        return
    if users.permitted(userhost, username, 'shop'):
        shop = shops[whoname]
        sayshop(bot, ievent, shop)
    else:
        ievent.reply("%s does not share shopping list with %s" % (who, \
username))
Exemple #35
0
def handle_op1(bot, ievent):
    """ op [<nick>] .. op an user """
    chan = ievent.channel.lower()
    if chan in bot.state['no-op']:
        ievent.reply('opping is disabled in %s' % ievent.channel)
        return
    if chan not in bot.state['opchan']:
        ievent.reply("i'm not op in %s" % ievent.channel)
        return
    try:
        nick = ievent.args[0]
    except IndexError:
        nick = ievent.nick
    userhost = getwho(bot, nick)
    if not userhost:
        userhost = ievent.userhost
    if users.status(userhost, ievent.channel.upper()):
        bot.doop(chan, nick)
    else:
        ievent.reply("%s doesn't have %s status" % (nick, \
ievent.channel.upper()))
def handle_remind(bot, ievent):
    """ remind <nick> <txt> .. add a remind """
    try:
        who = ievent.args[0]
        txt = ' '.join(ievent.args[1:])
    except IndexError:
        ievent.missing('<nick> <txt>')
        return
    if not txt:
        ievent.missing('<nick> <txt>')
        return
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't find userhost for %s" % who)
        return
    else:
        if ievent.jabber:
            remind.add(userhost, (who, ievent.userhost, txt, time.time()))
        else:
            remind.add(userhost, (who, ievent.nick, txt, time.time()))
        ievent.reply("remind for %s added" % who)
Exemple #37
0
def handle_idle(bot, ievent):
    """ idle [<nick>] .. show how idle an channel/user has been """
    try:
        who = ievent.args[0]
    except IndexError:
        handle_idle2(bot, ievent)
        return
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't get userhost of %s" % who)
        return
    try:
        elapsed = elapsedstring(time.time() - idle.data[jsonstring((bot.name, userhost))])
    except KeyError:
        ievent.reply("i haven't seen %s" % who)
        return
    if elapsed:
        ievent.reply("%s is idle for %s" % (who, elapsed))
        return
    else:
        ievent.reply("%s is not idle" % who)
        return   
Exemple #38
0
def handle_check(bot, ievent):
    """ user-check <nick> .. get user data of <nick> """
    try:
        nick = ievent.args[0]
    except IndexError:
        ievent.missing('<nick>')
        return
    userhost = getwho(bot, nick)
    if not userhost:
        ievent.reply("can't find userhost of %s" % nick)
        return
    name = users.getname(userhost)
    if not name:
        ievent.reply("can't find user")
        return
    userhosts = users.getuserhosts(name)
    perms = users.getuserperms(name)
    email = users.getuseremail(name)
    permits = users.getuserpermits(name)
    status = users.getuserstatuses(name)
    ievent.reply('userrecord of %s = userhosts: %s perms: %s email: %s \
permits: %s status: %s' % (name, str(userhosts), str(perms), \
str(email), str(permits), str(status)))
Exemple #39
0
def handle_idle(bot, ievent):
    """ idle [<nick>] .. show how idle an channel/user has been """
    try:
        who = ievent.args[0]
    except IndexError:
        handle_idle2(bot, ievent)
        return
    userhost = getwho(bot, who)
    if not userhost:
        ievent.reply("can't get userhost of %s" % who)
        return
    try:
        elapsed = elapsedstring(time.time() -
                                idle.data[jsonstring((bot.name, userhost))])
    except KeyError:
        ievent.reply("i haven't seen %s" % who)
        return
    if elapsed:
        ievent.reply("%s is idle for %s" % (who, elapsed))
        return
    else:
        ievent.reply("%s is not idle" % who)
        return
def handle_ignore(bot, ievent):
    """ ignore nick for number of seconds. """

    try:
        (nick, nrseconds) = ievent.args
        nrseconds = int(nrseconds)
    except ValueError:
        ievent.missing('<nick> <seconds>')
        return

    userhost = getwho(bot, nick)

    if not userhost:
        ievent.reply("can't get userhost of %s" % nick)
        return

    allowed = users.allowed(userhost, 'OPER', log=False)

    if allowed:
        ievent.reply("can't ignore OPER")
        return

    addignore(userhost, nrseconds)
    ievent.reply("ignoring %s for %s seconds" % (nick, nrseconds))
Exemple #41
0
def get_bothost(bot):
    return getwho(bot, bot.nick).split('@')[-1].lower()
Exemple #42
0
def handle_weather(bot, ievent):
    """ show weather using Google's weather API """
    userhost = ""
    loc = ""
    try:
        nick = ievent.options['--u']
        if nick:
            userhost = getwho(bot, nick)
            if not userhost:
                ievent.reply("can't determine username for %s" % nick)
                return
            else:
                try:
                    name = users.getname(userhost)
                    if not name:
                         ievent.reply("%s is not known with the bot" % nick)
                         return
                    us = UserState(name)
                    loc = us['location']
                except KeyError:
                    ievent.reply("%s doesn't have his location set in \
userstate" % nick)
                    return
    except KeyError:
         pass
    if not loc:
        if ievent.rest:
             loc = ievent.rest
        else:
             ievent.missing('--u <nick> or <location>')
             return
    query = urlencode({'weather':loc})
    weathertxt = geturl('http://www.google.ca/ig/api?%s' % query)
    if 'problem_cause' in weathertxt:
        rlog(10, 'weather', 'ERROR: %s' % weathertxt)
        ievent.reply('an error occured looking up data for %s' % loc)
        return
    resultstr = ""
    if len(weathertxt) > 135:
        gweather = minidom.parseString(weathertxt)
        gweather = gweather.getElementsByTagName('weather')[0]
        if ievent.command == "weather":
            info = gweather.getElementsByTagName('forecast_information')[0]
            if info:
                city = info.getElementsByTagName('city')[0].attributes["data"].value
                zip = info.getElementsByTagName('postal_code')[0].attributes["data"].value
                time = info.getElementsByTagName('current_date_time')[0].attributes["data"].value

                weather = gweather.getElementsByTagName('current_conditions')[0]
                condition = weather.getElementsByTagName('condition')[0].attributes["data"].value
                temp_f = weather.getElementsByTagName('temp_f')[0].attributes["data"].value
                temp_c = weather.getElementsByTagName('temp_c')[0].attributes["data"].value
                humidity = weather.getElementsByTagName('humidity')[0].attributes["data"].value
                wind = weather.getElementsByTagName('wind_condition')[0].attributes["data"].value

                try:
                    wind_km = round(int(wind[-6:-4]) * 1.609344)
                except ValueError:
                    wind_km = ""

                if (not condition == ""):
                    condition = " Oh, and it's " + condition + "."

                resultstr = "As of %s, %s (%s) has a temperature of %sC/%sF with %s. %s (%s km/h).%s" % (time, city, zip, temp_c, temp_f, humidity, wind, wind_km, condition)
        elif ievent.command == "forecast":
            forecasts = gweather.getElementsByTagName('forecast_conditions')
            for forecast in forecasts:
                condition = forecast.getElementsByTagName('condition')[0].attributes["data"].value
                low_f = forecast.getElementsByTagName('low')[0].attributes["data"].value
                high_f = forecast.getElementsByTagName('high')[0].attributes["data"].value
                day = forecast.getElementsByTagName('day_of_week')[0].attributes["data"].value
                low_c = round((int(low_f) - 32) * 5.0 / 9.0)
                high_c = round((int(high_f) - 32) * 5.0 / 9.0)
                resultstr += "[%s: F(%sl/%sh) C(%sl/%sh) %s]" % (day, low_f, high_f, low_c, high_c, condition)
    if not resultstr:
        ievent.reply('%s not found!' % loc)
        return
    else:
        ievent.reply(resultstr)
def get_bothost(bot):
    return getwho(bot, bot.nick).split('@')[-1].lower()