示例#1
0
async def searchForAllMatches(players, client):
    playersInGame = []
    gameIds = []

    if players is None:
        return

    for i in range(0, len(players)):
        try:
            player = players[i]

            global rightBound
            matchRes = await Api.getPlayerMatch(player['user_id'], rightBound)

            if matchRes.status != 200:
                continue

            matchResData = await matchRes.json()
            match = matchResData.get('items')

            if len(match) != 0:
                playersInGame.append(player['nickname'])
                gameIds.append(match[0].get('match_id'))
        except Exception as e:
            log('Exception! ' + str(e))
            continue

    if len(playersInGame) != 0:
        await printMatches(playersInGame, gameIds, client)
示例#2
0
    def execute(self, command, seq):

        self.db.ping(True)

        logString = command % seq
        log('execute: ' + logString)

        self.query(command, seq)
示例#3
0
    def contains(self, command, seq):

        self.db.ping(True)

        logString = command % seq
        log('contains: ' + logString)

        return self.query(command, seq)
示例#4
0
async def record(client, message):
    matchID = message.content[8:]
    isAdmin = message.channel.permissions_for(message.author).administrator

    if not isAdmin or addedMatches.get(matchID):
        await client.send_message(
            message.channel,
            'Error, match has already been added, or you are not an admin.')
        return

    teamRes = await Api.getTeamMembers()
    teamResData = await teamRes.json()
    members = teamResData.get('members')

    playersInGame = []
    gameIds = []

    matchInfoRes = await Api.getMatchInfo(matchID)
    matchInfoData = await matchInfoRes.json()
    teams = matchInfoData.get('teams')

    allMembers = {}

    if members is None or teams is None:
        await client.send_message(message.channel,
                                  'Error, could not find match. Sorry!')
        return

    factionOne = matchInfoData.get('teams').get('faction1')
    factionTwo = matchInfoData.get('teams').get('faction2')

    factionOneList = factionOne.get('roster_v1')
    factionTwoList = factionTwo.get('roster_v1')

    if factionOneList == None:
        factionOneList = factionOne.get('roster')
        factionTwoList = factionTwo.get('roster')

    for i in range(0, len(factionOneList)):
        allMembers[factionOneList[i].get('nickname')] = True
        allMembers[factionTwoList[i].get('nickname')] = True

    for i in range(0, len(members)):
        try:
            playerNick = members[i]['nickname']
            if allMembers[playerNick]:
                playersInGame.append(playerNick)
                gameIds.append(matchID)
        except Exception as e:
            log('Exception! ' + str(e))
            continue

    if len(playersInGame) != 0:
        await printMatches(playersInGame, gameIds, client)

    addedMatches[matchID] = True
示例#5
0
    def get(self, command, seq):

        self.db.ping(True)

        logString = command % seq
        log('get: ' + logString)

        self.query(command, seq)
        return [
            dict(zip([column[0] for column in self.cur.description], row))
            for row in self.cur.fetchall()
        ]
示例#6
0
async def startMatchSearch(client):
    teamRes = await Api.getTeamMembers()
    teamResData = await teamRes.json()
    members = teamResData.get('members')

    log('startMatchSearch w/ ' + str(members))

    for i in range(0, len(members)):
        member = members[i]
        DBQuery.insertOrUpdate(member.get('user_id'), member.get('nickname'))

    while True:
        await searchForAllMatches(members, client)
        global addToDatabase
        if len(addToDatabase) != 0:
            for i in range(0, len(addToDatabase)):
                await addMatchToDatabase(addToDatabase[i], members)

            addToDatabase = []

        await asyncio.sleep(SLEEP_LENGTH)
示例#7
0
    async def get(self, url):

        log('req: %s' % url)

        body = await self.client.get(FACEIT_URL + url)
        try:
            log('Rate Limit Left: ' +
                body.headers['X-Ratelimit-Remaining-Hour'])
        except:
            log('Cant find rate limit, heres the body: ' + str(body))

        return body
示例#8
0
async def on_ready():
    log('Logged in as: %s [%s]' % (client.user.name, client.user.id))

    # Start 60s timer to look for FACEIT matches.
    await startMatchSearch(client)
示例#9
0
    def __del__(self):
        log("Closing MySQL connection...")

        self.cur.close()
        self.db.close()