Example #1
0
 async def remove_event(self, ctx: commands.Context, event: str, streamer: str):
     lang = await self.bot.getg_lang(ctx.guild.id)
     resp = await remove_user_event(ctx, self.bot.http_session, event, streamer)
     if resp.status >= 200 and resp.status < 300:
         embed = discord.Embed(
             description=self.bot.locales[lang]["description_configure_lyvego"].format(
                 self.bot.lyvego_url),
             color=self.bot.color,
             timestamp=dctt()
         )
         embed.set_author(
             name=self.bot.locales[lang]["author_name_success_removed"].format(
                 streamer),
             icon_url=ctx.author.avatar_url
         )
         embed.set_thumbnail(
             url=ctx.me.avatar_url
         )
         try:
             await ctx.message.add_reaction("<a:valid_checkmark:709737579460952145>")
         except:
             pass
         await ctx.send(embed=embed)
     else:
         raise errors.StreamerNotFound(
             self.bot.locales[lang]["error_streamer_not_found"].format(ctx.author))
Example #2
0
    async def add_follow(self, ctx: commands.Context, streamer: str, *message):
        lang = await self.bot.getg_lang(ctx.guild.id)
        resp = await post_streamer(
            ctx,
            self.bot.http_session,
            json=[
                {
                    "type": "follow_announcement",
                    "channel_id": ctx.channel.id,
                    "streamer": streamer,
                    "message": " ".join(message) if len(message)
                    else self.bot.locales[lang]["message_started_following"],
                    "color": self.bot.color_str,
                    "update_message_on_change": False,
                    "delete_message_on_change": False
                }
            ]
        )
        if resp.status in range(200, 300):

            embed = discord.Embed(
                description=self.bot.locales[lang]["description_configure_lyvego"].format(
                    self.bot.lyvego_url),
                color=self.bot.color,
                timestamp=dctt()
            )
            embed.set_author(
                name=f"{streamer} successfully added",
                icon_url=ctx.author.avatar_url
            )
            embed.set_thumbnail(
                url=ctx.me.avatar_url
            )
            try:
                await ctx.message.add_reaction("<a:valid_checkmark:709737579460952145>")
            except:
                pass
            await ctx.send(embed=embed)
        else:
            raise errors.StreamerNotFound(
                self.bot.locales[lang]["error_streamer_not_found"].format(ctx.author))
Example #3
0
    async def topclip(self, ctx: commands.Context, streamer: str, amount=5):
        lang = await self.bot.getg_lang(ctx.guild.id)
        if amount > 100:
            raise Exception(self.bot.locales[lang]["error_amount_topclips"])
        try:
            clips = await top_clips(self.bot.http_session, streamer, parameters=f"&amount={amount}")
            if clips == None:
                raise errors.StreamerNotFound(
                    self.bot.locales[lang]["error_streamer_not_found"].format(ctx.author))
            clips = clips["clips"]
            if clips[0]:
                pass
            try:
                await ctx.message.add_reaction("<a:valid_checkmark:709737579460952145>")
            except:
                pass
        except (IndexError, KeyError):
            raise errors.ClipsNotFound(
                self.bot.locales[lang]["error_clips_not_found"].format(ctx.author))

        embed = discord.Embed(
            timestamp=dctt(),
            color=self.bot.color
        )
        embed.set_author(
            name=self.bot.locales[lang]["author_name_most_viewed_clips"].format(
                clips[0]["streamer"]["name"]),
            url=f"https://twitch.tv/{clips[0]['streamer']['name']}",
            icon_url=clips[0]["streamer"]["avatar"]
        )

        embed.set_thumbnail(
            url=clips[0]["thumbnail"]
        )
        start = 0
        end = 8
        self.__next(embed, clips, start, end, lang)

        if len(clips) * 3 <= 25:
            return await ctx.send(embed=embed)
        embed.set_footer(
            text=f"lyvego.com | Pages {end // 8}/{math.ceil(len(clips) / 8)}"
        )

        pages = await ctx.send(embed=embed)
        react_list = ["◀�", "▶�"]
        for reaction in react_list:
            await pages.add_reaction(reaction)

        def predicate(reaction, user):
            return ctx.message.author == user and str(reaction.emoji) in react_list

        start += 8
        end += 8
        while True:
            try:
                reaction, user = await self.bot.wait_for('reaction_add', check=predicate, timeout=180.0)
            except asyncio.TimeoutError:
                try:
                    await ctx.message.delete()
                except:
                    pass
                await pages.delete()
                return

            if react_list[0] == str(reaction.emoji):
                self.__next(embed, clips, start, end, lang)

                start -= 8
                end -= 8
                if start < 0:
                    end = len(clips)
                    start = end - 8

            if react_list[1] == str(reaction.emoji):
                self.__next(embed, clips, start, end, lang)
                start += 8
                end += 8
                if end > len(clips):
                    start = 0
                    end = 8

            await pages.remove_reaction(reaction.emoji, user)
            await pages.edit(embed=embed)