async def save_quickaction( self, ctx: commands.Context, emoji: converters.Emoji ) -> None: """Set the quickAction emoji for saving messages""" clean = utils.clean_emoji(emoji) await raise_if_exists(clean, ctx) await self.bot.db.execute( """UPDATE guilds SET qa_save=$1 WHERE id=$2""", clean, ctx.guild.id, ) await ctx.send(f"Set the save emoji to {emoji}")
async def on_raw_reaction_remove( self, payload: discord.RawReactionActionEvent) -> None: if not payload.guild_id: return emoji = utils.clean_emoji(payload.emoji) orig_message = await starboard_funcs.orig_message( self.bot, payload.message_id) if orig_message is not None: # Delete from the original message await self.bot.db.delete_reaction_user(emoji, int(orig_message["id"]), payload.user_id) await starboard_funcs.update_message(self.bot, orig_message["id"], payload.guild_id) else: # Delete from the message since it is the original await self.bot.db.delete_reaction_user(emoji, payload.message_id, payload.user_id) await starboard_funcs.update_message(self.bot, payload.message_id, payload.guild_id)
async def on_raw_reaction_add( self, payload: discord.RawReactionActionEvent ) -> None: qa_type: Optional[str] emoji: str message: Optional[discord.Message] orig_message: Optional[dict] if not payload.guild_id: user = await self.bot.fetch_user(payload.user_id) if payload.emoji.name == "❌": m = await user.fetch_message(payload.message_id) if m.author.id != self.bot.user.id: return await m.delete() return if payload.member.bot: return await self.bot.db.create_guild(payload.guild_id) sql_guild = await self.bot.db.get_guild(payload.guild_id) if not sql_guild["qa_enabled"]: return emoji = utils.clean_emoji(payload.emoji) if emoji in await starboard_funcs.sbemojis(self.bot, payload.guild_id): return qa_type = qa_funcs.get_qa_type(emoji, sql_guild) if qa_type is None: return message = await self.bot.cache.fetch_message( self.bot, payload.guild_id, payload.channel_id, payload.message_id ) if not message: return orig_message = await starboard_funcs.orig_message( self.bot, payload.message_id ) if not orig_message: guild = self.bot.get_guild(payload.guild_id) channel = guild.get_channel(payload.channel_id) await self.bot.db.create_message( payload.message_id, payload.guild_id, payload.channel_id, payload.member.id, channel.is_nsfw(), ) orig_message = await self.bot.db.get_message(payload.message_id) status: bool = True if qa_type in self.qa_map: status = await self.qa_map[qa_type]( self.bot, orig_message, payload.member ) if status is True: try: await message.remove_reaction(payload.emoji, payload.member) except (discord.errors.Forbidden, discord.errors.NotFound): pass
async def on_raw_reaction_add( self, payload: discord.RawReactionActionEvent) -> None: # Check if bot if not payload.guild_id: return if payload.member.bot: return # Check if is starEmoji emoji = utils.clean_emoji(payload.emoji) starboards = await self.bot.db.get_starboards(payload.guild_id) sb_emojis = [] for s in starboards: sb_emojis += s["star_emojis"] if emoji not in sb_emojis: return # Create necessary data await self.bot.db.create_user(payload.member.id, payload.member.bot) await self.bot.db.create_member(payload.member.id, payload.guild_id) # Add reaction sql_message = await starboard_funcs.orig_message( self.bot, payload.message_id) if sql_message is not None: # Get the message since it already exists message = await self.bot.cache.fetch_message( self.bot, int(sql_message["guild_id"]), int(sql_message["channel_id"]), int(sql_message["id"]), ) await self.bot.db.create_reaction_user(emoji, sql_message["id"], payload.user_id) await starboard_funcs.update_message(self.bot, sql_message["id"], sql_message["guild_id"]) else: # Get the message as well as add it to the database message = await self.bot.cache.fetch_message( self.bot, payload.guild_id, payload.channel_id, payload.message_id, ) await self.bot.db.create_user(message.author.id, message.author.bot) await self.bot.db.create_member(message.author.id, payload.guild_id) await self.bot.db.create_message( message.id, message.guild.id, message.channel.id, message.author.id, message.channel.is_nsfw(), ) await self.bot.db.create_reaction_user(emoji, message.id, payload.user_id) await starboard_funcs.update_message(self.bot, payload.message_id, payload.guild_id)