Skip to content

Commit 646c3f3

Browse files
committed
Merge branch 'main' of github.com:CommanderBot-Dev/commanderbot-ext into main
2 parents 5ab4dbf + 311ee3c commit 646c3f3

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [Unreleased]
8+
9+
### Added
10+
11+
- Added `quote` and `quotem` commands
12+
713
## [0.5.0] - 2021-01-06
814

915
### Changed

commanderbot_ext/quote/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from discord.ext import commands
2+
from commanderbot_ext.quote.quote_cog import QuoteCog
3+
4+
5+
def setup(bot: commands.Bot):
6+
bot.add_cog(QuoteCog(bot))
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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

Comments
 (0)