Пример #1
0
def handle_merge(bot, ievent):
    """ arguments: <name> <nick> - merge the userhost belonging to <nick> into an already existing user. """
    if len(ievent.args) != 2:
        ievent.missing('<name> <nick>')
        return
    name, nick = ievent.args
    name = name.lower()
    if bot.users.gotperm(name, 'OPER') and not bot.users.allowed(ievent.userhost, 'OPER'):
        ievent.reply("only OPER perm can merge with OPER user")
        return
    if name == 'owner' and not bot.ownercheck(ievent.userhost):
         ievent.reply("you are not the owner")
         return 
    if not bot.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
    if bot.ownercheck(userhost):
        ievent.reply("can't merge with owner")
        return
    result = bot.users.merge(name, userhost)
    if result: ievent.reply('%s merged' % nick)
    else: ievent.reply('merge failed')
Пример #2
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 = getusers().getname(userhost)
    if not whouser: ievent.reply("can't find user for %s" % userhost) ; return
    name = getusers().getname(ievent.userhost)
    if not getusers().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)
        karma = plugs.get("tl.plugs.db.karma2")
        if karma: alarmnr = alarms.add(bot.name, who, ttime, what)
        else: alarmnr = None
        nr = todo.add(whouser, what, ttime, alarmnr)
    else: nr = todo.add(whouser, what, None)
    ievent.reply('todo item %s added' % nr)
Пример #3
0
def handle_unignore(bot, event):
    """ arguments: <nick>|<userhost>|<JID> - unignore a user. """
    if not event.rest: event.missing("<nick>|<userhost>|<JID>") ; return
    nick = event.rest
    userhost = getwho(bot, nick)
    if not userhost: userhost = event.rest
    if userhost in bot.ignore: bot.ignore.remove(userhost) ; event.reply("%s removed from ignore list" % userhost)
    else: event.reply("%s is not in ignore list" % event.rest)
Пример #4
0
def handle_ignore(bot, event):
    """ arguments: <nick>|<userhost>|<JID> - ignore a user. """
    if not event.rest: event.missing("<nick>|<userhost>|<JID>") ; return
    nick = event.rest
    userhost = getwho(bot, nick)
    if not userhost: userhost = event.rest
    perms = getusers().getperms(userhost)
    if perms and "OPER" in perms: event.reply("can't ignore OPER") ; return
    if not userhost in bot.ignore: bot.ignore.append(userhost)
    event.reply("%s added to ignore list" % userhost)
Пример #5
0
def handle_remind(bot, ievent):
    """ arguments: <nick> <txt>  - add a remind for a user, as soon as he/she gets online or says something the txt will be send. """
    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:
        remind.add(userhost, [who, ievent.nick, txt, time.time()])
        ievent.reply("remind for %s added" % who)
Пример #6
0
def handle_permdel(bot, ievent):
    if not ievent.chan: ievent.reply("channel is not set in event") ; return
    try: nick = ievent.args[0]
    except IndexError: nick = ievent.nick
    userhost = getwho(bot, nick)
    if not userhost: userhost = ievent.userhost
    if userhost in ievent.chan.data.ops:
        ievent.chan.data.ops.remove(userhost)
        ievent.chan.save()
        ievent.reply("removed %s from the permenent ops list" % userhost)
    else: ievent.reply("%s is not in permops list" % userhost)
Пример #7
0
def handle_permadd(bot, ievent):
    if not ievent.chan: ievent.reply("channel is not set in event") ; return
    try: nick = ievent.args[0]
    except IndexError: nick = ievent.nick
    userhost = getwho(bot, nick)
    if not userhost: userhost = ievent.userhost
    if not userhost in ievent.chan.data.ops:
        ievent.chan.data.ops.append(userhost)
        ievent.chan.save()
        ievent.reply("added %s to the permenent ops list" % userhost)
    else: ievent.reply("%s is already in permops list" % userhost)
Пример #8
0
def handle_op1(bot, ievent):
    """ op [<nick>] .. op an user """
    chan = ievent.channel.lower()
    #if bot.state.has_key('no-op') and chan in bot.state['no-op']:
    #    ievent.reply('opping is disabled 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 (ievent.user and 'OPER' in ievent.user.data.perms) or (ievent.chan and userhost in ievent.chan.data.ops): bot.doop(chan, nick)
    ievent.done()
Пример #9
0
def handle_fish(bot, event):
  """ Handles the fish command """
  args = event.rest.rsplit(" ")
  if not args[0]: event.missing("<commands> [options,...]") ; return

  command = args[0]
  if command == 'help':
    event.reply("help                      -- shows this text")
    event.reply("keyx <nick>               -- Exchanges key")
    event.reply("key  <user|channel> <key> -- Set the key")
    event.reply("del  <user|channel>       -- Removes the key")
    return False

  if command == 'keyx':
    if len(args) != 2: event.missing("keyx <nick>"); return

    userhost = getwho(bot, args[1])
    if userhost == None: return

    user = users.getuser(userhost)
    if user == None:
        event.reply("Unable to exchange key with an unknown user")
        return 

    target = user.data.name
    if target == None: return

    logging.warn("FiSH: Key exchange with  %s (%s)" % (args[1], target))
    dh = DH1080Ctx()
    bot.notice(args[1], dh1080_pack(dh))

    key = KeyStore(stripname(target))
    key.data.dh = pickle.dumps(dh)
    key.save()
    
  if command == 'key':
    if len(args) != 3: event.missing("key <user|channel> <key>"); return
    key = KeyStore(stripname(args[1]))
    key.data.key = args[2]
    key.save()
    event.reply("Stored key for %s" % args[1])

  if command == 'del':
    if len(args) != 2: event.missing("del <user|channel>"); return
    key = KeyStore(stripname(args[1]))

    if not key.data.key: 
      event.reply("No key found for %s" % args[1]); return

    key.data.key=""
    key.data.dh=""
    key.save()
    event.reply("Deleted key %s" % args[1])
Пример #10
0
def handle_to(bot, ievent):
    """ arguments: <nick> - direct output to <nick>, use this command in a pipeline. """
    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
    if not ievent.inqueue: time.sleep(1)
    if ievent.inqueue:
        bot.say(nick, "%s sends you this:" % ievent.nick)
        bot.say(nick, " ".join(ievent.inqueue))
        if len(ievent.inqueue) == 1: ievent.reply('1 element sent')
        else: ievent.reply('%s elements sent' % len(ievent.inqueue))
    else: ievent.reply('nothing to send')
Пример #11
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
    users = getusers()
    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)
Пример #12
0
def handle_ban_add(bot, ievent):
    """ arguments: <nick> - add a ban. """
    if not ievent.args: ievent.missing('<nick>') ; return
    if bot.cfg.nick and ievent.args[0].lower() == bot.cfg.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])
Пример #13
0
def handle_kickban_add(bot, ievent):
    """ arguments: <nick> [<reason>] - add a kickban. """
    if not ievent.args: ievent.missing('<nick> [<reason>]') ; return
    if bot.cfg.nick and ievent.args[0].lower() == bot.cfg.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])
Пример #14
0
def handle_bd(bot, ievent):
    """ bd [<nr|user>] .. show birthday of month or user """
    global db
    if not db: ievent.reply("plugin isnt initialised yet") ; return
    if not ievent.rest: handle_checkbd(bot, ievent) ; return
    try: int(ievent.args[0]) ; handle_checkbd2(bot, ievent) ; return
    except (IndexError, ValueError):
        try: userhost = who = ievent.args[0].lower()
        except IndexError: userhost = who = ievent.userhost
    if not who: who = userhost = getwho(bot, who)
    if not who: ievent.reply("don't know userhost of %s" % who) ; return
    name = bot.users.getname(userhost)
    if not name: ievent.reply("can't find user for %s" % userhost) ; return
    result = db.execute(""" SELECT birthday FROM birthday WHERE name = %s """, name)
    try: birthday = result[0][0]
    except TypeError: ievent.reply("i don't have birthday data for %s" % who) ; return
    ievent.reply('birthday of %s is %s' % (who, birthday))
Пример #15
0
def handle_age(bot, ievent):
    """ age <nick> .. show age of user """
    global db
    if not db: ievent.reply("plugin isnt initialised yet") ; return
    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 = bot.users.getname(userhost)
    if not name: ievent.reply("can't find user for %s" % userhost) ; return
    birthday = db.execute(""" SELECT birthday FROM birthday WHERE name = %s """, name)
    try: birthday = birthday[0][0]
    except TypeError: 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)))
Пример #16
0
def handle_getname(bot, ievent):
    """ arguments: <nick> - fetch username 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 = bot.users.getname(userhost)
    if not name:
        ievent.reply("can't find user for %s" % userhost)
        return

    ievent.reply(name)
Пример #17
0
def handle_check(bot, ievent):
    """ arguments: <nick> - get data of a user based on nick name. """
    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 = bot.users.getname(userhost)
    if not name:
        ievent.reply("can't find user")
        return
    userhosts = bot.users.getuserhosts(name)
    perms = bot.users.getuserperms(name)
    email = bot.users.getuseremail(name)
    permits = bot.users.getuserpermits(name)
    status = bot.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)))
Пример #18
0
def handle_idle(bot, ievent):
    """ arguments: [<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
    logging.warn("idle - userhost is %s" % userhost)
    try:
        elapsed = elapsedstring(time.time() - idle.data[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   
Пример #19
0
def handle_meet(bot, ievent):
    """ arguments: <nick> - introduce a new user to the bot. """
    try: nick = ievent.args[0]
    except IndexError: 
        ievent.missing('<nick>')
        return
    if bot.users.exist(nick):
        ievent.reply('there is already a user with username %s' % nick)
        return
    userhost = getwho(bot, nick)
    logging.warn("users - meet - userhost is %s" % userhost)
    if not userhost:
        ievent.reply("can't find userhost of %s" % nick)
        return
    username = bot.users.getname(userhost)
    if username:
        ievent.reply('we already have a user with userhost %s (%s)' % (userhost, username))
        return
    result = 0
    name = stripname(nick.lower())
    result = bot.users.add(name, [userhost, ], ['USER', 'GUEST'])
    if result: ievent.reply('%s - %s - (%s) added to user database' % (nick, userhost, name))
    else: ievent.reply('add failed')
Пример #20
0
def handle_adminfloodcontrol(bot, event):
    """ no arguments - disable debug on a channel. """
    try:
        who, threshold = event.args
        threshold = int(threshold) 
    except ValueError: event.missing("<userhost> <threshold> [period] [wait]") ; return
    userhost = getwho(bot, who)
    if userhost: user = bot.users.getuser(userhost)
    else: user = bot.users.byname(who)
    if not user: event.reply("i don't know a user %s" % who) ; return
    if "OPER" in user.data.perms: event.reply("no flood control for OPER") ; return
    try: period = event.args[2]
    except IndexError: period = 60
    try: wait = event.args[3]
    except IndexError: wait = 120
    if threshold < 1: threshold = 1
    user.data.floodtime = period
    user.data.floodthreshold = threshold
    user.data.floodwait = wait
    user.data.floodrate = 1
    user.save()
    from tl.lib.floodcontrol import floodcontrol
    for u in user.data.userhosts: floodcontrol.reset(u)
    event.reply("floodrate for %s set to %s" % (user.data.name, threshold))
Пример #21
0
def handle_weather(bot, ievent):
    """ show weather using Google's weather API """
    userhost = ""
    loc = ""
    try:
        nick = ievent.rest
        if nick:
            userhost = getwho(bot, nick)
            if not userhost: pass
            else:
                try:
                    name = bot.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('<nick>|<location>') ; return
    query = urlencode({'weather':loc})
    try: weathertxt = geturl2('http://www.google.ca/ig/api?%s' % query)
    except urllib.error.HTTPError as ex: ievent.reply(str(ex)) ; return
    if 'problem_cause' in bytes(weathertxt, "utf-8"):
        logging.error(weathertxt)
        ievent.reply('an error occured looking up data for %s' % loc)
        return
    logging.debug("weather - got reply: %s" % weathertxt)
    resultstr = ""
    if weathertxt:
        gweather = minidom.parseString(weathertxt)
        gweather = gweather.getElementsByTagName('weather')[0]
        if ievent.usercmnd == "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
                try: wind = weather.getElementsByTagName('wind_condition')[0].attributes["data"].value
                except IndexError: wind = ""
                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.usercmnd == "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)
Пример #22
0
def get_bothost(bot):
    return getwho(bot, bot.cfg.nick).split('@')[-1].lower()