Ejemplo n.º 1
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
Ejemplo n.º 2
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