diff options
author | Arjun Satarkar <me@arjunsatarkar.net> | 2023-10-14 23:23:21 +0000 |
---|---|---|
committer | Arjun Satarkar <me@arjunsatarkar.net> | 2023-10-14 23:23:21 +0000 |
commit | 95f5158399c959c67f5d692a49e78b92aff76310 (patch) | |
tree | 500213513245c934df7dc52c24f32c0e930746d3 /pindelegate | |
download | red_cogs-main.tar red_cogs-main.tar.gz red_cogs-main.zip |
Diffstat (limited to 'pindelegate')
-rw-r--r-- | pindelegate/__init__.py | 5 | ||||
-rw-r--r-- | pindelegate/pindelegate.py | 65 |
2 files changed, 70 insertions, 0 deletions
diff --git a/pindelegate/__init__.py b/pindelegate/__init__.py new file mode 100644 index 0000000..dab4b9a --- /dev/null +++ b/pindelegate/__init__.py @@ -0,0 +1,5 @@ +from .pindelegate import PinDelegate + + +async def setup(bot): + await bot.add_cog(PinDelegate(bot)) diff --git a/pindelegate/pindelegate.py b/pindelegate/pindelegate.py new file mode 100644 index 0000000..2b94bf4 --- /dev/null +++ b/pindelegate/pindelegate.py @@ -0,0 +1,65 @@ +import discord +from redbot.core import Config +from redbot.core import checks +from redbot.core import commands + + +class PinDelegate(commands.Cog): + def __init__(self, bot): + self.bot = bot + self.config = Config.get_conf( + self, identifier="551742410770612234|6772870d-1739-4ada-a2c5-1821b4f3a618" + ) + self.config.register_channel(pin_capable_members={}) + + @commands.command() + @checks.admin_or_permissions(administrator=True) + async def pindelegate(self, ctx, user: discord.Member): + async with self.config.channel( + ctx.channel + ).pin_capable_members() as pin_capable_members: + pin_capable_members[user.id] = True + await ctx.reply( + f"User {user.name} ({user.id}) is now pin-capable in this channel." + ) + + @commands.command() + @checks.admin_or_permissions(administrator=True) + async def pinundelegate(self, ctx, user: discord.Member): + async with self.config.channel( + ctx.channel + ).pin_capable_members() as pin_capable_members: + try: + del pin_capable_members[str(user.id)] + except KeyError: + await ctx.reply( + f"User {user.name} ({user.id}) was already not pin-capable in this channel." + ) + return + await ctx.reply( + f"User {user.name} ({user.id}) removed from pin-capable users in this channel." + ) + + async def is_pin_capable(self, channel, member_id): + try: + await self.config.channel(channel).pin_capable_members.get_raw( + str(member_id) + ) + except KeyError: + return False + return True + + @commands.command() + async def pin(self, ctx): + if await self.is_pin_capable(ctx.channel, ctx.author.id): + await ctx.message.reference.resolved.pin() + + @commands.command() + async def unpin(self, ctx): + replied_to_message = ctx.message.reference.resolved + if await self.is_pin_capable(ctx.channel, ctx.author.id): + if replied_to_message.pinned: + await replied_to_message.unpin() + await ctx.reply("Unpinned message!") + else: + await ctx.reply("That message was already not pinned.") |