Exemple #1
0
 def rssHandler(self, feedDict):
     try:
         if feedDict:
             for feedName, results in feedDict.iteritems():
                 if results:
                     newcount = len(results)
                     keys = results.keys()
                     keys.sort()
                     keys.reverse()
                     if newcount > 2:
                         #use #eversible whilst testing
                         self.connection.privmsg(
                             self.IRCconfig["irc"]["channel"],
                             functions.parseIRCBBCode(
                                 "There are [colour=green]%i[/colour] new items for feed: [b]%s[/b]"
                                 % (newcount, feedName)))
                     self.connection.privmsg(
                         self.IRCconfig["irc"]["channel"],
                         functions.parseIRCBBCode(
                             "%s: ([colour=yellow]%s ago[/colour]) [colour=light_green]%s[/colour] [ [colour=blue]%s[/colour] ]"
                             % (feedName,
                                functions.convert_to_human(
                                    time.time() - results[keys[0]]["date"]),
                                results[keys[0]]["title"],
                                results[keys[0]]["link"])))
     except:
         print "Error in scheduler thread (rssHandler):"
         traceback.print_exc()
Exemple #2
0
def index(connection, event, config, evedb, userdb):
    locale.setlocale(locale.LC_ALL, config["core"]["locale"])
    serverstatus = API.Server("status")
    status = serverstatus["status"]
    online = serverstatus["online"]
    servertime = serverstatus["time"].split()[1]
    if status == "Online":
        if online >= 50000:
            players = "[colour=red]" + locale.format("%d", online,
                                                     True) + "[/colour]"
        elif online >= 30000:
            players = "[colour=yellow]" + locale.format("%d", online,
                                                        True) + "[/colour]"
        else:
            players = "[colour=green]" + locale.format("%d", online,
                                                       True) + "[/colour]"

        message = functions.parseIRCBBCode(
            "[b]Server[/b]: [colour=light_cyan]Tranquility[/colour]  [b]Status[/b]: [colour=light_green]Online[/colour]  [b]Players[/b]: %(players)s  [b]Server Time (GMT)[/b]: %(servertime)s"
            % {
                "players": players,
                "servertime": servertime,
            })

    elif status == "Offline":
        message = functions.parseIRCBBCode(
            "[b]Server[/b]: [colour=light_cyan]Tranquility[/colour]  [b]Status[/b]: [colour=light_red]Offline[/colour]"
        )

    connection.privmsg(event.target(), message)
Exemple #3
0
def index(connection, event, config, DB, userdb):
    try:
        shipName = event.arguments()[0].split()[1]
        lvlJDC = int(event.arguments()[0].split()[2])
        lvlJFC = int(event.arguments()[0].split()[3])
        lvlJF = int(event.arguments()[0].split()[4])
        systemFrom = event.arguments()[0].split()[5]
        systemTo = event.arguments()[0].split()[6]
    except (IndexError, ValueError):
        connection.privmsg(
            event.target(),
            "Syntax is: %sjump [ship name] [JDC lvl] [JFC lvl] [JF lvl] [system name] [system name]"
            % config["bot"]["prefix"])
    else:
        responseShipID = DB.getItemIDByName(shipName)
        responseSystemFromID = DB.getSystemIDByName(systemFrom)
        responseSystemToID = DB.getSystemIDByName(systemTo)
        if not responseSystemFromID:
            connection.privmsg(event.target(),
                               "System '%s' is unknown to me" % systemFrom)
        elif not responseSystemToID:
            connection.privmsg(event.target(),
                               "System '%s' is unknown to me" % systemTo)
        elif not responseShipID:
            connection.privmsg(event.target(),
                               "Ship '%s' is unknown to me" % shipName)
        elif not responseShipID in jumpCapableID:
            connection.privmsg(event.target(),
                               "Ship '%s' not jump capable" % shipName)
        elif lvlJDC > 5 or lvlJDC < 0:
            connection.privmsg(event.target(),
                               "JDC level not within acceptable ranges")
        elif lvlJFC > 5 or lvlJFC < 0:
            connection.privmsg(event.target(),
                               "JFC level not within acceptable ranges")
        elif lvlJF > 5 or lvlJF < 0:
            connection.privmsg(event.target(),
                               "JF level not within acceptable ranges")
        elif DB.getSystemInfoByID(responseSystemFromID)["security"] >= 0.5:
            connection.privmsg(
                event.target(),
                functions.parseIRCBBCode(
                    "Origin system security must be less than [b][colour=red]0.5[/colour][/b]"
                ))
        elif DB.getSystemInfoByID(responseSystemToID)["security"] >= 0.5:
            connection.privmsg(
                event.target(),
                functions.parseIRCBBCode(
                    "Destination system security must be less than [b][colour=red]0.5[/colour][/b]"
                ))

        else:
            systemNameFrom = DB.getSystemNameByID(responseSystemFromID)
            systemSecFrom = functions.security(responseSystemFromID)
            systemNameTo = DB.getSystemNameByID(responseSystemToID)
            systemSecTo = functions.security(responseSystemToID)
            shipName = DB.getItemNameByID(responseShipID)
            sytemSecFromChk = DB.getSystemInfoByID(
                responseSystemFromID)["security"]
            systemSecToChk = DB.getSystemInfoByID(
                responseSystemToID)["security"]

            outputMessage = """
                \x02Origin\x02:     %s (%s)
                \x02Endpoint\x02:   %s (%s)
                \x02Ship\x02:       %s  \x0314[JDC: %s, JFC: %s, JF: %s]\x03
                \x02Jump Route\x02: \x1fhttp://evemaps.dotlan.net/jump/%s,%s%s%s/%s:%s\x1f
            """ % (systemNameFrom, systemSecFrom, systemNameTo, systemSecTo,
                   shipName, lvlJDC, lvlJFC, lvlJF, shipName, lvlJDC, lvlJFC,
                   lvlJF, systemNameFrom, systemNameTo)
            for line in outputMessage.split("\n"):
                connection.privmsg(event.target(), line.strip())
Exemple #4
0
    def mailCheck(self):
        #get identified users
        try:
            USERS = users.DB()
            loggedInHostnames = USERS.getHostnames()
            for id, hostname in loggedInHostnames.iteritems():
                API = None
                mailXML = None
                nick = hostname.split("!")[0]
                resp = USERS.retrieveUserByHostname(hostname)
                if resp:
                    API = resp["apiObject"]
                else:
                    print "No api object for id: %s, hostname: %s" % (id,
                                                                      hostname)
                    continue
                mails = API.Char("mail")

                ##############################################################
                if API.CHAR_ID in self.MAIL_RECORD.keys():
                    latest_time = self.MAIL_RECORD[API.CHAR_ID]["sentTime"]
                    latest_id = self.MAIL_RECORD[API.CHAR_ID]["messageID"]
                else:
                    result = USERS.getMessageID(API.CHAR_ID)
                    if result:
                        self.MAIL_RECORD[API.CHAR_ID] = {}
                        self.MAIL_RECORD[API.CHAR_ID]["sentTime"] = result[1]
                        self.MAIL_RECORD[API.CHAR_ID]["messageID"] = result[0]
                        latest_time = result[1]
                        latest_id = result[0]
                    else:
                        latest_time = None
                        latest_id = None

                new_latest_time = None
                new_latest_id = None

                newIDs = []
                count = 0

                mailList = sorted(mails.items(),
                                  key=lambda x: x[1]["sentTime"],
                                  reverse=True)
                for mailID, row in mailList:
                    #>>> mails.keys()
                    #['corpTicker', 'toCharacterIDs', 'listName', 'sentTime', 'title', 'corpID', 'allianceTicker', 'senderID', 'allianceID', 'listID', 'allianceName', 'sentDate', 'messageID', 'corpName', 'senderName']
                    messageID = row["messageID"]
                    sentDate = row["sentTime"]
                    if count <= 5:
                        count += 1
                    if count > 5:
                        break

                    if sentDate > latest_time:
                        if sentDate > new_latest_time:
                            new_latest_time = sentDate
                            new_latest_id = messageID
                        newIDs += [messageID]
                if newIDs:
                    newIDs_len = len(newIDs)
                    self.connection.notice(
                        nick,
                        functions.parseIRCBBCode(
                            "You have [colour=red]%i[/colour] new mails" %
                            newIDs_len))

                    count = 0
                    ids = []
                    for i in range(5):
                        try:
                            ids += [str(newIDs[i])]
                            count += 1
                        except IndexError:
                            break

                    if newIDs_len == count:
                        self.connection.notice(
                            nick,
                            functions.parseIRCBBCode("ids are: [b]%s[/b]" %
                                                     ("[/b], [b]".join(ids))))
                    else:
                        self.connection.notice(
                            nick,
                            functions.parseIRCBBCode(
                                "First %i ids are: [b]%s[/b]" %
                                (count, "[/b], [b]".join(ids))))

                    #insert new data into users
                    USERS.insertMessageID(API.CHAR_ID, new_latest_id,
                                          new_latest_time)
                    self.MAIL_RECORD[API.CHAR_ID] = {
                        "messageID": new_latest_id,
                        "sentTime": new_latest_time
                    }
        except:
            print "Error in scheduler thread (mailCheck):"
            traceback.print_exc()
Exemple #5
0
def index(connection, event, config, DUMP, USERS):
    locale.setlocale(locale.LC_ALL, config["core"]["locale"])
    sourceHostName = event.source()
    sourceNick = event.source().split("!")[0]

    #check if identified
    APItest = USERS.retrieveUserByHostname(sourceHostName)

    if not APItest:
        connection.notice(sourceNick,
                          "This command requires your full api key")
        connection.notice(sourceNick, "Please identify or register")
        connection.privmsg(
            event.target(),
            "User \x034\x02'%s'\x03\x02 not recognised" % sourceNick)
    else:
        API = APItest["apiObject"]

        #syntax: pve daterange [system]
        # e.g. : pve 1w F9O-U9

        try:
            daterange = event.arguments()[0].split()[1]
        except IndexError:
            daterange = "7d"
        try:
            system = event.arguments()[0].split()[2]
        except IndexError:
            system = None

        results = re.search(
            "((?P<weeksago>\d+)w)?((?P<daysago>\d+)d)?((?P<hoursago>\d+)h)?((?P<minutesago>\d+)m)?((?P<secondsago>\d+)s)?",
            daterange, re.I).groupdict()
        try:
            weeks = int(results["weeksago"])
        except TypeError:
            weeks = 0
        try:
            days = int(results["daysago"])
        except TypeError:
            days = 0
        try:
            hours = int(results["hoursago"])
        except TypeError:
            hours = 0
        try:
            minutes = int(results["minutesago"])
        except TypeError:
            minutes = 0
        try:
            seconds = int(results["secondsago"])
        except TypeError:
            seconds = 0
        delta = seconds + minutes * 60 + hours * 60 * 60 + days * 24 * 60 * 60 + weeks * 7 * 24 * 60 * 60
        starttime = time.time() - delta
        endtime = time.time()

        #now check system
        if system:
            system_ID = DUMP.getSystemIDByName(system)
            if not system_ID:
                system_ID = None
        else:
            system_ID = None

        try:
            walletdict = API.Char("wallet")
        except api.APIError:
            connection.notice(sourceNick,
                              "This command requires your full API key")
            connection.privmsg(event.target(), "Insufficient permissions")
        else:
            walletSorted = sorted(walletdict.items(),
                                  key=lambda x: x[1]["time"],
                                  reverse=True)
            kills = {}
            total_bounty = 0
            earliest_date = endtime + 10
            latest_date = starttime - 10
            for transact in walletSorted:
                walletData = transact[1]
                refTypeID = walletData["refTypeID"]
                if refTypeID == 85:
                    #bounty prize! \o/
                    bounty_system_id = walletData["argID1"]
                    if not system_ID or system_ID == bounty_system_id:
                        bounty_date = walletData["time"]
                        if bounty_date > starttime and bounty_date <= endtime:
                            if bounty_date < earliest_date:
                                earliest_date = bounty_date
                            if bounty_date > latest_date:
                                latest_date = bounty_date
                            bountyData = walletData["reason"]
                            for NPC in bountyData.split(",")[:-1]:
                                NPCid = int(NPC.split(":")[0])
                                if NPCid in kills.keys():
                                    prev_count = kills[NPCid]["count"]
                                    kills[NPCid] = {
                                        "shipID": NPCid,
                                        "shipName": kills[NPCid]["shipName"],
                                        "count": prev_count + NPCcount,
                                    }
                                else:
                                    NPCname = DUMP.getItemNameByID(NPCid)
                                    NPCcount = int(NPC.split(":")[1])
                                    kills[NPCid] = {
                                        "shipID": NPCid,
                                        "shipName": NPCname,
                                        "count": NPCcount,
                                    }
                            total_bounty += walletData["amount"]

            bounties_list = sorted(kills.items(),
                                   key=lambda ship: ship[1]["count"],
                                   reverse=True)
            if total_bounty > 0:
                datestring = "for the past %s" % daterange
                systemstring = ""
                if system:
                    systemstring = "in system [colour=red]%s[/colour]" % DUMP.getSystemNameByID(
                        system_ID)
                connection.privmsg(
                    event.target(),
                    functions.parseIRCBBCode(
                        "[b]PvE stats for character [colour=light_yellow]%s[/colour] %s %s [/b]"
                        %
                        (APItest["characterName"], datestring, systemstring)))
                connection.privmsg(
                    event.target(),
                    functions.parseIRCBBCode(
                        "[b]Total bounty earned[/b]: [colour=light_green]%s ISK[/colour]"
                        % locale.format("%.2f", total_bounty, True)))
                connection.privmsg(event.target(),
                                   "\x02Top 5 NPC ships killed:\x02")
                for shiptype in bounties_list[:5]:
                    connection.privmsg(
                        event.target(),
                        "\x034\x02%-25s\x03\x02:  \x033\x02\x02%1i\x03" %
                        (shiptype[1]["shipName"], shiptype[1]["count"]))
                connection.privmsg(
                    event.target(),
                    functions.parseIRCBBCode(
                        "[b]Earliest date in range[/b]: %s" % time.strftime(
                            "%Y-%b-%d %H:%M", time.gmtime(earliest_date))))
                connection.privmsg(
                    event.target(),
                    functions.parseIRCBBCode(
                        "[b]Latest date in range[/b]: %s" % time.strftime(
                            "%Y-%b-%d %H:%M", time.gmtime(latest_date))))
            else:
                connection.privmsg(
                    event.target(),
                    functions.parseIRCBBCode("No PvE kills found"))
                connection.privmsg(
                    event.target(),
                    functions.parseIRCBBCode(
                        "[b]Syntax[/b]: %spve [time ago] [system]" %
                        config["bot"]["prefix"]))
Exemple #6
0
def index(connection, event, config, evedb, USERS):
    sourceHostName = event.source()
    sourceNick = event.source().split("!")[0]

    try:
        mailID = event.arguments()[0].split()[1]
        mailID = int(mailID)
    except (IndexError, ValueError):
        mailID = None

    response = USERS.retrieveUserByHostname(sourceHostName)
    if not response:
        connection.privmsg(event.source().split("!")[0],
                           "This command requires your full API key")
        connection.privmsg(event.source().split("!")[0],
                           "Please identify or register")
    else:
        characterName = response["characterName"]
        characterID = response["characterID"]
        API = response["apiObject"]

        if not mailID:
            try:
                connection.privmsg(sourceNick, "Fetching mail, please wait")
                mailheaders = API.Char("mail")
            except api.APIError:
                connection.privmsg(
                    sourceNick,
                    "There was an error with the API: %s" % " ".join(
                        traceback.format_exc().splitlines()[-1].split()[1:]))
            else:
                #(309935139, {'listName': None, 'sentTime': 1326055740, 'title': 'Re: Re: Op: Big-badda-boom', 'toCharacterIDs':
                #'2081077519', 'senderID': 2081077519, 'listID': None, 'sentDate': '2012-01-08 20:49:00', 'messageID': 309935139,
                #'toCorpOrAlliance': '1102238026', 'senderName': 'Gheent'})
                sortedMail = sorted(mailheaders.items(),
                                    key=lambda x: x[1]["sentTime"],
                                    reverse=True)

                connection.privmsg(sourceNick, "\x02Latest 5 mails\x02:")
                connection.privmsg(sourceNick, " (\x1fmail ID\x1f)")
                for mail in sortedMail[:5]:
                    mailID = mail[0]
                    mailInfo = mail[1]
                    title = mailInfo["title"]
                    fromName = mailInfo["senderName"]
                    toIDs = mailInfo["toCharacterIDs"] + [
                        mailInfo["toCorpOrAlliance"]
                    ]
                    toNameList = []
                    for ID in toIDs:
                        toName = API.Eve("getname", nameID=ID)
                        if toName:
                            toNameList += [toName["name"]]
                        else:
                            toNameList += [str(ID)]
                    to_formatted = functions.parseIRCBBCode(
                        "[colour=green][b]%s[/b][/colour]" %
                        "[/b][/colour], [colour=green][b]".join(toNameList))
                    sentTime = mailInfo["sentTime"]
                    when = "%s ago" % (functions.convert_to_human(time.time() -
                                                                  sentTime))
                    message = functions.parseIRCBBCode(
                        " ([b]%(mailID)s[/b]): [u]%(title)s[/u] from [colour=red]%(from)s[/colour] to %(to_formatted)s (%(when)s)"
                        % {
                            "mailID": mailID,
                            "title": title,
                            "from": fromName,
                            "to_formatted": to_formatted,
                            "when": when
                        })
                    connection.privmsg(sourceNick, message)
        else:
            try:
                mailID = int(mailID)
                mailHeader = API.Char("mail")[mailID]
                message = API.Char("mail", mailID=mailID)
            except api.APIError:
                connection.privmsg(
                    sourceNick,
                    "There was an error with the API: %s" % " ".join(
                        traceback.format_exc().splitlines()[-1].split()[1:]))
            except KeyError:
                connection.privmsg(sourceNick, "No such mail")
            else:
                title = mailHeader["title"]
                From = mailHeader["senderName"]
                To = []
                if mailHeader["toCorpOrAlliance"]:
                    To += [
                        functions.parseIRCBBCode(
                            "[colour=dark_green][b]%s[/b][/colour]" % API.Eve(
                                "getname",
                                nameID=int(
                                    mailHeader["toCorpOrAlliance"]))["name"])
                    ]
                if mailHeader["toCharacterIDs"]:
                    for charID in mailHeader["toCharacterIDs"]:
                        To += [
                            functions.parseIRCBBCode(
                                "[colour=blue][b]%s[/b][/colour]" %
                                API.Eve("getname", nameID=charID))
                        ]
                TO = "\x02\x02,\x02\x02".join(To)

                timeSent = time.time() - mailHeader["sentTime"]

                ###############################################################################################

                human_time = functions.convert_to_human(timeSent)
                connection.privmsg(
                    sourceNick,
                    "(\x02%i\x02): \x1f%s\x1f from \x034\x02%s\x02\x03 to %s (%s ago)"
                    % (mailID, title, From, TO, human_time))

                #parse out html
                message = re.sub("(\<br\>)+", "\n", message)
                message = message.replace("<b>", "\x02")
                message = message.replace("</b>", "\x02")
                message = message.replace("<u>", "\x1f")
                message = message.replace("</u>", "\x1f")
                message = message.replace("&gt;",
                                          ">").replace("&lt;", "<").replace(
                                              "&amp;", "&")
                itemmatches = re.findall(
                    "(\<a href=\"showinfo:(\d+)\"\>(.*?)\<\/a\>)", message,
                    re.DOTALL)
                for match in itemmatches:
                    html = match[0]
                    itemID = match[1]
                    itemName = match[2]
                    #message = message.replace(html, "\x1f%s\x1f ( http://games.chruker.dk/eve_online/item.php?type_id=%s )" % (itemName, itemID))
                    message = message.replace(html, "\x1f%s\x1f" % itemName)

                itemmatches = re.findall(
                    "(\<a href=\"showinfo:5//(\d+)\"\>(.*?)\<\/a\>)", message,
                    re.DOTALL)
                for match in itemmatches:
                    html = match[0]
                    solarSystemID = match[1]
                    solarSystemName = match[2]
                    message = message.replace(
                        html, "\x035\x02%s\x03\x02" % solarSystemName)

                itemmatches = re.findall(
                    "(\<a href=\"showinfo:4//(\d+)\"\>(.*?)\<\/a\>)", message,
                    re.DOTALL)
                for match in itemmatches:
                    html = match[0]
                    ID = match[1]
                    Name = match[2]
                    message = message.replace(html,
                                              "\x0310\x02%s\x03\x02" % Name)

                itemmatches = re.findall(
                    "(\<a href=\"showinfo:3//(\d+)\"\>(.*?)\<\/a\>)", message,
                    re.DOTALL)
                for match in itemmatches:
                    html = match[0]
                    ID = match[1]
                    Name = match[2]
                    message = message.replace(html,
                                              "\x032\x02%s\x03\x02" % Name)

                itemmatches = re.findall(
                    "(\<a href=\"showinfo:3//(\d+)\"\>(.*?)\<\/a\>)", message,
                    re.DOTALL)
                for match in itemmatches:
                    html = match[0]
                    ID = match[1]
                    Name = match[2]
                    message = message.replace(html,
                                              "\x037\x02%s\x03\x02" % Name)

                itemmatches = re.findall(
                    "(\<a href=\"showinfo:16159//(\d+)\"\>(.*?)\<\/a\>)",
                    message, re.DOTALL)
                for match in itemmatches:
                    html = match[0]
                    ID = match[1]
                    Name = match[2]
                    message = message.replace(html,
                                              "\x033\x02%s\x03\x02" % Name)

                itemmatches = re.findall(
                    "(\<a href=\"showinfo:1377//(\d+)\"\>(.*?)\<\/a\>)",
                    message, re.DOTALL)
                for match in itemmatches:
                    html = match[0]
                    ID = match[1]
                    Name = match[2]
                    message = message.replace(html,
                                              "\x034\x02%s\x03\x02" % Name)

                itemmatches = re.findall(
                    "(\<a href=\"showinfo:3867//(\d+)\"\>(.*?)\<\/a\>)",
                    message, re.DOTALL)
                for match in itemmatches:
                    html = match[0]
                    ID = match[1]
                    Name = match[2]
                    message = message.replace(html, "\x02%s\x02" % Name)

                #remove all unparsed html tags
                message = re.sub("\<.*?\>", "", message)

                for line in message.splitlines():
                    connection.privmsg(sourceNick, line)