Add a way to have Bonfire add a role to someone when they join a server
This commit is contained in:
parent
a211fe3048
commit
be971dda94
|
@ -209,6 +209,16 @@ class GuildConfiguration:
|
|||
else:
|
||||
return "This server has no custom hugs"
|
||||
|
||||
async def _handle_show_join_role(self, ctx, opt):
|
||||
result = await ctx.bot.db.fetchrow("SELECT join_role FROM guilds WHERE id = $1", ctx.guild.id)
|
||||
|
||||
if result['join_role']:
|
||||
role = ctx.bot.get_role(result['join_role'])
|
||||
if role is None:
|
||||
return "You had a role set, but I can't find it...it's most likely been deleted afterwords!"
|
||||
else:
|
||||
return f"When people join I will give them the role {role.name}"
|
||||
|
||||
async def _handle_set_birthday_notifications(self, ctx, setting):
|
||||
opt = "birthday_notifications"
|
||||
setting = self._str_to_bool(opt, setting)
|
||||
|
@ -402,6 +412,21 @@ WHERE
|
|||
"""
|
||||
return await ctx.bot.db.execute(query, setting, ctx.guild.id)
|
||||
|
||||
async def _handle_set_join_role(self, ctx, setting):
|
||||
converter = commands.converter.RoleConverter()
|
||||
role = await converter.convert(ctx, setting)
|
||||
|
||||
query = """
|
||||
UPDATE
|
||||
guilds
|
||||
SET
|
||||
join_role = $1
|
||||
where
|
||||
ID=$2
|
||||
"""
|
||||
|
||||
return await ctx.bot.db.execute(query, role.id, ctx.guild.id)
|
||||
|
||||
async def _handle_remove_birthday_notifications(self, ctx, setting=None):
|
||||
return await self._set_db_guild_opt("birthday_notifications", False, ctx)
|
||||
|
||||
|
@ -447,6 +472,9 @@ WHERE
|
|||
async def _handle_remove_raffle_alerts(self, ctx, setting=None):
|
||||
return await self._set_db_guild_opt("raffle_alerts", None, ctx)
|
||||
|
||||
async def _handle_remove_join_role(self, ctx, setting=None):
|
||||
return await self._set_db_guild_opt("join_role", None, ctx)
|
||||
|
||||
async def _handle_remove_followed_picarto_channels(self, ctx, setting=None):
|
||||
if setting is None:
|
||||
raise WrongSettingType("Specifying which channel you want to remove is required")
|
||||
|
|
|
@ -72,22 +72,30 @@ class StatsUpdate:
|
|||
query = """
|
||||
SELECT
|
||||
COALESCE(welcome_alerts, default_alerts) AS channel,
|
||||
welcome_msg AS msg
|
||||
welcome_msg AS msg,
|
||||
join_role as role
|
||||
FROM
|
||||
guilds
|
||||
WHERE
|
||||
welcome_notifications = True
|
||||
AND
|
||||
id = $1
|
||||
AND
|
||||
COALESCE(welcome_alerts, default_alerts) IS NOT NULL
|
||||
"""
|
||||
settings = await self.bot.db.fetchrow(query, member.guild.id)
|
||||
if settings:
|
||||
message = settings['msg'] or "Welcome to the '{server}' server {member}!"
|
||||
channel = member.guild.get_channel(settings['channel'])
|
||||
try:
|
||||
channel = member.guild.get_channel(settings['channel'])
|
||||
await channel.send(message.format(server=member.guild.name, member=member.mention))
|
||||
# Forbidden for if the channel has send messages perms off
|
||||
# HTTP Exception to catch any weird happenings
|
||||
# Attribute Error catches when a channel is set, but that channel doesn't exist any more
|
||||
except (discord.Forbidden, discord.HTTPException, AttributeError):
|
||||
pass
|
||||
|
||||
try:
|
||||
role = member.guild.get_role(settings['role'])
|
||||
await member.add_roles(role)
|
||||
except (discord.Forbidden, discord.HTTPException, AttributeError):
|
||||
pass
|
||||
|
||||
|
|
Loading…
Reference in a new issue