mirror of
https://github.com/brandons209/Red-bot-Cogs.git
synced 2024-06-02 18:45:17 +12:00
added seperate channels for leave and ban events
This commit is contained in:
parent
ceecffa25e
commit
32876be417
|
@ -51,3 +51,4 @@ turn
|
||||||
cah
|
cah
|
||||||
pupper
|
pupper
|
||||||
pingtime
|
pingtime
|
||||||
|
quotetools
|
||||||
|
|
|
@ -33,6 +33,8 @@ class Welcome(getattr(commands, "Cog", object)):
|
||||||
guild_defaults = {
|
guild_defaults = {
|
||||||
'enabled': False,
|
'enabled': False,
|
||||||
'channel': None,
|
'channel': None,
|
||||||
|
'leave_channel': None,
|
||||||
|
'ban_channel': None,
|
||||||
'date': None,
|
'date': None,
|
||||||
'join': {
|
'join': {
|
||||||
'enabled': True,
|
'enabled': True,
|
||||||
|
@ -83,7 +85,9 @@ class Welcome(getattr(commands, "Cog", object)):
|
||||||
guild = ctx.guild
|
guild = ctx.guild
|
||||||
c = await self.config.guild(guild).all()
|
c = await self.config.guild(guild).all()
|
||||||
|
|
||||||
channel = await self.__get_channel(ctx.guild)
|
channel = await self.__get_channel(ctx.guild, "join")
|
||||||
|
leave_channel = await self.__get_channel(ctx.guild, "leave")
|
||||||
|
ban_channel = await self.__get_channel(ctx.guild, "ban")
|
||||||
|
|
||||||
j = c['join']
|
j = c['join']
|
||||||
jw = j['whisper']
|
jw = j['whisper']
|
||||||
|
@ -96,7 +100,9 @@ class Welcome(getattr(commands, "Cog", object)):
|
||||||
emb.add_field(name="General", value=(
|
emb.add_field(name="General", value=(
|
||||||
"**Enabled:** {}\n"
|
"**Enabled:** {}\n"
|
||||||
"**Channel:** #{}\n"
|
"**Channel:** #{}\n"
|
||||||
).format(c['enabled'], channel))
|
"**Leave Channel:** #{}\n"
|
||||||
|
"**Ban/Unban Channel:** #{}\n"
|
||||||
|
).format(c['enabled'], channel, leave_channel, ban_channel))
|
||||||
emb.add_field(name="Join", value=(
|
emb.add_field(name="Join", value=(
|
||||||
"**Enabled:** {}\n"
|
"**Enabled:** {}\n"
|
||||||
"**Delete previous:** {}\n"
|
"**Delete previous:** {}\n"
|
||||||
|
@ -194,6 +200,44 @@ class Welcome(getattr(commands, "Cog", object)):
|
||||||
"").format(channel)
|
"").format(channel)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@welcomeset.command(name='leave-channel')
|
||||||
|
async def welcomeset_leave_channel(self, ctx: commands.Context, channel: discord.TextChannel):
|
||||||
|
"""Sets the channel to be used for leave_channel event notices."""
|
||||||
|
|
||||||
|
if not self.__can_speak_in(channel):
|
||||||
|
await ctx.send(
|
||||||
|
("I do not have permission to send messages in {0.mention}. Check your permission settings and try again."
|
||||||
|
"").format(channel)
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
guild = ctx.guild
|
||||||
|
await self.config.guild(guild).leave_channel.set(channel.id)
|
||||||
|
|
||||||
|
await ctx.send(
|
||||||
|
("I will now send leave event notices to {0.mention}."
|
||||||
|
"").format(channel)
|
||||||
|
)
|
||||||
|
|
||||||
|
@welcomeset.command(name='ban-channel')
|
||||||
|
async def welcomeset_channel(self, ctx: commands.Context, channel: discord.TextChannel):
|
||||||
|
"""Sets the channel to be used for event notices."""
|
||||||
|
|
||||||
|
if not self.__can_speak_in(channel):
|
||||||
|
await ctx.send(
|
||||||
|
("I do not have permission to send messages in {0.mention}. Check your permission settings and try again."
|
||||||
|
"").format(channel)
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
guild = ctx.guild
|
||||||
|
await self.config.guild(guild).ban_channel.set(channel.id)
|
||||||
|
|
||||||
|
await ctx.send(
|
||||||
|
("I will now send ban/unban event notices to {0.mention}."
|
||||||
|
"").format(channel)
|
||||||
|
)
|
||||||
|
|
||||||
@welcomeset.group(name='join')
|
@welcomeset.group(name='join')
|
||||||
async def welcomeset_join(self, ctx: commands.Context):
|
async def welcomeset_join(self, ctx: commands.Context):
|
||||||
"""Change settings for join notices."""
|
"""Change settings for join notices."""
|
||||||
|
@ -237,7 +281,7 @@ class Welcome(getattr(commands, "Cog", object)):
|
||||||
|
|
||||||
guild = ctx.guild
|
guild = ctx.guild
|
||||||
whisper_type = choice.value
|
whisper_type = choice.value
|
||||||
channel = await self.__get_channel(ctx.guild)
|
channel = await self.__get_channel(ctx.guild, "join")
|
||||||
|
|
||||||
await self.config.guild(guild).join.whisper.state.set(whisper_type)
|
await self.config.guild(guild).join.whisper.state.set(whisper_type)
|
||||||
|
|
||||||
|
@ -673,7 +717,7 @@ class Welcome(getattr(commands, "Cog", object)):
|
||||||
|
|
||||||
if settings['delete'] and settings['last'] is not None:
|
if settings['delete'] and settings['last'] is not None:
|
||||||
# we need to delete the previous message
|
# we need to delete the previous message
|
||||||
await self.__delete_message(guild, settings['last'])
|
await self.__delete_message(guild, settings['last'], event)
|
||||||
# regardless of success, remove reference to that message
|
# regardless of success, remove reference to that message
|
||||||
await guild_settings.get_attr(event).last.set(None)
|
await guild_settings.get_attr(event).last.set(None)
|
||||||
|
|
||||||
|
@ -682,7 +726,7 @@ class Welcome(getattr(commands, "Cog", object)):
|
||||||
# store it for (possible) deletion later
|
# store it for (possible) deletion later
|
||||||
await guild_settings.get_attr(event).last.set(new_message and new_message.id)
|
await guild_settings.get_attr(event).last.set(new_message and new_message.id)
|
||||||
|
|
||||||
async def __get_channel(self, guild: discord.Guild) -> discord.TextChannel:
|
async def __get_channel(self, guild: discord.Guild, event: str) -> discord.TextChannel:
|
||||||
"""Gets the best text channel to use for event notices.
|
"""Gets the best text channel to use for event notices.
|
||||||
|
|
||||||
Order of priority:
|
Order of priority:
|
||||||
|
@ -693,7 +737,15 @@ class Welcome(getattr(commands, "Cog", object)):
|
||||||
|
|
||||||
channel = None
|
channel = None
|
||||||
|
|
||||||
channel_id = await self.config.guild(guild).channel()
|
if event == 'join':
|
||||||
|
channel_id = await self.config.guild(guild).channel()
|
||||||
|
elif event == 'leave':
|
||||||
|
channel_id = await self.config.guild(guild).leave_channel()
|
||||||
|
elif event == 'ban' or event == 'unban':
|
||||||
|
channel_id = await self.config.guild(guild).ban_channel()
|
||||||
|
else:
|
||||||
|
raise TypeError("Wrong event type in __get_channel.")
|
||||||
|
|
||||||
if channel_id is not None:
|
if channel_id is not None:
|
||||||
channel = guild.get_channel(channel_id)
|
channel = guild.get_channel(channel_id)
|
||||||
|
|
||||||
|
@ -733,11 +785,11 @@ class Welcome(getattr(commands, "Cog", object)):
|
||||||
else:
|
else:
|
||||||
return int(msg.content)
|
return int(msg.content)
|
||||||
|
|
||||||
async def __delete_message(self, guild: discord.Guild, message_id: int):
|
async def __delete_message(self, guild: discord.Guild, message_id: int, event: str):
|
||||||
"""Attempts to delete the message with the given ID."""
|
"""Attempts to delete the message with the given ID."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await (await (await self.__get_channel(guild)).fetch_message(message_id)).delete()
|
await (await (await self.__get_channel(guild, event)).fetch_message(message_id)).delete()
|
||||||
except discord.NotFound:
|
except discord.NotFound:
|
||||||
log.warning(
|
log.warning(
|
||||||
("Failed to delete message (ID {}): not found"
|
("Failed to delete message (ID {}): not found"
|
||||||
|
@ -765,7 +817,7 @@ class Welcome(getattr(commands, "Cog", object)):
|
||||||
if count and count != 1:
|
if count and count != 1:
|
||||||
plural = 's'
|
plural = 's'
|
||||||
|
|
||||||
channel = await self.__get_channel(guild)
|
channel = await self.__get_channel(guild, event)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return await channel.send(
|
return await channel.send(
|
||||||
|
|
Loading…
Reference in a new issue