Пример #1
0
def doe_gemiddelde_offlinetijd(channel_, nick_, tu_):
    print("doe_gemiddelde_offlinetijd(" + channel_ + ", " + nick_ + ", " +
          str(tu_) + ")\n")
    # CREATE TABLE offline(channel string, nick string, tijd int)

    # CREATE TEMPORARY TABLE t(tijd int);
    # .import weary_offlinetijd.txt t
    # INSERT INTO offline SELECT "#^Ra^Re_mensen", "weary", tijd FROM t;
    # DROP TABLE t

    chan = channel_.replace('"', '""').lower()
    nick = nick_.replace('"', '""').lower()
    tijd = str(tu_)
    query = 'INSERT INTO offline VALUES("' + chan + '", "' + nick + '", ' + tijd + ')'
    piet.db(query)
    query = 'SELECT ROUND(AVG(tijd)) FROM offline WHERE channel="' + chan + '" and nick="' + nick + '"'
    if (tu_ < 3600):
        query += " AND tijd<3600"
    elif (tu_ < 4 * 3600):
        query += " AND tijd>=3600 AND tijd<4*3600"
    elif (tu_ < 20 * 3600):
        query += " AND tijd>=4*3600 AND tijd<20*3600"
    else:
        query += " AND tijd>=20*3600"
    avg = float(piet.db(query)[1][0])
    return int(avg)
Пример #2
0
def init_tables(channel):
#
# volgens sqlite-handleiding moet IF NOT EXISTS werken
# --> SQL error: near "NOT": syntax error
#
# hmm werkt gewoon hoor..
#
  try:
    piet.db("CREATE TABLE IF NOT EXISTS kookbalans_mutaties (" +
      "tijdstip TIMESTAMP NOT NULL," +
      "muteerder VARCHAR(255) NOT NULL," +
      "koker VARCHAR(255) NOT NULL," +
      "eters VARCHAR(255) NOT NULL," +
      "kosten FLOAT NOT NULL," +
      "commentaar TEXT NULL)")

    piet.db("CREATE TABLE IF NOT EXISTS kookbalans_balans (" +
      "nick VARCHAR(255) PRIMARY KEY NOT NULL," +
      "saldo FLOAT NOT NULL DEFAULT 0)")

    # piet.send(channel, "nieuwe tabellen aangemaakt")
  except:
    pass

  return True
Пример #3
0
def doe_gemiddelde_offlinetijd(channel_, nick_, tu_):
  print("doe_gemiddelde_offlinetijd("+channel_+", "+nick_+", "+str(tu_)+")\n");
  # CREATE TABLE offline(channel string, nick string, tijd int)

  # CREATE TEMPORARY TABLE t(tijd int);
  # .import weary_offlinetijd.txt t
  # INSERT INTO offline SELECT "#^Ra^Re_mensen", "weary", tijd FROM t;
  # DROP TABLE t

  chan=channel_.replace('"', '""').lower();
  nick=nick_.replace('"', '""').lower();
  tijd=str(tu_);
  query='INSERT INTO offline VALUES("'+chan+'", "'+nick+'", '+tijd+')';
  piet.db(query);
  query='SELECT ROUND(AVG(tijd)) FROM offline WHERE channel="'+chan+'" and nick="'+nick+'"';
  if (tu_<3600):
    query+=" AND tijd<3600";
  elif (tu_<4*3600):
    query+=" AND tijd>=3600 AND tijd<4*3600";
  elif (tu_<20*3600):
    query+=" AND tijd>=4*3600 AND tijd<20*3600";
  else:
    query+=" AND tijd>=20*3600";
  avg=float(piet.db(query)[1][0]);
  return int(avg);
Пример #4
0
def checkmessages(channel_):
  global nicks;
  where="WHERE lower(nick) IN ("+','.join(['"'+x.lower()+'"' for x in nicks])+")";
  msgs=piet.db("SELECT nick,msg FROM notes "+where);
  if (msgs!=None and len(msgs)>=2):
    piet.db("DELETE FROM notes "+where);
    msgs=[n+": "+m for n,m in msgs[1:]];
    piet.send(channel_, '\n'.join(msgs));
Пример #5
0
def checkmessages(channel_):
    global nicks
    where = "WHERE lower(nick) IN (" + ','.join(
        ['"' + x.lower() + '"' for x in nicks]) + ")"
    msgs = piet.db("SELECT nick,msg FROM notes " + where)
    if (msgs != None and len(msgs) >= 2):
        piet.db("DELETE FROM notes " + where)
        msgs = [n + ": " + m for n, m in msgs[1:]]
        piet.send(channel_, '\n'.join(msgs))
Пример #6
0
def check_sleep_time(nick_, auth_, channel_, command_, msg_):
    print("check_sleep_time(" + nick_ + ", " + str(auth_) + ", " + channel_ +
          ", " + command_ + ", " + msg_ + ")\n")
    # CREATE TABLE logout(
    #    channel string, nick string, tijd int, reason string,
    #    primary key (channel,nick));

    chan = channel_.replace('"', '""').lower()
    nick = nick_.replace('"', '""').lower()
    if (command_ in ["PART", "QUIT", "KICK"]):
        tijd = str(int(time.time() + 0.5))
        reason = msg_[5:].replace('"', '""')
        query = 'REPLACE INTO logout VALUES("' + chan + '", "' + nick + '", ' + tijd + ', "' + reason + '")'
        piet.db(query)
    elif (command_ in ["JOIN"]):
        try:
            where = 'WHERE channel="' + chan + '" and nick="' + nick + '"'
            dbtijd = piet.db('SELECT tijd FROM logout ' + where)
            piet.db('DELETE FROM logout ' + where)
            if dbtijd and len(dbtijd) >= 2:
                tu = int(time.time() + 0.5) - int(dbtijd[1][0])
            else:
                tu = -1

            titel = random.choice(
                ("heer", "meester", "prins", "gast", "joker", "orgelspeler",
                 "held", "bedwinger", "plaag", "buitenlander", "mastermind",
                 "heerser", "samensteller"))
            subtitel = random.choice(
                ("des duisternis", "van het licht", "des ubers", "des modders",
                 "des oordeels", "van de knaagdieren", "overste", "ongezien",
                 "enzo", "extraordinaire", "(gevallen)", "in rust",
                 "ten strijde", "(onverschrokken)", "van iedereen",
                 "van deze wereld", "in de dop", "(te jong)"))

            reply = "ACTION presenteert: %s, %s %s" % (nick, titel, subtitel)

            nicks_stripped = set(n.strip('_') for n in nicks.keys())
            if nick.strip('_') in nicks_stripped:
                print "user %s was al gejoined, geen groet" % nick
            elif tu > 0:
                reply = reply + ", weer terug na " + pietlib.format_tijdsduur(
                    tu, 2)
                try:
                    gemiddeld = doe_gemiddelde_offlinetijd(channel_, nick_, tu)
                    reply += ", gemiddeld %s nu" % pietlib.format_tijdsduur(
                        gemiddeld, 2)
                except:
                    traceback.print_exc()
                    reply += ", geen gemiddelde"
                piet.send(channel_, reply + ".\n")
            elif tu == 0:
                piet.send(channel_,
                          "blijkbaar is " + nick_ + " aan het fietsen\n")
        except:
            traceback.print_exc()
            piet.send(channel_, "Hee " + nick_ + "!\n")
Пример #7
0
def check_sleep_time(nick_, auth_, channel_, command_, msg_):
  print("check_sleep_time("+nick_+", "+str(auth_)+", "+channel_+", "+command_+", "+msg_+")\n");
  # CREATE TABLE logout(
  #    channel string, nick string, tijd int, reason string,
  #    primary key (channel,nick));

  chan=channel_.replace('"', '""').lower();
  nick=nick_.replace('"', '""').lower();
  if (command_ in ["PART", "QUIT", "KICK"]):
    tijd=str(int(time.time()+0.5));
    reason=msg_[5:].replace('"', '""');
    query='REPLACE INTO logout VALUES("'+chan+'", "'+nick+'", '+tijd+', "'+reason+'")';
    piet.db(query);
  elif (command_ in ["JOIN"]):
    try:
      where='WHERE channel="' + chan + '" and nick="' + nick + '"'
      dbtijd = piet.db('SELECT tijd FROM logout ' + where)
      piet.db('DELETE FROM logout ' + where)
      if dbtijd and len(dbtijd) >= 2:
        tu = int(time.time()+0.5) - int(dbtijd[1][0])
      else:
        tu = -1

      titel=random.choice(("heer", "meester", "prins", "gast", "joker",
        "orgelspeler", "held", "bedwinger", "plaag", "buitenlander", "mastermind",
        "heerser", "samensteller"))
      subtitel=random.choice(("des duisternis", "van het licht", "des ubers",
        "des modders", "des oordeels", "van de knaagdieren", "overste",
        "ongezien", "enzo", "extraordinaire", "(gevallen)",
        "in rust", "ten strijde", "(onverschrokken)", "van iedereen", "van deze wereld",
        "in de dop", "(te jong)"))
        
      reply = "ACTION presenteert: %s, %s %s" % (nick, titel, subtitel)

      nicks_stripped = set(n.strip('_') for n in nicks.keys())
      if nick.strip('_') in nicks_stripped:
        print "user %s was al gejoined, geen groet" % nick
      elif tu>0:
        reply = reply + ", weer terug na " + pietlib.format_tijdsduur(tu, 2)
        try:
          gemiddeld = doe_gemiddelde_offlinetijd(channel_, nick_, tu)
          reply += ", gemiddeld %s nu" % pietlib.format_tijdsduur(gemiddeld, 2)
        except:
          traceback.print_exc()
          reply += ", geen gemiddelde"
        piet.send(channel_, reply+".\n")
      elif tu==0:
        piet.send(channel_, "blijkbaar is "+nick_+" aan het fietsen\n")
    except:
      traceback.print_exc()
      piet.send(channel_, "Hee "+nick_+"!\n")
Пример #8
0
def check_pagina(channel, nick, paginas):
    try:
        paginas = int(paginas)
        nu = int(time.time())
        piet.db("INSERT INTO paginas VALUES(" + str(nu) + ", \"" + nick +
                "\", " + str(paginas) + ");")
        first = piet.db("SELECT tijd,paginas FROM paginas WHERE nick=\"" +
                        nick + "\" ORDER BY tijd LIMIT 1")[1]
        first = [int(a) for a in first]
        prev = int(
            piet.db("SELECT paginas FROM paginas WHERE nick=\"" + nick +
                    "\" ORDER BY tijd DESC LIMIT 2")[2][0])

        # sinds vorige keer
        mutatie = paginas - prev
        r = ""
        if mutatie > 1:
            r = "dat zijn er weer " + str(mutatie)
        elif mutatie > 0:
            r = "weer eentje dus"
        elif mutatie < -1:
            r = "hee, dat zijn er " + str(-mutatie) + " minder"
        elif mutatie < 0:
            r = "pagina'tje minder, altijd goed"
        else:
            r = "echt opschieten doet't niet"

        # sinds begin
        dpag = paginas - int(first[1])
        dtijd = nu - int(first[0])
        d = float(dpag) / dtijd
        d = d * 60
        eenheid = "minuut"
        if abs(d) < 0.5:
            d = d * (24 * 60)
            eenheid = "dag"
        if abs(d) < 0.5:
            d = d * 7
            eenheid = "week"
        if abs(d) < 0.5:
            d = d * 52
            eenheid = "jaar"
        d = round(d, 2)

        r = r + " (ongeveer " + str(d) + " per " + eenheid + ")"
        piet.send(channel, r)
    except:
        traceback.print_exc()
Пример #9
0
def check_names(nick_, channel_, msg_):
  global nicks
  print("check_names("+nick_+", "+channel_+", "+msg_+")\n")
  msg_nicks=msg_[msg_.find(':')+1:].split(' ')
  nicks={}
  for x in msg_nicks:
    if (x[0]=='@'):
      nicks[x[1:]]=True
    else:
      nicks[x]=False
  pietnick=piet.nick()
  if nicks[pietnick]: # piet heeft ops
    noop = [k for (k,v) in nicks.iteritems() if not v]
    op_basenames = set(k.strip('_') for k,v in nicks.iteritems() if v)
    if noop:
      qry = ("SELECT name FROM auth WHERE auth>=500 AND name IN (" +
           ','.join(['"'+x+'"' for x in noop])+")")
      dbres=piet.db(qry)
      if dbres and len(dbres)>=2:
        authusers = [x[0] for x in dbres[1:]]
        newnicks = set(n for n in authusers if n.strip('_') not in op_basenames) # only print message if user not already joined
        if len(newnicks) == 1:
          piet.send(channel_, "hup, een apenstaart voor "+list(newnicks)[0]+"\n")
        elif len(newnicks) > 1:
          piet.send(channel_, "ho, hier moet even wat gefixed worden.\n")
        piet.op(channel_, authusers)
  else: # piet niet operator
    ops=[x for (x,o) in nicks.iteritems() if o]
    if ops:
      myop=random.choice(ops)
      msg=random.choice(["mag ik een @?", "toe, doe eens een @?",
          "ik wil graag je operatortje zijn, mag ik?",
          "kijk, ik heb geen @. fix's?", "een @, ah toe?"])
      piet.send(channel_, myop+": "+msg+"\n")
  checkmessages(channel_)
Пример #10
0
def tijdzone_nick(naam):
  inp = piet.db('SELECT timezone FROM auth where name="'+naam+'"');
  if (not(inp) or len(inp)<=1):
    tzone = LOCALTIMEZONE;
  else:
    tzone = inp[1][0];
  return tzone;
Пример #11
0
def check_netsplit(nick_, channel_, command_, msg_):
  # CREATE TABLE netsplit(channel string,nick string, servers string, timeout int, PRIMARY KEY(channel,nick));

  NETSPLIT_TIMEOUT=3600; # seconds
  if (command_ in ["QUIT"]):
    if quitmsg_is_split(msg_):
      chan=channel_.replace('"', '""').lower();
      nick=nick_.replace('"', '""').lower();
      servers=msg_[6:].replace('"', '""');
      tijd=str(int(time.time()+0.5)+NETSPLIT_TIMEOUT);
      query='REPLACE INTO netsplit VALUES("'+chan+'", "'+nick+'", "'+servers+'", '+tijd+')';
      piet.db(query);
      return True;
  elif (command_ in ["JOIN"]):
    chan=channel_.replace('"', '""').lower();
    nick=nick_.replace('"', '""').lower();
    tijd=int(time.time()+0.5);
    where='WHERE channel="'+chan+'" AND nick="'+nick+'" AND timeout>'+str(tijd);
    query='SELECT servers FROM netsplit '+where;

    ns=piet.db(query);
    if (not(ns)): return False;
    servers=ns[1][0];
    piet.db('DELETE FROM netsplit '+where);

    # others from same netsplit should return now within 30s -> restrict timeout
    query='REPLACE INTO netsplit ';
    query+='SELECT channel,nick,servers,MIN(timeout,'+str(tijd+30)+') '
    query+='FROM netsplit WHERE servers="'+servers+'"';
    piet.db(query);
    return True;

  return False;
Пример #12
0
def check_pagina(channel, nick, paginas):
  try:
    paginas=int(paginas);
    nu=int(time.time());
    piet.db("INSERT INTO paginas VALUES("+str(nu)+", \""+nick+"\", "+str(paginas)+");");
    first=piet.db("SELECT tijd,paginas FROM paginas WHERE nick=\""+nick+"\" ORDER BY tijd LIMIT 1")[1];
    first=[int(a) for a in first]
    prev=int(piet.db("SELECT paginas FROM paginas WHERE nick=\""+nick+"\" ORDER BY tijd DESC LIMIT 2")[2][0]);

    # sinds vorige keer
    mutatie=paginas-prev;
    r="";
    if mutatie>1:
        r="dat zijn er weer "+str(mutatie);
    elif mutatie>0:
        r="weer eentje dus";
    elif mutatie<-1:
        r="hee, dat zijn er "+str(-mutatie)+" minder"
    elif mutatie<0:
        r="pagina'tje minder, altijd goed"
    else:
        r="echt opschieten doet't niet"
    
    # sinds begin
    dpag=paginas-int(first[1]);
    dtijd=nu-int(first[0]);
    d=float(dpag)/dtijd;
    d=d*60; eenheid="minuut";
    if abs(d)<0.5:
        d=d*(24*60);
        eenheid="dag";
    if abs(d)<0.5:
        d=d*7;
        eenheid="week";
    if abs(d)<0.5:
        d=d*52;
        eenheid="jaar";
    d=round(d,2);
    
    r=r+" (ongeveer "+str(d)+" per "+eenheid+")";
    piet.send(channel, r)
  except:
    traceback.print_exc();
Пример #13
0
def mutatie_inverteren(afzender):
  q_last = "FROM kookbalans_mutaties WHERE muteerder = '%s' ORDER BY tijdstip DESC LIMIT 1" % afzender.replace("'","''")

  try:
    q_results = piet.db("SELECT koker,eters,kosten " + q_last);

  except:
    return format_exception("probleem met database")

  if q_results == None or len(q_results) < 2:
    return "geen laatste log entry gevonden"

  kokert = q_results[1][0]
  eters = q_results[1][1].strip().split(" ")
  kosten = float(q_results[1][2])
  kooktimestamp = strftime("%Y-%m-%d %H:%M:%S")
  
  return mutatie(afzender, kokert, eters, -kosten, "undo", kooktimestamp)
Пример #14
0
def check_names(nick_, channel_, msg_):
    global nicks
    print("check_names(" + nick_ + ", " + channel_ + ", " + msg_ + ")\n")
    msg_nicks = msg_[msg_.find(':') + 1:].split(' ')
    nicks = {}
    for x in msg_nicks:
        if (x[0] == '@'):
            nicks[x[1:]] = True
        else:
            nicks[x] = False
    pietnick = piet.nick()
    if nicks[pietnick]:  # piet heeft ops
        noop = [k for (k, v) in nicks.iteritems() if not v]
        op_basenames = set(k.strip('_') for k, v in nicks.iteritems() if v)
        if noop:
            qry = ("SELECT name FROM auth WHERE auth>=500 AND name IN (" +
                   ','.join(['"' + x + '"' for x in noop]) + ")")
            dbres = piet.db(qry)
            if dbres and len(dbres) >= 2:
                authusers = [x[0] for x in dbres[1:]]
                newnicks = set(
                    n for n in authusers if n.strip('_') not in op_basenames
                )  # only print message if user not already joined
                if len(newnicks) == 1:
                    piet.send(
                        channel_,
                        "hup, een apenstaart voor " + list(newnicks)[0] + "\n")
                elif len(newnicks) > 1:
                    piet.send(channel_,
                              "ho, hier moet even wat gefixed worden.\n")
                piet.op(channel_, authusers)
    else:  # piet niet operator
        ops = [x for (x, o) in nicks.iteritems() if o]
        if ops:
            myop = random.choice(ops)
            msg = random.choice([
                "mag ik een @?", "toe, doe eens een @?",
                "ik wil graag je operatortje zijn, mag ik?",
                "kijk, ik heb geen @. fix's?", "een @, ah toe?"
            ])
            piet.send(channel_, myop + ": " + msg + "\n")
    checkmessages(channel_)
Пример #15
0
def nickchange(nick_, auth_, channel_, newnick):
    global nicks
    print("nickchange(" + nick_ + ", " + str(auth_) + ", " + channel_ + ", " +
          newnick + "):\n")
    if (newnick[0] == ':'): newnick = newnick[1:]
    if (nick_ == piet.nick()):
        piet.nick(newnick)
        piet.send(
            channel_, "wat een prutnaam, dat " + nick_ +
            ", ik heet veel liever " + newnick + "\n")
    else:
        try:
            otherauth = piet.db(
                "SELECT name,auth,timezone FROM auth where name=\"" + newnick +
                "\"")[1]
        except:
            otherauth = [newnick, -5, pietlib.LOCALTIMEZONE]

        try:
            auth = piet.db(
                "SELECT name,auth,timezone FROM auth where name=\"" + nick_ +
                "\"")[1]
        except:
            auth = [nick_, -5, pietlib.LOCALTIMEZONE]

        print("nickswap: " + repr(auth) + " en " + repr(otherauth) + "\n")
        piet.db("REPLACE INTO auth VALUES(\"" + auth[0] + "\", " +
                str(otherauth[1]) + ", \"" + otherauth[2] + "\")")
        piet.db("REPLACE INTO auth VALUES(\"" + otherauth[0] + "\", " +
                str(auth[1]) + ", \"" + auth[2] + "\")")

        if (auth[1] > otherauth[1]):
            piet.send(channel_, "authenticatie "+str(auth[1])+" nu naar "+newnick+" overgezet, "+\
                nick_+" heeft 't niet meer nodig lijkt me\n")
        elif auth[1] == otherauth[1] and auth[1] > 0:
            if nick.strip('_') != nick:
                piet.send(
                    channel_, "authenticatie van " + str(nick_) + " en " +
                    newnick + " zijn gelijk, niks veranderd\n")
        elif (auth[1] < otherauth[1] and auth[1] > 0):
            piet.send(
                channel_,
                "authenticatie " + str(auth[1]) + " nu naar " + newnick +
                " overgezet, niet nickchangen om hogere auth te krijgen\n")

    if nicks.has_key(nick_):
        nicks[newnick] = nicks[nick_]
        del nicks[nick_]
    check_names_delayed(channel_)
Пример #16
0
def print_kookgeschiedenis(channel, nrecords):
  try:
    records = piet.db("SELECT tijdstip,koker,eters,kosten,commentaar FROM kookbalans_mutaties ORDER BY tijdstip DESC LIMIT %d" % nrecords)

  except:
    return format_exception("probleem met database")

  if records == None or len(records) < 2:
    return "geen informatie"

  del records[0]

  for rec in records:
    tijdstip = rec[0]
    koker = rec[1]
    eters = rec[2].strip().split(" ")
    kosten = float(rec[3])
    commentaar = rec[4]

    piet.send(channel, "%s: %s" % (tijdstip, kookmelding(koker, eters, kosten, commentaar)))

  return ""
Пример #17
0
def cmd_kookbalans(channel, nick, auth, params):
  if not init_tables(channel):
    return "ACTION kan geen tabellen aanmaken"

  saldos = None

  try:
    saldos = piet.db("SELECT nick, saldo, COUNT(*) from kookbalans_mutaties LEFT JOIN kookbalans_balans ON kookbalans_mutaties.koker = kookbalans_balans.nick GROUP BY nick ORDER BY saldo")

  except:
    return format_exception("probleem met database")

  if saldos == None:
    return "geen informatie"

  # delete column headers
  del saldos[0]

  zegdit = []
  for saldo in saldos:
    zegdit.append("het saldo van %s is %.2f (uit %d keer koken)" % (saldo[0], float(saldo[1]), int(saldo[2])))

  return '\n'.join(zegdit)
Пример #18
0
def check_netsplit(nick_, channel_, command_, msg_):
    # CREATE TABLE netsplit(channel string,nick string, servers string, timeout int, PRIMARY KEY(channel,nick));

    NETSPLIT_TIMEOUT = 3600
    # seconds
    if (command_ in ["QUIT"]):
        if quitmsg_is_split(msg_):
            chan = channel_.replace('"', '""').lower()
            nick = nick_.replace('"', '""').lower()
            servers = msg_[6:].replace('"', '""')
            tijd = str(int(time.time() + 0.5) + NETSPLIT_TIMEOUT)
            query = 'REPLACE INTO netsplit VALUES("' + chan + '", "' + nick + '", "' + servers + '", ' + tijd + ')'
            piet.db(query)
            return True
    elif (command_ in ["JOIN"]):
        chan = channel_.replace('"', '""').lower()
        nick = nick_.replace('"', '""').lower()
        tijd = int(time.time() + 0.5)
        where = 'WHERE channel="' + chan + '" AND nick="' + nick + '" AND timeout>' + str(
            tijd)
        query = 'SELECT servers FROM netsplit ' + where

        ns = piet.db(query)
        if (not (ns)): return False
        servers = ns[1][0]
        piet.db('DELETE FROM netsplit ' + where)

        # others from same netsplit should return now within 30s -> restrict timeout
        query = 'REPLACE INTO netsplit '
        query += 'SELECT channel,nick,servers,MIN(timeout,' + str(tijd +
                                                                  30) + ') '
        query += 'FROM netsplit WHERE servers="' + servers + '"'
        piet.db(query)
        return True

    return False
Пример #19
0
def balans_bijwerken(kokert, eters, kosten):
  try:
    for eter in eters:
      piet.db("INSERT OR IGNORE INTO kookbalans_balans(nick) VALUES('%s')" % eter.replace("'","''"))

  except:
    return format_exception("probleem met het toevoegen van eters")

  q_mutatie = "UPDATE kookbalans_balans SET saldo = saldo + %f WHERE nick = '%s'"

  try:
    piet.db(q_mutatie % (kosten, kokert.replace("'","''")))
  except:
    return format_exception("probleem met saldo update van kok")

  try:
    for eter in eters:
      piet.db(q_mutatie % (-kosten/len(eters), eter.replace("'","''")))

  except:
    return format_exception("probleem met saldo update van eters")

  return None
Пример #20
0
def nickchange(nick_, auth_, channel_, newnick):
  global nicks;
  print("nickchange("+nick_+", "+str(auth_)+", "+channel_+", "+newnick+"):\n");
  if (newnick[0]==':'): newnick=newnick[1:];
  if (nick_==piet.nick()):
    piet.nick(newnick);
    piet.send(channel_, "wat een prutnaam, dat "+nick_+", ik heet veel liever "+newnick+"\n");
  else:
    try:
      otherauth=piet.db("SELECT name,auth,timezone FROM auth where name=\""+newnick+"\"")[1];
    except:
      otherauth=[newnick, -5, pietlib.LOCALTIMEZONE];

    try:
      auth=piet.db("SELECT name,auth,timezone FROM auth where name=\""+nick_+"\"")[1];
    except:
      auth=[nick_, -5, pietlib.LOCALTIMEZONE];

    print("nickswap: "+repr(auth)+" en "+repr(otherauth)+"\n");
    piet.db("REPLACE INTO auth VALUES(\""+auth[0]+"\", "+str(otherauth[1])+", \""+otherauth[2]+"\")");
    piet.db("REPLACE INTO auth VALUES(\""+otherauth[0]+"\", "+str(auth[1])+", \""+auth[2]+"\")");

    if (auth[1]>otherauth[1]):
      piet.send(channel_, "authenticatie "+str(auth[1])+" nu naar "+newnick+" overgezet, "+\
          nick_+" heeft 't niet meer nodig lijkt me\n")
    elif auth[1] == otherauth[1] and auth[1]>0:
      if nick.strip('_') != nick:
        piet.send(channel_, "authenticatie van "+str(nick_)+" en "+newnick+ " zijn gelijk, niks veranderd\n")
    elif (auth[1]<otherauth[1] and auth[1]>0):
      piet.send(channel_, "authenticatie "+str(auth[1])+" nu naar "+newnick+
          " overgezet, niet nickchangen om hogere auth te krijgen\n")
  
  if nicks.has_key(nick_):
    nicks[newnick]=nicks[nick_];
    del nicks[nick_];
  check_names_delayed(channel_);
Пример #21
0
def mutatie(afzender, kokert, eters, kosten, commentaar, kooktimestamp):
  try:
    for eter in eters:
      result = piet.db("SELECT COUNT(*) FROM auth WHERE name = '%s'" % eter.replace("'","''"))
      if int(result[1][0]) == 0:
        result = piet.db("SELECT COUNT(*) FROM kookbalans_balans WHERE nick = '%s'" % eter.replace("'","''"))
      if int(result[1][0]) == 0:
        return "%s ken ik niet" % eter

  except:
    return format_exception("probleem met de database")

  # q_log = "INSERT INTO kookbalans_mutaties(tijdstip,muteerder,koker,eters,kosten,commentaar) VALUES (datetime('now'), '%s', '%s', ' %s ', %f, '%s')"
  q_log = "INSERT INTO kookbalans_mutaties(tijdstip,muteerder,koker,eters,kosten,commentaar) VALUES ('%s', '%s', '%s', ' %s ', %f, '%s')"
  
  try:
    piet.db("BEGIN")

    piet.db(q_log % (kooktimestamp.replace("'","''"),
      afzender.replace("'","''"),
      kokert.replace("'","''"),
      ' '.join(eters).replace("'","''"),
      kosten,
      commentaar.replace("'","''")))

  except:
    try:
      piet.db("ROLLBACK")
    except:
      pass
    return format_exception("ACTION kan geen log entry toevoegen")

  err = balans_bijwerken(kokert,eters,kosten)
  if err != None:
    try:
      piet.db("ROLLBACK")
    except:
      pass
    return err

  try:
    piet.db("COMMIT")
  except:
    return format_exception("ACTION kan de database niet wijzigen")

  return kookmelding(kokert, eters, kosten, commentaar)