|
| 1 | +import discord |
| 2 | +from commanderbot_lib.logging import Logger, get_clogger |
| 3 | +from discord.ext.commands import Bot, Cog, command |
| 4 | + |
| 5 | + |
| 6 | +class QuoteCog(Cog): |
| 7 | + def __init__(self, bot: Bot): |
| 8 | + self.bot: Bot = bot |
| 9 | + self._log: Logger = get_clogger(self) |
| 10 | + |
| 11 | + async def construct_embed(self, msg_link: str, quotem: bool = False): |
| 12 | + message_link = msg_link.split("/") |
| 13 | + message_channel = self.bot.get_channel(int(message_link[-2])) |
| 14 | + message = await message_channel.fetch_message(int(message_link[-1])) |
| 15 | + |
| 16 | + # message.author is name + discrim, icon_url is authors avatar |
| 17 | + quote_embed = discord.Embed(description=message.clean_content, timestamp=message.created_at) |
| 18 | + quote_embed.set_author(name=str(message.author), icon_url=str(message.author.avatar_url)) |
| 19 | + quote_embed.set_footer(text=f"#{message_channel.name}") |
| 20 | + |
| 21 | + if quotem: |
| 22 | + return (quote_embed, message.author) |
| 23 | + return quote_embed |
| 24 | + |
| 25 | + @command(name="quote") |
| 26 | + async def cmd_quote(self, ctx: discord.Message, msg_link: str): |
| 27 | + quote_embed = await self.construct_embed(msg_link) |
| 28 | + await ctx.send(f"{ctx.author.mention}\n{msg_link}", embed=quote_embed) |
| 29 | + |
| 30 | + @command(name="quotem") |
| 31 | + async def cmd_quotem(self, ctx: discord.Message, msg_link: str): |
| 32 | + quote_embed = await self.construct_embed(msg_link, quotem=True) |
| 33 | + await ctx.send(f"{ctx.author.mention} {quote_embed[1].mention}\n{msg_link}", embed=quote_embed[0]) |
0 commit comments