def whois_embed(self, ctx, member: discord.Member, db_member: object) -> discord.Embed: """Construct the whois embed""" embed = self.embed(ctx=ctx, title="Whois", description=member.mention) embed.add_field( name=self.text.get("whois", "information"), value=self.text.get( "whois", "account_information", name=self.sanitise(member.display_name), account_since=utils.id_to_datetime(member.id).strftime("%Y-%m-%d"), member_since=member.joined_at.strftime("%Y-%m-%d"), ), inline=False, ) if db_member is not None: embed.add_field( name=self.text.get("whois", "email"), value=self.dbobj2email(db_member) if db_member.login else self.text.get("whois", "missing"), ) embed.add_field( name=self.text.get("whois", "code"), value=db_member.code if db_member.code else self.text.get("whois", "missing"), ) embed.add_field( name=self.text.get("whois", "status"), value=db_member.status if db_member.status else self.text.get("whois", "missing"), ) embed.add_field( name=self.text.get("whois", "group"), value=db_member.group if db_member.group else self.text.get("whois", "missing"), ) embed.add_field( name=self.text.get("whois", "changed"), value=db_member.changed if db_member.changed else self.text.get("whois", "missing"), ) if db_member.comment and len(db_member.comment): embed.add_field( name=self.text.get("whois", "comment"), value=db_member.comment, inline=False ) role_list = ", ".join(list((r.name) for r in member.roles[::-1])[:-1]) embed.add_field( name=self.text.get("whois", "roles"), value=role_list if len(role_list) else self.text.get("whois", "missing"), ) return embed
async def report_duplicate(self, message: discord.Message, original: object, distance: int): """Send report. message: The new message containing attachment repost. original: The original attachment. distance: Hamming distance between the original and repost. """ if distance <= self.limit_full: level = "title_full" await message.add_reaction("♻️") elif distance <= self.limit_hard: level = "title_hard" await message.add_reaction("🤔") else: level = "title_soft" await message.add_reaction("🤷🏻") similarity = "{:.1f} %".format((1 - distance / 128) * 100) timestamp = utils.id_to_datetime(original.attachment_id).strftime("%Y-%m-%d %H:%M:%S") try: original_channel = message.guild.get_channel(original.channel_id) original_message = await original_channel.fetch_message(original.message_id) author = discord.utils.escape_markdown(original_message.author.display_name) link = f"[**{author}**, {timestamp}]({original_message.jump_url})" except discord.errors.NotFound: link = "404 " + emote.sad description = self.text.get( "report", "description", name=discord.utils.escape_markdown(message.author.display_name), similarity=similarity, ) embed = discord.Embed( title=self.text.get("report", level), color=config.color, description=description, ) embed.add_field( name=self.text.get("report", "original"), value=link, inline=False, ) embed.add_field( name=self.text.get("report", "help"), value=self.text.get( "report", "help_content", limit=self.config.get("not duplicate limit"), ), inline=False, ) embed.set_footer(text=f"{message.author.id} | {message.id}") report = await message.reply(embed=embed) await report.add_reaction("❎")
async def _announceDuplicate(self, message: discord.Message, original: object, hamming: int): """Send message that a post is a original original: object hamming: Hamming distance between the image and closest database entry """ if hamming <= self.limit_full: t = "**♻️ To je repost!**" await message.add_reaction("♻️") elif hamming <= self.limit_hard: t = "**♻️ To je asi repost**" await message.add_reaction("🤔") else: t = "To je možná repost" await message.add_reaction("🤷🏻") prob = "{:.1f} %".format((1 - hamming / 128) * 100) timestamp = utils.id_to_datetime( original.attachment_id).strftime("%Y-%m-%d %H:%M:%S") src_chan = self.getGuild().get_channel(original.channel_id) try: src_post = await src_chan.fetch_message(original.message_id) link = src_post.jump_url author = discord.utils.escape_markdown( src_post.author.display_name) except: link = "404 " + emote.sad author = "_??? (404)_" d = self.text.get( "repost description", name=discord.utils.escape_markdown(message.author.display_name), value=prob, ) embed = discord.Embed(title=t, color=config.color, description=d, url=message.jump_url) embed.add_field(name=f"**{author}**, {timestamp}", value=link, inline=False) embed.add_field( name=self.text.get("repost title"), value="_" + self.text.get("repost content", limit=self.config.get("not duplicate limit")) + "_", ) embed.set_footer(text=f"{message.author.id} | {message.id}") m = await message.channel.send(embed=embed) await m.add_reaction("❎") await m.add_reaction("🆗")
async def bookmark_message( self, message: discord.Message, user: Union[discord.Member, discord.User], ): embed = self.embed( title=self.text.get("bookmark", "title"), description=message.content, author=message.author, ) timestamp = utils.id_to_datetime( message.id).strftime("%Y-%m-%d %H:%M:%S") embed.add_field( name=self.sanitise(message.author.display_name), value=self.text.get( "bookmark", "info", timestamp=timestamp, channel=message.channel.name, link=message.jump_url, ), inline=False, ) info = set() if len(message.attachments): embed.add_field( name=self.text.get("bookmark", "files"), value=self.text.get("bookmark", "total", count=len(message.attachments)), ) if len(message.embeds): embed.add_field( name=self.text.get("bookmark", "embeds"), value=self.text.get("bookmark", "total", count=len(message.embeds)), ) await user.send(embed=embed) await self.event.user( user, f"Bookmarked message in #{message.channel.name}\n> {message.jump_url}", escape_markdown=False, )
async def seeking(self, ctx): """List items for current channel""" if ctx.invoked_subcommand is not None: return embed = self.embed(ctx=ctx, title=self.text.get("embed", "title")) items = repo_s.getAll(ctx.channel.id) if items is not None: template = self.text.get("embed", "template") for item in items: member = ctx.guild.get_member(item.user_id) name = ( self.sanitise(member.display_name) if hasattr(member, "display_name") else self.text.get("embed", "no_user") ) try: message = await ctx.channel.fetch_message(item.message_id) except discord.NotFound: message = None if message: text = item.text + f" | [link]({message.jump_url})" else: text = item.text embed.add_field( name=template.format( id=item.id, name=name, timestamp=utils.id_to_datetime(item.message_id).strftime("%Y-%m-%d %H:%M"), ), value=text, inline=False, ) else: embed.add_field(name="\u200b", value=self.text.get("embed", "no_items")) await ctx.send(embed=embed)
async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent): """Pinning functionality""" channel = self.bot.get_channel(payload.channel_id) if channel is None or not isinstance(channel, discord.TextChannel): return if payload.emoji.name not in ("📌", "📍", "🔖"): return try: message = await channel.fetch_message(payload.message_id) except discord.errors.NotFound: return if payload.emoji.is_custom_emoji(): return reaction_author: discord.User = self.bot.get_user(payload.user_id) if reaction_author.bot: return if message.type != discord.MessageType.default: await message.remove_reaction(payload.emoji, reaction_author) return if payload.emoji.name == "📍" and not reaction_author.bot: await reaction_author.send(self.text.get("bad pin")) await message.remove_reaction(payload.emoji, reaction_author) return if payload.emoji.name == "🔖": await self.bookmark_message(message, reaction_author) await message.remove_reaction(payload.emoji, reaction_author) return for reaction in message.reactions: if reaction.emoji != "📌": continue if message.pinned: return await reaction.clear() if channel.id in self.config.get("unpinnable"): return await reaction.clear() if reaction.count < self.config.get("pins"): return users = await reaction.users().flatten() user_names = ", ".join([str(user) for user in users]) log_embed = self.embed(title=self.text.get("pinned"), description=user_names) if len(message.content): value = utils.id_to_datetime( message.id).strftime("%Y-%m-%d %H:%M:%S") log_embed.add_field(name=str(message.author), value=value) url_text = self.text.get( "link text", channel=channel.name, guild=channel.guild.name, ) if len(message.content): log_embed.add_field( name=self.text.get("content"), value=message.content[:1024], inline=False, ) if len(message.content) >= 1024: log_embed.add_field( name="\u200b", value=message.content[1024:], inline=False, ) if len(message.attachments): log_embed.add_field( name=self.text.get("content"), value=self.text.get("attachments", count=len(message.attachments)), inline=False, ) log_embed.add_field( name=self.text.get("link"), value=f"[{url_text}]({message.jump_url})", inline=False, ) try: await message.pin() except discord.errors.HTTPException as e: await self.event.user(channel, "Could not pin message.", e) error_embed = self.embed( title=self.text.get("pin error"), description=user_names, url=message.jump_url, ) await message.channel.send(embed=error_embed) return event_channel = self.bot.get_channel( config.get("channels", "events")) await event_channel.send(embed=log_embed) await reaction.clear() await message.add_reaction("📍")
def whois_embed( self, ctx, member: Optional[Union[discord.Member, discord.User, int]], db_member: Optional[object], ) -> discord.Embed: """Construct the whois embed""" if type(member) in (discord.Member, discord.User): description = f"{member.name}\n{member.id}" elif db_member is not None: description = str(db_member.discord_id) else: description = discord.Embed.Empty embed = self.embed(ctx=ctx, title="Whois", description=description) if type(member) in (discord.Member, discord.User): embed.add_field( name=self.text.get("whois", "information"), value=self.text.get( "whois", "account_information", name=self.sanitise(member.display_name), account_since=utils.id_to_datetime( member.id).strftime("%Y-%m-%d"), member_since=member.joined_at.strftime("%Y-%m-%d"), ), inline=False, ) if db_member is None: embed.add_field( name=self.text.get("whois", "none"), value=self.text.get("whois", "not_in_database"), inline=False, ) else: embed.add_field( name=self.text.get("whois", "login"), value=self.dbobj2email(db_member) if db_member.login else self.text.get("whois", "missing"), ) embed.add_field( name=self.text.get("whois", "code"), value=db_member.code if db_member.code else self.text.get( "whois", "missing"), ) embed.add_field( name=self.text.get("whois", "status"), value=db_member.status if db_member.status else self.text.get( "whois", "missing"), ) embed.add_field( name=self.text.get("whois", "group"), value=db_member.group if db_member.group else self.text.get( "whois", "missing"), ) embed.add_field( name=self.text.get("whois", "changed"), value=db_member.changed if db_member.changed else self.text.get("whois", "missing"), ) if db_member.comment and len(db_member.comment): embed.add_field(name=self.text.get("whois", "comment"), value=db_member.comment, inline=False) if type(member) in (discord.Member, discord.User): role_list = ", ".join( list((r.name) for r in member.roles[::-1])[:-1]) embed.add_field( name=self.text.get("whois", "roles"), value=role_list if len(role_list) else self.text.get( "whois", "missing"), ) return embed