1
0
Fork 0
mirror of synced 2024-05-19 20:12:30 +12:00

Add the ability to set custom welcome/goodbye messages

This commit is contained in:
phxntxm 2017-06-28 04:58:53 -05:00
parent fe7f57e9bb
commit cc35fa377b
2 changed files with 40 additions and 6 deletions

View file

@ -453,7 +453,7 @@ class Administration:
@commands.command(aliases=['notifications'])
@commands.guild_only()
@utils.custom_perms(kick_members=True)
@utils.custom_perms(manage_guild=True)
@utils.check_restricted()
async def alerts(self, ctx, channel: discord.TextChannel):
"""This command is used to set a channel as the server's default 'notifications' channel
@ -474,9 +474,9 @@ class Administration:
await ctx.send("I have just changed this server's default 'notifications' channel"
"\nAll notifications will now default to `{}`".format(channel))
@commands.group(invoke_without_command=True)
@commands.group(invoke_without_command=True, aliases=['goodbye'])
@commands.guild_only()
@utils.custom_perms(kick_members=True)
@utils.custom_perms(manage_guild=True)
@utils.check_restricted()
async def welcome(self, ctx, on_off: str):
"""This command can be used to set whether or not you want user notificaitons to show
@ -500,7 +500,7 @@ class Administration:
@welcome.command(name='alerts', aliases=['notifications'])
@commands.guild_only()
@utils.custom_perms(kick_members=True)
@utils.custom_perms(manage_guild=True)
@utils.check_restricted()
async def _welcome_alerts(self, ctx, *, channel: discord.TextChannel):
"""A command used to set the override for notifications about users joining/leaving
@ -518,6 +518,32 @@ class Administration:
await ctx.send(
"I have just changed this server's welcome/goodbye notifications channel to {}".format(channel.name))
@welcome.command(name='message')
@commands.guild_only()
@utils.custom_perms(manage_guild=True)
@utils.check_restricted()
async def _welcome_message(self, ctx, *, msg = None):
"""A command to customize the welcome/goodbye message
There are a couple things that can be set to customize the message
{member} - Will mention the user joining
{server} - Will display the server's name
Give no message and it will be set to the default
EXAMPLE: !welcome message {member} to {server}
RESULT: Welcome Member#1234 to ServerName"""
parent = ctx.message.content.split()[0]
parent = parent[len(ctx.prefix):]
if re.search("{.*token.*}", msg):
await ctx.send("Illegal content in {} message".format(parent))
else:
entry = {
'server_id': str(ctx.message.guild.id),
parent + '_message': msg
}
self.bot.db.save('server_settings', entry)
await ctx.send("I have just updated your {} message".format(parent))
@commands.group()
@utils.check_restricted()
async def nsfw(self, ctx):

View file

@ -66,6 +66,10 @@ class StatsUpdate:
default_channel_id = notifications.get('default') or guild.id
# If it is has been overriden by picarto notifications setting, use this
channel_id = notifications.get('welcome') or default_channel_id
# Get the message if it exists
join_message = self.bot.db.load('server_settings', key=guild.id, pluck='welcome_message')
if not join_message:
join_message = "Welcome to the '{server.name}' server {member}!"
else:
return
except (IndexError, TypeError, KeyError):
@ -73,7 +77,7 @@ class StatsUpdate:
channel = guild.get_channel(int(channel_id))
try:
await channel.send("Welcome to the '{0.guild.name}' server {0.mention}!".format(member))
await channel.send(join_message.format(server=member.server.name, member=member.mention))
except (discord.Forbidden, discord.HTTPException):
pass
@ -90,6 +94,10 @@ class StatsUpdate:
default_channel_id = notifications.get('default') or guild.id
# If it is has been overriden by picarto notifications setting, use this
channel_id = notifications.get('welcome') or default_channel_id
# Get the message if it exists
leave_message = self.bot.db.load('server_settings', key=guild.id, pluck='goodbye_message')
if not leave_message:
leave_message = "{member} has left the server, I hope it wasn't because of something I said :c"
else:
return
except (IndexError, TypeError, KeyError):
@ -97,7 +105,7 @@ class StatsUpdate:
channel = guild.get_channel(int(channel_id))
try:
await channel.send("{0} has left the server, I hope it wasn't because of something I said :c".format(member.display_name))
await channel.send(leave_message.format(server=member.server.name, member=member.mention))
except (discord.Forbidden, discord.HTTPException):
pass