Generic changes (#26)
* Make lockdown configuration more generic * pin: Add reaction pinning functionality
This commit is contained in:
parent
2d2adfddc4
commit
3400b94c7c
4 changed files with 99 additions and 11 deletions
|
@ -58,7 +58,8 @@ initial_extensions = ['cogs.common',
|
||||||
'cogs.links',
|
'cogs.links',
|
||||||
'cogs.remind',
|
'cogs.remind',
|
||||||
'cogs.robocronp',
|
'cogs.robocronp',
|
||||||
'cogs.meme']
|
'cogs.meme',
|
||||||
|
'cogs.pin']
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix=get_prefix,
|
bot = commands.Bot(command_prefix=get_prefix,
|
||||||
description=config.bot_description, pm_help=True)
|
description=config.bot_description, pm_help=True)
|
||||||
|
|
|
@ -36,11 +36,12 @@ class Lockdown:
|
||||||
channel = ctx.channel
|
channel = ctx.channel
|
||||||
log_channel = self.bot.get_channel(config.modlog_channel)
|
log_channel = self.bot.get_channel(config.modlog_channel)
|
||||||
|
|
||||||
if channel.id in config.community_channels:
|
for key, lockdown_conf in config.lockdown_configs.items():
|
||||||
roles = [config.named_roles["community"],
|
if channel.id in lockdown_conf["channels"]:
|
||||||
config.named_roles["hacker"]]
|
roles = lockdown_conf["roles"]
|
||||||
else:
|
|
||||||
roles = [config.named_roles["participant"]]
|
if roles is None:
|
||||||
|
roles = config.lockdown_configs["default"]["roles"]
|
||||||
|
|
||||||
for role in roles:
|
for role in roles:
|
||||||
await self.set_sendmessage(channel, role, False, ctx.author)
|
await self.set_sendmessage(channel, role, False, ctx.author)
|
||||||
|
@ -68,11 +69,12 @@ class Lockdown:
|
||||||
channel = ctx.channel
|
channel = ctx.channel
|
||||||
log_channel = self.bot.get_channel(config.modlog_channel)
|
log_channel = self.bot.get_channel(config.modlog_channel)
|
||||||
|
|
||||||
if ctx.channel.id in config.community_channels:
|
for key, lockdown_conf in config.lockdown_configs.items():
|
||||||
roles = [config.named_roles["community"],
|
if channel.id in lockdown_conf["channels"]:
|
||||||
config.named_roles["hacker"]]
|
roles = lockdown_conf["roles"]
|
||||||
else:
|
|
||||||
roles = [config.named_roles["participant"]]
|
if roles is None:
|
||||||
|
roles = config.lockdown_configs["default"]["roles"]
|
||||||
|
|
||||||
await self.unlock_for_staff(channel, ctx.author)
|
await self.unlock_for_staff(channel, ctx.author)
|
||||||
|
|
||||||
|
|
68
cogs/pin.py
Normal file
68
cogs/pin.py
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
import config
|
||||||
|
import pprint
|
||||||
|
from discord.enums import MessageType
|
||||||
|
|
||||||
|
class Pin:
|
||||||
|
"""
|
||||||
|
Allow users to pin things
|
||||||
|
"""
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
# Use raw_reaction to allow pinning old messages.
|
||||||
|
async def on_raw_reaction_add(self, payload):
|
||||||
|
# TODO: handle more than 50 pinned message
|
||||||
|
# BODY: If there are more than 50 pinned messages,
|
||||||
|
# BODY: we should move the oldest pin to a pinboard
|
||||||
|
# BODY: channel to make room for the new pin.
|
||||||
|
# BODY: This is why we use the pin reaction to remember
|
||||||
|
# BODY: that a message is pinned.
|
||||||
|
|
||||||
|
# Check that the user wants to pin this message
|
||||||
|
if payload.emoji.name not in ["📌", "📍"]:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Check that reaction pinning is allowd in this channel
|
||||||
|
if payload.channel_id not in config.allowed_pin_channels:
|
||||||
|
return
|
||||||
|
|
||||||
|
target_guild = self.bot.get_guild(payload.guild_id)
|
||||||
|
if target_guild is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Check that the user is allowed to reaction-pin
|
||||||
|
target_user = target_guild.get_member(payload.user_id)
|
||||||
|
for role in config.staff_role_ids + config.allowed_pin_roles:
|
||||||
|
if role in [role.id for role in target_user.roles]:
|
||||||
|
target_chan = self.bot.get_channel(payload.channel_id)
|
||||||
|
target_msg = await target_chan.get_message(payload.message_id)
|
||||||
|
|
||||||
|
# Check that the message hasn't already been pinned
|
||||||
|
for reaction in target_msg.reactions:
|
||||||
|
if reaction.emoji == "📌":
|
||||||
|
if reaction.me:
|
||||||
|
return
|
||||||
|
break
|
||||||
|
|
||||||
|
# Wait for the automated "Pinned" message so we can delete it
|
||||||
|
waitable = self.bot.wait_for('message', check=check)
|
||||||
|
|
||||||
|
# Pin the message
|
||||||
|
await target_msg.pin()
|
||||||
|
|
||||||
|
# Delete the automated Pinned message
|
||||||
|
msg = await waitable
|
||||||
|
await msg.delete()
|
||||||
|
|
||||||
|
# Add a Pin reaction so we remember that the message is pinned
|
||||||
|
await target_msg.add_reaction("📌")
|
||||||
|
|
||||||
|
# Send custom pinned message
|
||||||
|
await target_chan.send("Pinned!")
|
||||||
|
|
||||||
|
def check(msg):
|
||||||
|
return msg.type is MessageType.pins_add
|
||||||
|
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot.add_cog(Pin(bot))
|
|
@ -66,6 +66,19 @@ community_channels = [269333940928512010,
|
||||||
435687501068501002,
|
435687501068501002,
|
||||||
286612533757083648] # Channels requiring community role
|
286612533757083648] # Channels requiring community role
|
||||||
|
|
||||||
|
# Controls which roles are blocked during lockdown
|
||||||
|
lockdown_configs = {
|
||||||
|
# Used as a default value for channels without a config
|
||||||
|
"default": {
|
||||||
|
"channels": general_channels,
|
||||||
|
"roles": [named_roles["participant"]]
|
||||||
|
},
|
||||||
|
"community": {
|
||||||
|
"channels": community_channels,
|
||||||
|
"roles": [named_roles["community"], named_roles["hacker"]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Mute role is applied to users when they're muted
|
# Mute role is applied to users when they're muted
|
||||||
# As we no longer have mute role on ReSwitched, I set it to 0 here
|
# As we no longer have mute role on ReSwitched, I set it to 0 here
|
||||||
mute_role = 0 # Mute role in ReSwitched
|
mute_role = 0 # Mute role in ReSwitched
|
||||||
|
@ -76,3 +89,7 @@ hourly_clean_channels = []
|
||||||
|
|
||||||
# Edited and deletes messages in these channels will be logged
|
# Edited and deletes messages in these channels will be logged
|
||||||
spy_channels = general_channels
|
spy_channels = general_channels
|
||||||
|
|
||||||
|
# Channels and roles where users can pin messages
|
||||||
|
allowed_pin_channels = []
|
||||||
|
allowed_pin_roles = []
|
||||||
|
|
Loading…
Reference in a new issue