blob: 94d5425f05561546c85d8b0aa0999bfe190a7918 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
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):
"""
Grant a user the ability to pin messages in this channel with the pin command.
"""
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):
"""
Remove a user's ability to pin messages in this channel.
"""
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):
"""
Pin the replied-to message.
"""
if await self.is_pin_capable(ctx.channel, ctx.author.id):
await ctx.message.reference.resolved.pin(
reason=f"On behalf of {ctx.author.name}"
)
@commands.command()
async def unpin(self, ctx):
"""
Unpin the replied-to message.
"""
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(reason=f"On behalf of {ctx.author.name}")
await ctx.reply("Unpinned message!")
else:
await ctx.reply("That message was already not pinned.")
|