Пример #1
0
    async def recentsets(self, ctx, message):
        '''
        Player's most recent sets. Takes a name or player ID.
        First method requires that the player is already in the list.
        Get a player's id by calling !listplayers or !playerinfo.
        !recentsets player's_name
        !recentsets player's_id
        '''
        #With the player ID, you can go straight into the query. Player name requires pulling it out from a player object
        #1 Each invidual player only has 1 PLayer ID, so even if they are in the list multiple times....
        try:
            int(message)
            playerId = message
        except:
            gamerTag = message.lower()
            playerList = self.get_list(ctx)
            players = playerList.get_players()
            player = [
                gamer for gamer in players
                if gamerTag == gamer.get_gamer_tag()
            ]
            if player == []:
                await ctx.send(
                    "Player needs to be in the list if you search by their name."
                )
                return
            playerId = player[0].get_player_id()  #1

        #Smash.gg recentSets query + validation
        query = Queries.recentSetsQuery
        input = {"playerId": playerId}
        result = self.client.execute(query, input)
        data = json.loads(result)
        validation = DataValidation.recent_sets_validate_data(data)
        if validation != "Valid":
            await ctx.send(validation)
            return

        #Parsing data for set information
        try:
            realId = data["data"]["player"]["id"]
            realTag = data["data"]["player"]["gamerTag"]
            recentSets = data["data"]["player"]["recentSets"]
            embedTitle = "{0}'s Recent Sets - Player ID: {1}".format(
                realTag, realId)
            info = ""
            for match in recentSets:
                tournament = match["event"]["tournament"]["name"]
                game = match["event"]["videogame"]["name"]
                score = match["displayScore"]
                roundText = match["fullRoundText"]
                info += """{0}\n{1} {2} @ {3}\n\n""".format(
                    score, game, roundText, tournament)
        except Exception as error:
            print(error)
            await ctx.send("Something went wrong with the recent sets query.")
        else:
            await ctx.send(embed=discord.Embed(title=embedTitle,
                                               description=info.rstrip()))
        return
Пример #2
0
    async def playersets(self, ctx, *, message):
        '''
        All of the sets a player has completed in the specified tournament.
        !playersets player's_name ; tournament
        '''
        #Add in ability to specify which event you want to filter on another day
        #If you just get the player and tournament, whole list. If they put player/tourny/game...
        parse = self.parse_message(message)
        if parse == False:
            await ctx.send('!playersets player name{0} tournament name'.format(
                self.splitter))
            return
        gamerTag = parse[0]
        tournySlug = parse[1]
        playerList = self.get_list(ctx)
        player = playerList.get_player(gamerTag, tournySlug)
        if player is False:
            await ctx.send(
                "{0} is not in the list under {1}. Add them first.".format(
                    gamerTag, tournySlug))
            return

        #Smash.gg query + validation
        query = Queries.playerSetsQuery
        input = {"slug": tournySlug, "playerId": player.get_player_id()}
        result = self.client.execute(query, input)
        data = json.loads(result)
        validation = DataValidation.player_sets_validate_data(data)
        if validation != "Valid":
            await ctx.send(validation)
            return

        #Getting player's matches in each event they're entered in
        events = data["data"]["tournament"]["events"]
        for event in events:
            if event["sets"]["nodes"] is None:
                continue
            else:
                info = ""
                gameName = event["name"]
                for match in event["sets"]["nodes"]:
                    roundText = match["fullRoundText"]
                    displayScore = match["displayScore"]
                    #Spoiler tag this
                    info += "{0} --- {1}\n".format(displayScore, roundText)
                    embedTitle = "{0} @ {1} - {2}".format(
                        gamerTag, tournySlug, gameName)
                await ctx.send(spoiler=True,
                               embed=discord.Embed(title=embedTitle,
                                                   description=info.rstrip()))
        return
Пример #3
0
    async def streamqueue(self, ctx, *, tournySlug: str):
        '''
        Get a tournament's stream queue.
        !streamqueue tournament
        '''
        #Smash.gg query + validation
        tournySlug = self.string_clean(tournySlug)
        query = Queries.streamQueueQuery
        input = {"slug": tournySlug}
        result = self.client.execute(query, input)
        data = json.loads(result)
        #print(json.dumps(data, indent=4, sort_keys=True))
        validation = DataValidation.stream_queue_validate_data(data)
        if validation != "Valid":
            await ctx.send(validation)
            return

        #Getting each tournament's stream and it's individual queue
        embedTitle = "{0}'s stream queue".format(tournySlug)
        streamQueue = data["data"]["tournament"]["streamQueue"]
        info = ""
        try:
            for stream in streamQueue:
                streamSource = stream["stream"]["streamSource"]
                streamSite = self.get_domain(streamSource)
                streamName = stream["stream"]["streamName"]
                streamUrl = "https://{0}{1}".format(streamSite, streamName)
                sets = stream["sets"]
                info += "{0}\n".format(streamUrl)
                for slot in sets:
                    event = slot["event"]["name"]
                    fullRoundText = slot["fullRoundText"]
                    entrant1 = slot["slots"][0]["entrant"]
                    entrant2 = slot["slots"][1]["entrant"]
                    if entrant1 is not None and entrant2 is not None:
                        info += "{0} vs {1} - {2}, {3}\n".format(
                            entrant1["name"], entrant2["name"], event,
                            fullRoundText)
                info += "\n"
        except Exception as error:
            await ctx.send(
                "Something went wrong getting the stream queue's information.")
            print("{}: {}".format(type(error).__name__, error))
        else:
            await ctx.send(embed=discord.Embed(title=embedTitle,
                                               description=info.rstrip()))
        return
Пример #4
0
    def check_queue(self, client):
        message = ""
        dataList = dict()
        idList = []

        #Each tournament being watched will have its data stored in a dictionary
        #The correct data will then be passed to Player.py's queue_status function to see if player is
        #in the stream queue.
        for tournySlug in self.queryList: 
            #Smash.GG query + validation
            query = Queries.streamQueueQuery
            input = {"slug": tournySlug}
            result = client.execute(query, input)
            data = json.loads(result)
            #data = Queries.streamQueueTestResult #For testing
            validation = DataValidation.stream_queue_validate_data(data)
            if validation != "Valid":
                #print("{0} - {1}".format(tournySlug, validation))
                continue
            else:
                dataList[tournySlug] = data

        #If dataList is empty, Gigi will consider the stream queue as empty
        if not dataList:
            return [message, idList]

        #Run through each player in the list
        #player.queue_status will return a message status[0] and the player's alert list status[1]
        #If no players are in the queue, message will go unmodified and GigiCog will know this was the case
        for player in self.players:
            tournySlug = player.get_tourny_slug()
            try:
                data = dataList[tournySlug]
            except Exception as error:
                continue
            status = player.queue_status(data)
            if status[1] is not None:
                message += status[0]
                #Convert keys from the alertlist back into ints so they are proper searchable IDs
                for key in status[1]:
                    idList.append(int(key))

        return [message, idList]
Пример #5
0
    async def multistream(self, ctx, *, tournySlug: str):
        '''
        Provides a multistre.am link for all a tournament's streams.
        Only works for Twitch.tv streams.
        !multistream tournament
        '''
        #Smash.gg query + validation
        tournySlug = self.string_clean(tournySlug)
        query = Queries.tournamentStreamQuery
        input = {"slug": tournySlug}
        result = self.client.execute(query, input)
        data = json.loads(result)
        #print(json.dumps(data, indent=4, sort_keys=True))
        validation = DataValidation.tourny_streams_validate_data(data)
        if validation != "Valid":
            await ctx.send(validation)
            return

        #Getting each tournament's stream info
        url = "https://multistre.am/"
        numStreams = 0
        embedTitle = "{0}'s Multistream".format(tournySlug)
        streams = data["data"]["tournament"]["streams"]
        try:
            for stream in streams:
                numStreams += 1
                url += "{0}/".format(stream["streamName"])
                if numStreams == 8:  #Multistre.am can fit a maximum of 8 streams
                    break

            layout = self.get_layout(numStreams)
            url = url + layout
        except Exception as error:
            await ctx.send("Something went wrong grabbing the streams.")
            print("{}: {}".format(type(error).__name__, error))
        else:
            await ctx.send(
                embed=discord.Embed(title=embedTitle, description=url))

        return
Пример #6
0
    async def streams(self, ctx, *, tournySlug: str):
        '''
        Get all of a tournament's streams.
        !tournystreams tournament
        '''
        #Smash.gg query + validation
        tournySlug = self.string_clean(tournySlug)
        query = Queries.tournamentStreamQuery
        input = {"slug": tournySlug}
        result = self.client.execute(query, input)
        data = json.loads(result)
        #print(json.dumps(data, indent=4, sort_keys=True))
        validation = DataValidation.tourny_streams_validate_data(data)
        if validation != "Valid":
            await ctx.send(validation)
            return

        #Getting each tournament's stream info
        info = ""
        embedTitle = "{0}'s Stream List".format(tournySlug)
        streams = data["data"]["tournament"]["streams"]
        try:
            for stream in streams:
                if stream["streamGame"] is not None:
                    streamGame = " - " + stream["streamGame"]
                else:
                    streamGame = ""
                streamSite = self.get_domain(stream["streamSource"])
                streamUrl = "https://{0}{1}".format(streamSite,
                                                    stream["streamName"])
                info += "{0}{1}\n".format(streamUrl, streamGame)
        except Exception as error:
            await ctx.send("Something went wrong getting the streams.")
            print("{}: {}".format(type(error).__name__, error))
        else:
            await ctx.send(embed=discord.Embed(title=embedTitle,
                                               description=info.rstrip()))
        return
Пример #7
0
    async def add(self, ctx, *, message):
        '''
        Add player @ tournament combination to the list to be watched.
        Adds whoever invoked the command to that player's alert list.
        !add player1, player2, ..., tournament
        '''
        success = False
        #Split up "message" into a gamertag and tournament slug
        parse = self.parse_message(message)
        if parse == False:
            await ctx.send("!add player1{0} player2{0} ...{0} tournament name".format(self.splitter))
            return
        gamerTags = parse[0]
        tournySlug = parse[1]
        for tag in gamerTags:
            input = {"gamerTag": tag, "slug": tournySlug}

            #Smash.gg query + validation
            query = Queries.playerQuery
            result = self.client.execute(query, input)
            data = json.loads(result)
            validation = DataValidation.tourny_validate_data(data)
            if validation != "Valid":
                await ctx.send(validation)
                continue

            #Create player object and add to the appropriate list; update json file
            try:
                realTag = data["data"]["tournament"]["participants"]["nodes"][0]["gamerTag"]
                playerId = data["data"]["tournament"]["participants"]["nodes"][0]["player"]["id"]
                attendeeId = data["data"]["tournament"]["participants"]["nodes"][0]["id"]
                eventList = data["data"]["tournament"]["participants"]["nodes"][0]["entrants"]
                gameList = {self.string_clean(eventList["event"]["name"]): eventList["id"] for eventList in eventList}
                alertList = dict()
                player = Player(realTag, playerId, tournySlug, attendeeId, gameList, alertList)

                playerList = self.get_list(ctx)
                check = playerList.add_player(player)
                if check != "Success":
                    #Case where player was already in the list
                    #Add the user to the alert list regardless
                    alertList = player.get_alert_list()
                    alertList[str(ctx.author.id)] = ctx.author.name
                    self.update_serial_list(ctx)
                    await ctx.send(check)
                    continue
            except Exception as error:
                print(error) #Logging
                await ctx.send("Something went wrong getting information from the player query")
            else:
                success = True
                alertList = player.get_alert_list()
                alertList[str(ctx.author.id)] = ctx.author.name
                self.update_serial_list(ctx)
                await ctx.send("Added {0} @ {1}.".format(realTag, tournySlug))

        if success == True:
            await ctx.send(
                "I'll mention you when these players are in the stream queue.\n"
                + "!alertoff all --- if you don't want to be mentioned."
                )
        return