Exemple #1
0
    async def on_raw_bulk_message_delete(self, payload):
        if not star_utils.star_check(self.bot, payload):
            return

        init_star_variants = [
            await self.bot.starboard.get(k) for k in payload.message_ids
        ]
        star_variants = [k for k in init_star_variants if k != None]

        if star_variants != []:
            for star_variant in star_variants:
                if star_variant.star_var_id not in payload.message_ids:
                    self.bot.starboard.delete(star_variant.ori_mes_id)

                    if star_variant.star_var_id != None:
                        star_chan = self.bot.get_partial_messageable(
                            star_variant.starboard_id)
                        try:
                            star_mes = await star_chan.fetch_message(
                                star_variant.star_var_id)
                            await star_mes.delete()
                            self.bot.star_queue.remove_from_copy((
                                star_variant.ori_chan_id,
                                star_variant.ori_mes_id,
                                star_variant.guild_id,
                            ))
                        except discord.HTTPException:
                            pass
                else:
                    star_variant.star_var_id = None
                    star_variant.starboard_id = None
                    star_variant.forced = False
                    self.bot.starboard.upsert(star_variant)
    async def on_raw_reaction_remove(self, payload):
        if not (star_utils.star_check(self.bot, payload)
                and str(payload.emoji) == "⭐"):
            return

        try:
            user, channel, mes = await star_utils.fetch_needed(
                self.bot, payload)
        except discord.NotFound:
            return
        except discord.Forbidden:
            return
        except AttributeError:
            return
        except discord.HTTPException:
            return

        if (not user.bot and mes.author.id != user.id
                and channel.id not in self.bot.config.getattr(
                    mes.guild.id, "star_blacklist")):

            star_variant = await self.bot.starboard.get(mes.id)

            if star_variant and not star_variant.frozen and not star_variant.trashed:
                await star_utils.modify_stars(self.bot, mes, payload.user_id,
                                              "SUBTRACT")

                if star_variant.star_var_id:
                    await star_utils.star_entry_refresh(
                        self.bot, star_variant, mes.guild.id)
Exemple #3
0
    async def on_raw_message_delete(self, payload):
        if not star_utils.star_check(self.bot, payload):
            return

        star_variant = await self.bot.starboard.get(payload.message_id)

        if star_variant:
            if star_variant.star_var_id != payload.message_id:
                self.bot.starboard.delete(star_variant.ori_mes_id)

                if star_variant.star_var_id != None:
                    star_chan = self.bot.get_partial_messageable(
                        star_variant.starboard_id)
                    try:
                        star_mes = await star_chan.fetch_message(
                            star_variant.star_var_id)
                        await star_mes.delete()
                        self.bot.star_queue.remove_from_copy((
                            star_variant.ori_chan_id,
                            star_variant.ori_mes_id,
                            star_variant.guild_id,
                        ))
                    except discord.HTTPException:
                        pass
            else:
                star_variant.star_var_id = None
                star_variant.starboard_id = None
                star_variant.forced = False
                self.bot.starboard.upsert(star_variant)
Exemple #4
0
    async def on_raw_message_delete(self, payload):
        if not star_utils.star_check(self.bot, payload):
            return

        star_variant = star_utils.get_star_entry(self.bot, payload.message_id)

        if star_variant != []:
            ori_mes_id = star_variant["ori_mes_id_bac"]
            if star_variant["star_var_id"] != payload.message_id:
                self.bot.starboard[ori_mes_id]["ori_chan_id"] = None
            else:
                self.bot.starboard[ori_mes_id]["star_var_id"] = None
                self.bot.starboard[ori_mes_id]["forced"] = False
Exemple #5
0
    async def on_raw_bulk_message_delete(self, payload):
        if not star_utils.star_check(self.bot, payload):
            return

        star_variants = [
            self.bot.starboard[k] for k in self.bot.starboard.keys()
            if (int(k) in payload.message_ids or self.bot.starboard[int(k)]
                ["star_var_id"] in payload.message_ids)
        ]

        if star_variants != []:
            for star_variant in star_variants:
                ori_mes_id = star_variant["ori_mes_id_bac"]
                if not star_variant["star_var_id"] in payload.message_ids:
                    self.bot.starboard[ori_mes_id]["ori_chan_id"] = None
                else:
                    self.bot.starboard[ori_mes_id]["star_var_id"] = None
                    self.bot.starboard[ori_mes_id]["forced"] = False
Exemple #6
0
    async def on_raw_reaction_add(self, payload):
        if not (star_utils.star_check(self.bot, payload)
                and str(payload.emoji) == "⭐"):
            return

        try:
            user, channel, mes = await utils.fetch_needed(self.bot, payload)
        except discord.Forbidden:
            return
        except discord.HTTPException:
            utils.msg_to_owner(
                self.bot,
                f"{payload.message_id}: could not find Message object. Channel: {payload.channel_id}"
            )
            return

        if (not user.bot and mes.author.id != user.id and not channel.id
                in self.bot.config[mes.guild.id]["star_blacklist"]):

            star_variant = star_utils.get_star_entry(self.bot,
                                                     mes.id,
                                                     check_for_var=True)

            if star_variant == []:
                if channel.id != self.bot.config[mes.guild.id]["starboard_id"]:
                    await star_utils.modify_stars(self.bot, mes,
                                                  payload.user_id, "ADD")

                    star_entry = star_utils.get_star_entry(self.bot, mes.id)
                    unique_stars = star_utils.get_num_stars(star_entry)

                    if unique_stars >= self.bot.config[
                            mes.guild.id]["star_limit"]:
                        self.bot.star_queue[mes.id] = {
                            "mes": mes,
                            "unique_stars": unique_stars,
                            "forced": False
                        }

            elif user.id != star_variant["author_id"]:
                await star_utils.modify_stars(self.bot, mes, payload.user_id,
                                              "ADD")
                await star_utils.star_entry_refresh(self.bot, star_variant,
                                                    mes.guild.id)
Exemple #7
0
    async def on_raw_reaction_remove(self, payload):
        if not (star_utils.star_check(self.bot, payload)
                and str(payload.emoji) == "⭐"):
            return

        try:
            user, channel, mes = await utils.fetch_needed(self.bot, payload)
        except discord.NotFound:
            return
        except discord.Forbidden:
            return

        if (not user.bot and mes.author.id != user.id and not channel.id
                in self.bot.config[mes.guild.id]["star_blacklist"]):

            star_variant = star_utils.get_star_entry(self.bot, mes.id)

            if star_variant != []:
                await star_utils.modify_stars(self.bot, mes, payload.user_id,
                                              "SUBTRACT")

                if star_variant["star_var_id"] != None:
                    await star_utils.star_entry_refresh(
                        self.bot, star_variant, mes.guild.id)
Exemple #8
0
    async def on_raw_reaction_clear_emoji(self, payload):
        if not star_utils.star_check(self.bot, payload):
            return

        if str(payload.emoji) == "тнР":
            await self.auto_clear_stars(payload)
Exemple #9
0
    async def on_raw_reaction_clear(self, payload):
        if not star_utils.star_check(self.bot, payload):
            return

        await self.auto_clear_stars(payload)
    async def on_raw_reaction_add(self, payload):
        if not (star_utils.star_check(self.bot, payload)
                and str(payload.emoji) == "⭐"):
            return

        try:
            user, channel, mes = await star_utils.fetch_needed(
                self.bot, payload)
        except discord.NotFound:
            return
        except discord.Forbidden:
            return
        except AttributeError:
            return
        except discord.HTTPException:
            return

        if not user.bot and channel.id not in self.bot.config.getattr(
                mes.guild.id, "star_blacklist"):

            if mes.author.id != user.id:
                starboard_entry = await self.bot.starboard.get(mes.id)

                if starboard_entry and (starboard_entry.frozen
                                        or starboard_entry.trashed):
                    return

                if not starboard_entry or not starboard_entry.star_var_id:
                    if channel.id != self.bot.config.getattr(
                            mes.guild.id, "starboard_id"):
                        await star_utils.modify_stars(self.bot, mes,
                                                      payload.user_id, "ADD")
                        starboard_entry = await self.bot.starboard.get(mes.id)
                        if not starboard_entry:
                            return

                        unique_stars = starboard_entry.num_reactors

                        if unique_stars >= self.bot.config.getattr(
                                mes.guild.id, "star_limit"):
                            # the queue is infinite, so we should be good there
                            self.bot.star_queue.put_nowait(
                                (mes.channel.id, mes.id, mes.guild.id))

                elif user.id != starboard_entry.author_id:
                    old_stars = starboard_entry.num_reactors

                    await star_utils.modify_stars(self.bot, mes,
                                                  payload.user_id, "ADD")

                    new_entry = await self.bot.starboard.get(mes.id)
                    new_stars = new_entry.num_reactors
                    if old_stars != new_stars:  # we don't want to refresh too often
                        await star_utils.star_entry_refresh(
                            self.bot, starboard_entry, mes.guild.id)

            elif self.bot.config.getattr(mes.guild.id, "remove_reaction"):
                # the previous if confirms this is the author who is reaction (simply by elimination), so...
                try:
                    await mes.remove_reaction("⭐", mes.author)
                except discord.HTTPException:
                    pass
                except TypeError:
                    pass