예제 #1
0
파일: base.py 프로젝트: janch32/rubbergod
 async def hadle_reaction(self, ctx):
     if ctx['emoji'] in ["◀", "▶"]:
         page = int(ctx['message'].embeds[0].footer.text[5])
         next_page = utils.pagination_next(ctx['emoji'], page,
                                           len(messages.info))
         if next_page:
             embed = self.make_embed(next_page)
             await ctx['message'].edit(embed=embed)
     if ctx['message'].guild:
         await ctx['message'].remove_reaction(ctx['emoji'], ctx['member'])
예제 #2
0
파일: base.py 프로젝트: michkot/rubbergod
    async def on_raw_reaction_add(self, payload):
        ctx = await utils.reaction_get_ctx(self.bot, payload)
        if ctx is None:
            return

        if ctx['message'].embeds and ctx['message'].embeds[0].title == "Rubbergod":
            if ctx['emoji'] in ["◀", "▶"]:
                page = int(ctx['message'].embeds[0].footer.text[5])
                next_page = utils.pagination_next(ctx['emoji'], page, len(messages.info))
                if next_page:
                    embed = self.make_embed(next_page)
                    await ctx['message'].edit(embed=embed)
            if ctx['message'].guild: 
                await ctx['message'].remove_reaction(ctx['emoji'], ctx['member'])
예제 #3
0
파일: embed.py 프로젝트: Misha12/rubbergod
 async def interaction_check(self,
                             interaction: disnake.Interaction) -> None:
     ids = [
         "embed:start_page", "embed:prev_page", "embed:next_page",
         "embed:end_page"
     ]
     if interaction.data.custom_id not in ids or self.max_page <= 1:
         return
     if self.author and interaction.author.id != self.author:
         await interaction.send(Messages.embed_not_author, ephemeral=True)
         return
     self.page = utils.pagination_next(interaction.data.custom_id,
                                       self.page, self.max_page,
                                       self.roll_arroud)
     await interaction.response.edit_message(embed=self.embed)
예제 #4
0
    async def handle_reaction(self, ctx: ReactionContext):
        if ctx.emoji not in ["⏪", "◀", "▶", "⏩"]:
            return
        try:
            if ctx.reply_to is None:  # Reply is required to render embed.
                await ctx.message.edit(
                    content=Messages.streamlinks_missing_original, embed=None)
                return

            embed: discord.Embed = ctx.message.embeds[0]
            footer_text = embed.footer.text.split('|')[1].strip()
            match = pagination_regex.match(footer_text)

            if match is None:
                await ctx.message.edit(
                    content=Messages.streamlinks_unsupported_embed, embed=None)
                return  # Invalid or unsupported embed.

            groups = match.groups()
            subject = str(groups[0]).lower()
            current_page = int(groups[1])
            pages_count = int(groups[2])

            streamlinks = self.repo.get_streamlinks_of_subject(subject)

            if len(streamlinks
                   ) != pages_count:  # New streamlink was added, but removed.
                await ctx.message.edit(content=Messages.streamlinks_not_actual,
                                       embed=None)
                return

            new_page = utils.pagination_next(ctx.emoji, current_page,
                                             pages_count)
            if new_page <= 0 or new_page == current_page:
                return  # Pagination to same page. We can ignore.

            # Index - 1, because index position.
            streamlink: StreamLink = streamlinks[new_page - 1]
            embed = self.create_embed_of_link(streamlink, ctx.reply_to.author,
                                              len(streamlinks), new_page)
            await ctx.message.edit(embed=embed)
        finally:
            if ctx.message.guild:  # cannot remove reaction in DM
                await ctx.message.remove_reaction(ctx.emoji, ctx.member)
예제 #5
0
 async def interaction_check(self, interaction: disnake.Interaction) -> None:
     if "review" not in interaction.data.custom_id:
         # interaction from super class
         await super().interaction_check(interaction)
         self.check_text_pages()
         # update view
         await interaction.edit_original_message(view=self)
         return False
     if "text" in interaction.data.custom_id and self.embed.fields[3].name == "Text page":
         # text page pagination
         review = self.repo.get_review_by_id(self.review_id)
         if review:
             pages = self.embed.fields[3].value.split("/")
             text_page = int(pages[0])
             max_text_page = int(pages[1])
             next_text_page = utils.pagination_next(interaction.data.custom_id, text_page, max_text_page)
             if next_text_page:
                 self.embed = self.manager.update_embed(self.embed, review, next_text_page)
                 await interaction.response.edit_message(embed=self.embed)
         return False
     # fallback to buttons callbacks
     return True
예제 #6
0
 async def handle_reaction(self, ctx):
     subject = ctx.message.embeds[0].title.split(" ", 1)[0].lower()
     footer = ctx.message.embeds[0].footer.text.split("|")
     # don't track old reviews as they are not compatible
     if len(footer) != 3:
         return
     review_id = footer[2][5:]
     pages = footer[1].split(":")[1].split("/")
     try:
         page = int(pages[0])
         max_page = int(pages[1])
     except ValueError:
         await ctx.message.edit(content=messages.reviews_page_e, embed=None)
         return
     except IndexError:  # handle legacy embed reviews
         try:
             await ctx.member.send(messages.review_legacy_clicked)
         except discord.HTTPException as e:
             if e.code != 50007:
                 raise
         return
     if ctx.emoji in ["◀", "▶", "⏪"]:
         next_page = utils.pagination_next(ctx.emoji, page, max_page)
         if next_page:
             review = review_repo.get_subject_reviews(subject)
             if review.count() >= next_page:
                 review = review.all()[next_page - 1].Review
                 next_page = f"{next_page}/{max_page}"
                 embed = self.rev.update_embed(ctx.message.embeds[0], review, next_page)
                 if embed.fields[3].name == "Text page":
                     await ctx.message.add_reaction("🔼")
                     await ctx.message.add_reaction("🔽")
                 else:
                     for emote in ctx.message.reactions:
                         if emote.emoji == "🔼":
                             await ctx.message.remove_reaction("🔼", self.bot.user)
                             await ctx.message.remove_reaction("🔽", self.bot.user)
                             break
                 await ctx.message.edit(embed=embed)
     elif ctx.emoji in ["👍", "👎", "🛑"]:
         review = review_repo.get_review_by_id(review_id)
         member_id = str(ctx.member.id)
         if review and member_id != review.member_ID:
             if ctx.emoji == "👍":
                 self.rev.add_vote(review_id, True, member_id)
             elif ctx.emoji == "👎":
                 self.rev.add_vote(review_id, False, member_id)
             elif ctx.emoji == "🛑":
                 review_repo.remove_vote(review_id, member_id)
             page = f"{page}/{max_page}"
             embed = self.rev.update_embed(ctx.message.embeds[0], review, page)
             await ctx.message.edit(embed=embed)
     elif ctx.emoji in ["🔼", "🔽"]:
         if ctx.message.embeds[0].fields[3].name == "Text page":
             review = review_repo.get_review_by_id(review_id)
             if review:
                 pages = ctx.message.embeds[0].fields[3].value.split("/")
                 text_page = int(pages[0])
                 max_text_page = int(pages[1])
                 next_text_page = utils.pagination_next(ctx.emoji, text_page, max_text_page)
                 if next_text_page:
                     page = f"{page}/{max_page}"
                     embed = self.rev.update_embed(
                         ctx.message.embeds[0], review, page, next_text_page
                     )
                     await ctx.message.edit(embed=embed)
     if ctx.message.guild:  # cannot remove reaction in DM
         await ctx.message.remove_reaction(ctx.emoji, ctx.member)
예제 #7
0
    async def on_raw_reaction_add(self, payload):
        ctx = await utils.reaction_get_ctx(self.bot, payload)
        if ctx is None:
            return

        if (
            ctx["message"].embeds
            and ctx["message"].embeds[0].title is not discord.Embed.Empty
            and "reviews" in ctx["message"].embeds[0].title
        ):
            subject = ctx["message"].embeds[0].title.split(" ", 1)[0].lower()
            footer = ctx["message"].embeds[0].footer.text.split("|")
            review_id = footer[2][5:]
            pages = footer[1].split(":")[1].split("/")
            try:
                page = int(pages[0])
                max_page = int(pages[1])
            except ValueError:
                await ctx["message"].edit(content=messages.reviews_page_e, embed=None)
                return
            if ctx["emoji"] in ["◀", "▶", "⏪"]:
                next_page = utils.pagination_next(ctx["emoji"], page, max_page)
                if next_page:
                    review = review_repo.get_subject_reviews(subject)
                    if review.count() >= next_page:
                        review = review.all()[next_page - 1].Review
                        next_page = f"{next_page}/{max_page}"
                        embed = self.rev.update_embed(ctx["message"].embeds[0], review, next_page)
                        if embed.fields[3].name == "Text page":
                            await ctx["message"].add_reaction("🔼")
                            await ctx["message"].add_reaction("🔽")
                        else:
                            for emote in ctx["message"].reactions:
                                if emote.emoji == "🔼":
                                    await ctx["message"].remove_reaction("🔼", self.bot.user)
                                    await ctx["message"].remove_reaction("🔽", self.bot.user)
                                    break
                        await ctx["message"].edit(embed=embed)
            elif ctx["emoji"] in ["👍", "👎", "🛑"]:
                review = review_repo.get_review_by_id(review_id)
                member_id = str(ctx["member"].id)
                if review and member_id != review.member_ID:
                    if ctx["emoji"] == "👍":
                        self.rev.add_vote(review_id, True, member_id)
                    elif ctx["emoji"] == "👎":
                        self.rev.add_vote(review_id, False, member_id)
                    elif ctx["emoji"] == "🛑":
                        review_repo.remove_vote(review_id, member_id)
                    page = f"{page}/{max_page}"
                    embed = self.rev.update_embed(ctx["message"].embeds[0], review, page)
                    await ctx["message"].edit(embed=embed)
            elif ctx["emoji"] in ["🔼", "🔽"]:
                if ctx["message"].embeds[0].fields[3].name == "Text page":
                    review = review_repo.get_review_by_id(review_id)
                    if review:
                        pages = ctx["message"].embeds[0].fields[3].value.split("/")
                        text_page = int(pages[0])
                        max_text_page = int(pages[1])
                        next_text_page = utils.pagination_next(ctx["emoji"], text_page, max_text_page)
                        if next_text_page:
                            page = f"{page}/{max_page}"
                            embed = self.rev.update_embed(
                                ctx["message"].embeds[0], review, page, next_text_page
                            )
                            await ctx["message"].edit(embed=embed)
            if ctx["message"].guild:  # cannot remove reaction in DM
                await ctx["message"].remove_reaction(ctx["emoji"], ctx["member"])
예제 #8
0
파일: review.py 프로젝트: betsst/rubbergod
    async def on_raw_reaction_add(self, payload):
        ctx = await utils.reaction_get_ctx(self.bot, payload)
        if ctx is None:
            return

        if (ctx["message"].embeds
                and ctx["message"].embeds[0].title is not discord.Embed.Empty
                and re.match(".* reviews", ctx["message"].embeds[0].title)):
            subject = ctx["message"].embeds[0].title.split(" ", 1)[0].lower()
            footer = ctx["message"].embeds[0].footer.text.split("|")[0]
            pos = footer.find("/")
            try:
                page = int(footer[8:pos])
                max_page = int(footer[(pos + 1):])
            except ValueError:
                await ctx["message"].edit(content=messages.reviews_page_e,
                                          embed=None)
                return
            description = ctx["message"].embeds[0].description
            if ctx["emoji"] in ["◀", "▶", "⏪"]:
                next_page = utils.pagination_next(ctx["emoji"], page, max_page)
                if next_page:
                    review = review_repo.get_subject_reviews(subject)
                    if review.count() >= next_page:
                        review = review.all()[next_page - 1].Review
                        next_page = str(next_page) + "/" + str(max_page)
                        embed = self.rev.make_embed(review, subject,
                                                    description, next_page)
                        if embed.fields[3].name == "Text page":
                            await ctx["message"].add_reaction("🔼")
                            await ctx["message"].add_reaction("🔽")
                        else:
                            for emote in ctx["message"].reactions:
                                if emote.emoji == "🔼":
                                    await ctx["message"].remove_reaction(
                                        "🔼", self.bot.user)
                                    await ctx["message"].remove_reaction(
                                        "🔽", self.bot.user)
                                    break
                        await ctx["message"].edit(embed=embed)
            elif ctx["emoji"] in ["👍", "👎", "🛑"]:
                review = review_repo.get_subject_reviews(subject)[page -
                                                                  1].Review
                if str(ctx["member"].id) != review.member_ID:
                    review_id = review.id
                    if ctx["emoji"] == "👍":
                        self.rev.add_vote(review_id, True,
                                          str(ctx["member"].id))
                    elif ctx["emoji"] == "👎":
                        self.rev.add_vote(review_id, False,
                                          str(ctx["member"].id))
                    elif ctx["emoji"] == "🛑":
                        review_repo.remove_vote(review_id,
                                                str(ctx["member"].id))
                    page = str(page) + "/" + str(max_page)
                    embed = self.rev.make_embed(review, subject, description,
                                                page)
                    await ctx["message"].edit(embed=embed)
            elif ctx["emoji"] in ["🔼", "🔽"]:
                if ctx["message"].embeds[0].fields[3].name == "Text page":
                    review = review_repo.get_subject_reviews(subject)
                    if review:
                        review = review[page - 1].Review
                        text_page = ctx["message"].embeds[0].fields[3].value
                        pos = ctx["message"].embeds[0].fields[3].value.find(
                            "/")
                        max_text_page = int(text_page[(pos + 1):])
                        text_page = int(text_page[:pos])
                        next_text_page = utils.pagination_next(
                            ctx["emoji"], text_page, max_text_page)
                        if next_text_page:
                            page = str(page) + "/" + str(max_page)
                            embed = self.rev.make_embed(
                                review, subject, description, page)
                            embed = self.rev.change_text_page(
                                review, embed, next_text_page, max_text_page)
                            await ctx["message"].edit(embed=embed)
            if ctx["message"].guild:  # cannot remove reaction in DM
                await ctx["message"].remove_reaction(ctx["emoji"],
                                                     ctx["member"])
예제 #9
0
    async def help(self, ctx: commands.Context, *command):
        # Subcommand help
        command = ' '.join(command)
        if command:
            command_obj = self.bot.get_command(command)
            if not command_obj:
                await ctx.send(
                    utils.fill_message('help_command_not_found',
                                       command=command))
            else:
                # if command group, show all possible subcommands
                if type(command_obj) == commands.Group:
                    subcommands = []
                    if command_obj.usage is not None:
                        subcommands.append(
                            command_obj.usage.replace('[',
                                                      '').replace(']', ''))
                    subcommands += [
                        subcommand.name for subcommand in command_obj.commands
                    ]
                    text = f"`{config.default_prefix}{command_obj.name} [{', '.join(subcommands)}]`"
                else:
                    text = f"`{config.default_prefix}{command_obj} {command_obj.signature}`"
                if command_obj.description:
                    text += f"\n{command_obj.description}"
                elif command_obj.brief:
                    text += f"\n{command_obj.brief}"
                await ctx.send(text)
            return

        # General help
        page_num = 1

        pages = self.generate_pages(ctx)
        embed = self.generate_embed(pages[0])

        pages_total = len(pages)

        commit = f"Commit {self.git.hash()}"
        footer_text = commit
        if pages_total > 1:
            footer_text = f"Strana {page_num}/{pages_total} | {commit}"
        embed.set_footer(text=footer_text,
                         icon_url=ctx.author.display_avatar.url)

        message = await ctx.reply(embed=embed)

        await utils.add_pagination_reactions(message, pages_total)

        while True:

            def check(reaction, user):
                return reaction.message.id == message.id and not user.bot

            try:
                reaction, user = await self.bot.wait_for("reaction_add",
                                                         check=check,
                                                         timeout=300.0)
            except asyncio.TimeoutError:
                return
            emoji = str(reaction.emoji)
            if emoji in ["⏪", "◀", "▶", "⏩"] and user.id == ctx.author.id:
                page_num = utils.pagination_next(emoji, page_num, pages_total)
                embed.clear_fields()
                self.add_fields(embed, pages[page_num - 1]["commands"])
                embed.set_footer(
                    text=f"Strana {page_num}/{pages_total} | {commit}")
                await message.edit(embed=embed)
            try:
                await message.remove_reaction(emoji, user)
            except disnake.errors.Forbidden:
                pass