From 92caf16fe977ba168ec343f7484a6ce099c42732 Mon Sep 17 00:00:00 2001 From: bobloy Date: Thu, 10 Sep 2020 09:17:02 -0400 Subject: [PATCH] FirstMessage initial commit --- firstmessage/__init__.py | 5 ++++ firstmessage/firstmessage.py | 48 ++++++++++++++++++++++++++++++++++++ firstmessage/info.json | 16 ++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 firstmessage/__init__.py create mode 100644 firstmessage/firstmessage.py create mode 100644 firstmessage/info.json diff --git a/firstmessage/__init__.py b/firstmessage/__init__.py new file mode 100644 index 0000000..4dab2ed --- /dev/null +++ b/firstmessage/__init__.py @@ -0,0 +1,5 @@ +from .firstmessage import FirstMessage + + +async def setup(bot): + bot.add_cog(FirstMessage(bot)) diff --git a/firstmessage/firstmessage.py b/firstmessage/firstmessage.py new file mode 100644 index 0000000..b74ea40 --- /dev/null +++ b/firstmessage/firstmessage.py @@ -0,0 +1,48 @@ +import logging + +import discord +from redbot.core import Config, commands +from redbot.core.bot import Red + +log = logging.getLogger("red.fox_v3.firstmessage") + + +class FirstMessage(commands.Cog): + """ + Provides a link to the first message in the provided channel + + Less important information about the cog + """ + + def __init__(self, bot: Red): + super().__init__() + self.bot = bot + self.config = Config.get_conf( + self, identifier=701051141151167710111511597103101, force_registration=True + ) + + default_guild = {} + + self.config.register_guild(**default_guild) + + async def red_delete_data_for_user(self, **kwargs): + """Nothing to delete""" + return + + @commands.command() + async def firstmessage(self, ctx: commands.Context, channel: discord.TextChannel = None): + if channel is None: + channel = ctx.channel + try: + message: discord.Message = ( + await channel.history(limit=1, oldest_first=True).flatten() + )[0] + except (discord.Forbidden, discord.HTTPException): + log.exception(f"Unable to read message history for {channel.id=}") + await ctx.maybe_send_embed("Unable to read message history for that channel") + return + + em = discord.Embed(description=f"[First Message in {channel.mention}]({message.jump_url})") + em.set_author(name=message.author.display_name, icon_url=message.author.avatar_url) + + await ctx.send(embed=em) diff --git a/firstmessage/info.json b/firstmessage/info.json new file mode 100644 index 0000000..c01766f --- /dev/null +++ b/firstmessage/info.json @@ -0,0 +1,16 @@ +{ + "author": [ + "Bobloy" + ], + "min_bot_version": "3.4.0", + "description": "Simple cog to jump to the first message of a channel easily", + "hidden": false, + "install_msg": "Thank you for installing FirstMessage.\nGet started with `[p]load firstmessage`, then `[p]help FirstMessage`", + "short": "Simple cog to jump to first message of a channel", + "end_user_data_statement": "This cog does not store any End User Data", + "tags": [ + "bobloy", + "utilities", + "tool" + ] +} \ No newline at end of file