示例#1
0
def add_site(url, nick, channel, server, diffType="diff"):
    """Add a site to watching list

    Argument:
    url -- URL to watch
    """

    o = urlparse(getNormalizedURL(url), "http")
    if o.netloc == "":
        raise IMException("sorry, I can't watch this URL :(")

    alert = ModuleState("alert")
    alert["nick"] = nick
    alert["server"] = server
    alert["channel"] = channel
    alert["message"] = "{url} just changed!"

    if url not in DATAS.index:
        watch = ModuleState("watch")
        watch["type"] = diffType
        watch["url"] = url
        watch["time"] = 123
        DATAS.addChild(watch)
        watch.addChild(alert)
        start_watching(watch)
    else:
        DATAS.index[url].addChild(alert)

    save()
    return Response(channel=channel, nick=nick,
                    message="this site is now under my supervision.")
示例#2
0
文件: birthday.py 项目: nbr23/nemubot
def parseask(msg):
    res = re.match(r"^(\S+)\s*('s|suis|est|is|was|were)?\s+(birthday|geburtstag|née? |nee? le|born on).*$", msg.message, re.I)
    if res is not None:
        try:
            extDate = extractDate(msg.message)
            if extDate is None or extDate.year > datetime.now().year:
                return Response("la date de naissance ne paraît pas valide...",
                                msg.channel,
                                msg.frm)
            else:
                nick = res.group(1)
                if nick == "my" or nick == "I" or nick == "i" or nick == "je" or nick == "mon" or nick == "ma":
                    nick = msg.frm
                if nick.lower() in context.data.index:
                    context.data.index[nick.lower()]["born"] = extDate
                else:
                    ms = ModuleState("birthday")
                    ms.setAttribute("name", nick.lower())
                    ms.setAttribute("born", extDate)
                    context.data.addChild(ms)
                context.save()
                return Response("ok, c'est noté, %s est né le %s"
                                % (nick, extDate.strftime("%A %d %B %Y à %H:%M")),
                                msg.channel,
                                msg.frm)
        except:
            raise IMException("la date de naissance ne paraît pas valide.")
示例#3
0
def load(context):
    """Load this module"""
    if not context.data.hasNode("aliases"):
        context.data.addChild(ModuleState("aliases"))
    context.data.getNode("aliases").setIndex("alias")
    if not context.data.hasNode("variables"):
        context.data.addChild(ModuleState("variables"))
    context.data.getNode("variables").setIndex("name")
示例#4
0
def parseask(msg):
    if msg.text.find("Free") >= 0 and (
            msg.text.find("API") >= 0 or msg.text.find("api") >= 0) and (
                msg.text.find("SMS") >= 0 or msg.text.find("sms") >= 0):
        resuser = apiuser_ask.search(msg.text)
        reskey = apikey_ask.search(msg.text)
        if resuser is not None and reskey is not None:
            apiuser = resuser.group("user")
            apikey = reskey.group("key")

            test = send_sms("nemubot", apiuser, apikey,
                            "Vous avez enregistré vos codes d'authentification dans nemubot, félicitation !")
            if test is not None:
                return Response("je n'ai pas pu enregistrer tes identifiants : %s" % test, msg.channel, msg.nick)

            if msg.nick in context.data.index:
                context.data.index[msg.nick]["user"] = apiuser
                context.data.index[msg.nick]["key"] = apikey
            else:
                ms = ModuleState("phone")
                ms.setAttribute("name", msg.nick)
                ms.setAttribute("user", apiuser)
                ms.setAttribute("key", apikey)
                ms.setAttribute("lastuse", 0)
                context.data.addChild(ms)
            context.save()
            return Response("ok, c'est noté. Je t'ai envoyé un SMS pour tester ;)",
                            msg.channel, msg.nick)
示例#5
0
def parseask(msg):
    if msg.message.find("Free") >= 0 and (
            msg.message.find("API") >= 0 or msg.message.find("api") >= 0) and (
                msg.message.find("SMS") >= 0 or msg.message.find("sms") >= 0):
        resuser = apiuser_ask.search(msg.message)
        reskey = apikey_ask.search(msg.message)
        if resuser is not None and reskey is not None:
            apiuser = resuser.group("user")
            apikey = reskey.group("key")

            test = send_sms(
                "nemubot", apiuser, apikey,
                "Vous avez enregistré vos codes d'authentification dans nemubot, félicitation !"
            )
            if test is not None:
                return Response(
                    "je n'ai pas pu enregistrer tes identifiants : %s" % test,
                    msg.channel, msg.frm)

            if msg.frm in context.data.index:
                context.data.index[msg.frm]["user"] = apiuser
                context.data.index[msg.frm]["key"] = apikey
            else:
                ms = ModuleState("phone")
                ms.setAttribute("name", msg.frm)
                ms.setAttribute("user", apiuser)
                ms.setAttribute("key", apikey)
                ms.setAttribute("lastuse", 0)
                context.data.addChild(ms)
            context.save()
            return Response(
                "ok, c'est noté. Je t'ai envoyé un SMS pour tester ;)",
                msg.channel, msg.frm)
示例#6
0
文件: whois.py 项目: nbr23/nemubot
def parseask(msg):
    res = re.match(r"^(\S+)\s*('s|suis|est|is|was|were)\s+([a-zA-Z0-9_-]{3,8})$", msg.text, re.I)
    if res is not None:
        nick = res.group(1)
        login = res.group(3)
        if nick == "my" or nick == "I" or nick == "i" or nick == "je" or nick == "mon" or nick == "ma":
            nick = msg.nick
        if nick in context.data.getNode("aliases").index:
            context.data.getNode("aliases").index[nick]["to"] = login
        else:
            ms = ModuleState("alias")
            ms.setAttribute("from", nick)
            ms.setAttribute("to", login)
            context.data.getNode("aliases").addChild(ms)
        context.save()
        return Response("ok, c'est noté, %s est %s" % (nick, login), channel=msg.channel, nick=msg.nick)
示例#7
0
def load(context):
    global PASSWD_FILE
    if not context.config or "passwd" not in context.config:
        print("No passwd file given")
    else:
        PASSWD_FILE = context.config["passwd"]
        print("passwd file loaded:", PASSWD_FILE)

    global APIEXTRACT_FILE
    if not context.config or "apiextract" not in context.config:
        print("No passwd file given")
    else:
        APIEXTRACT_FILE = context.config["apiextract"]
        print("JSON users file loaded:", APIEXTRACT_FILE)

    if PASSWD_FILE is None and APIEXTRACT_FILE is None:
        return None

    if not context.data.hasNode("aliases"):
        context.data.addChild(ModuleState("aliases"))
    context.data.getNode("aliases").setIndex("from", "alias")

    import nemubot.hooks
    context.add_hook(
        nemubot.hooks.Command(
            cmd_whois,
            "whois",
            keywords={
                "lookup":
                "Perform a lookup of the begining of the login instead of an exact search."
            }), "in", "Command")
示例#8
0
def start_watch(msg):
    w = ModuleState("watch")
    w["server"] = msg.server
    w["channel"] = msg.channel
    w["proprio"] = msg.frm
    w["start"] = datetime.now(timezone.utc)
    context.data.addChild(w)
    context.save()
    raise IMException("This channel is now watching world cup events!")
示例#9
0
def add_score(nick, t):
    if nick not in context.data.index:
        st = ModuleState("score")
        st["name"] = nick
        context.data.addChild(st)

    if context.data.index[nick].hasAttribute(t):
        context.data.index[nick][t] = context.data.index[nick].getInt(t) + 1
    else:
        context.data.index[nick][t] = 1
    context.save()
示例#10
0
def parseask(msg):
    res = re.match(
        r"^(\S+)\s*('s|suis|est|is|was|were)?\s+(birthday|geburtstag|née? |nee? le|born on).*$",
        msg.message, re.I)
    if res is not None:
        try:
            extDate = extractDate(msg.message)
            if extDate is None or extDate.year > datetime.now().year:
                return Response("la date de naissance ne paraît pas valide...",
                                msg.channel, msg.frm)
            else:
                nick = res.group(1)
                if nick == "my" or nick == "I" or nick == "i" or nick == "je" or nick == "mon" or nick == "ma":
                    nick = msg.frm
                if nick.lower() in context.data.index:
                    context.data.index[nick.lower()]["born"] = extDate
                else:
                    ms = ModuleState("birthday")
                    ms.setAttribute("name", nick.lower())
                    ms.setAttribute("born", extDate)
                    context.data.addChild(ms)
                context.save()
                return Response(
                    "ok, c'est noté, %s est né le %s" %
                    (nick, extDate.strftime("%A %d %B %Y à %H:%M")),
                    msg.channel, msg.frm)
        except:
            raise IMException("la date de naissance ne paraît pas valide.")
示例#11
0
def create_alias(alias, origin, channel=None, creator=None):
    """Create or erase an existing alias
    """

    anode = ModuleState("alias")
    anode["alias"] = alias
    anode["origin"] = origin
    if channel is not None:
        anode["creator"] = channel
    if creator is not None:
        anode["creator"] = creator
    context.data.getNode("aliases").addChild(anode)
    context.save()
示例#12
0
def set_variable(name, value, creator):
    """Define or erase a variable.

    Arguments:
    name -- The variable identifier
    value -- Variable value
    creator -- User who has created this variable
    """

    var = ModuleState("variable")
    var["name"] = name
    var["value"] = value
    var["creator"] = creator
    context.data.getNode("variables").addChild(var)
    context.save()
示例#13
0
def cmd_watch(msg):
    if not msg.frm_owner:
        raise IMException(
            "sorry, this command is currently limited to the owner")

    wnnode = ModuleState("alert_channel")
    wnnode["to_server"] = msg.server
    wnnode["to_channel"] = msg.channel
    wnnode["owner"] = msg.frm

    context.data.addChild(wnnode)
    watch(**wnnode.attributes)

    return Response("Ok ok, I'll alert you on new pictures on ohsnap!",
                    channel=msg.channel)
示例#14
0
def parseask(msg):
    res = gps_ask.match(msg.message)
    if res is not None:
        city_name = res.group("city").lower()
        gps_lat = res.group("lat").replace(",", ".")
        gps_long = res.group("long").replace(",", ".")

        if city_name in context.data.index:
            context.data.index[city_name]["lat"] = gps_lat
            context.data.index[city_name]["long"] = gps_long
        else:
            ms = ModuleState("city")
            ms.setAttribute("name", city_name)
            ms.setAttribute("lat", gps_lat)
            ms.setAttribute("long", gps_long)
            context.data.addChild(ms)
        context.save()
        return Response(
            "ok, j'ai bien noté les coordonnées de %s" % res.group("city"),
            msg.channel, msg.frm)
示例#15
0
文件: weather.py 项目: nbr23/nemubot
def parseask(msg):
    res = gps_ask.match(msg.message)
    if res is not None:
        city_name = res.group("city").lower()
        gps_lat = res.group("lat").replace(",", ".")
        gps_long = res.group("long").replace(",", ".")

        if city_name in context.data.index:
            context.data.index[city_name]["lat"] = gps_lat
            context.data.index[city_name]["long"] = gps_long
        else:
            ms = ModuleState("city")
            ms.setAttribute("name", city_name)
            ms.setAttribute("lat", gps_lat)
            ms.setAttribute("long", gps_long)
            context.data.addChild(ms)
        context.save()
        return Response("ok, j'ai bien noté les coordonnées de %s" % res.group("city"),
                        msg.channel, msg.frm)
示例#16
0
def cmd_watch(msg):
    if "host" not in msg.kwargs:
        raise IMException("please give a hostname in keywords")

    if not msg.frm_owner:
        raise IMException(
            "sorry, this command is currently limited to the owner")

    wnnode = ModuleState("watched_newsgroup")
    wnnode["id"] = _indexServer(**msg.kwargs)
    wnnode["to_server"] = msg.server
    wnnode["to_channel"] = msg.channel
    wnnode["group"] = msg.args[0] if len(msg.args) > 0 else "*"

    wnnode["user"] = msg.kwargs["user"] if "user" in msg.kwargs else ""
    wnnode["password"] = msg.kwargs[
        "password"] if "password" in msg.kwargs else ""
    wnnode["host"] = msg.kwargs["host"] if "host" in msg.kwargs else ""
    wnnode["port"] = msg.kwargs["port"] if "port" in msg.kwargs else 119

    context.data.addChild(wnnode)
    watch(**wnnode.attributes)

    return Response("Ok ok, I watch this newsgroup!", channel=msg.channel)
示例#17
0
def parseask(msg):
    res = re.match(
        r"^(\S+)\s*('s|suis|est|is|was|were)\s+([a-zA-Z0-9_-]{3,8})$",
        msg.message, re.I)
    if res is not None:
        nick = res.group(1)
        login = res.group(3)
        if nick == "my" or nick == "I" or nick == "i" or nick == "je" or nick == "mon" or nick == "ma":
            nick = msg.frm
        if nick in context.data.getNode("aliases").index:
            context.data.getNode("aliases").index[nick]["to"] = login
        else:
            ms = ModuleState("alias")
            ms.setAttribute("from", nick)
            ms.setAttribute("to", login)
            context.data.getNode("aliases").addChild(ms)
        context.save()
        return Response("ok, c'est noté, %s est %s" % (nick, login),
                        channel=msg.channel,
                        nick=msg.frm)
示例#18
0
def start_countdown(msg):
    """!start /something/: launch a timer"""
    if len(msg.args) < 1:
        raise IMException("indique le nom d'un événement à chronométrer")
    if msg.args[0] in context.data.index:
        raise IMException("%s existe déjà." % msg.args[0])

    strnd = ModuleState("strend")
    strnd["server"] = msg.server
    strnd["channel"] = msg.channel
    strnd["proprio"] = msg.nick
    strnd["start"] = msg.date
    strnd["name"] = msg.args[0]
    context.data.addChild(strnd)

    evt = ModuleEvent(call=fini, call_data=dict(strend=strnd))

    if len(msg.args) > 1:
        result1 = re.findall("([0-9]+)([smhdjwyaSMHDJWYA])?", msg.args[1])
        result2 = re.match("(.*[^0-9])?([0-3]?[0-9])/([0-1]?[0-9])/((19|20)?[01239][0-9])", msg.args[1])
        result3 = re.match("(.*[^0-9])?([0-2]?[0-9]):([0-5]?[0-9])(:([0-5]?[0-9]))?", msg.args[1])
        if result2 is not None or result3 is not None:
            try:
                now = msg.date
                if result3 is None or result3.group(5) is None: sec = 0
                else: sec = int(result3.group(5))
                if result3 is None or result3.group(3) is None: minu = 0
                else: minu = int(result3.group(3))
                if result3 is None or result3.group(2) is None: hou = 0
                else: hou = int(result3.group(2))
                if result2 is None or result2.group(4) is None: yea = now.year
                else: yea = int(result2.group(4))
                if result2 is not None and result3 is not None:
                    strnd["end"] = datetime(yea, int(result2.group(3)), int(result2.group(2)), hou, minu, sec, timezone.utc)
                elif result2 is not None:
                    strnd["end"] = datetime(int(result2.group(4)), int(result2.group(3)), int(result2.group(2)), 0, 0, 0, timezone.utc)
                elif result3 is not None:
                  if hou * 3600 + minu * 60 + sec > now.hour * 3600 + now.minute * 60 + now.second:
                    strnd["end"] = datetime(now.year, now.month, now.day, hou, minu, sec, timezone.utc)
                  else:
                    strnd["end"] = datetime(now.year, now.month, now.day + 1, hou, minu, sec, timezone.utc)
                evt._end = strnd.getDate("end")
                strnd["_id"] = context.add_event(evt)
            except:
                context.data.delChild(strnd)
                raise IMException("Mauvais format de date pour l'événement %s. Il n'a pas été créé." % msg.args[0])

        elif result1 is not None and len(result1) > 0:
            strnd["end"] = msg.date
            for (t, g) in result1:
                if g is None or g == "" or g == "m" or g == "M":
                    strnd["end"] += timedelta(minutes=int(t))
                elif g == "h" or g == "H":
                    strnd["end"] += timedelta(hours=int(t))
                elif g == "d" or g == "D" or g == "j" or g == "J":
                    strnd["end"] += timedelta(days=int(t))
                elif g == "w" or g == "W":
                    strnd["end"] += timedelta(days=int(t)*7)
                elif g == "y" or g == "Y" or g == "a" or g == "A":
                    strnd["end"] += timedelta(days=int(t)*365)
                else:
                    strnd["end"] += timedelta(seconds=int(t))
            evt._end = strnd.getDate("end")
            eid = context.add_event(evt)
            if eid is not None:
                strnd["_id"] = eid

    context.save()
    if "end" in strnd:
        return Response("%s commencé le %s et se terminera le %s." %
                        (msg.args[0], msg.date.strftime("%A %d %B %Y à %H:%M:%S"),
                         strnd.getDate("end").strftime("%A %d %B %Y à %H:%M:%S")),
                        nick=msg.frm)
    else:
        return Response("%s commencé le %s"% (msg.args[0],
                            msg.date.strftime("%A %d %B %Y à %H:%M:%S")),
                        nick=msg.frm)