-
Notifications
You must be signed in to change notification settings - Fork 8
Added toggle for Verify, new default behaviour for welcome message and k!setup #232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4b65ef8
2f19f96
dcf4193
f1c3d11
2e4bfc5
2fab180
69d3927
69f0aee
ba38d53
122d57c
304debd
6fdfe45
c08a688
e82f5d1
378b7b2
24a938c
aa85a26
95d067a
c930433
1da6931
8761098
50e7600
e2d957a
1ec4753
af59bbb
721174e
dd1f097
b5d6a53
ea4bb34
7850f15
b5f2a40
4b1ef73
0646e2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,13 @@ def is_admin(ctx): | |
return ctx.author.guild_permissions.administrator or is_dpytest | ||
|
||
|
||
def terms_agreed(ctx): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
""" | ||
Global check to block access to commands if legal terms aren't agreed with | ||
""" | ||
return DBManager.fetch_guild_setup_status(database_manager, ctx.guild.id) != 0 | ||
|
||
|
||
def is_dm_channel(ctx): | ||
return isinstance(ctx.channel, discord.channel.DMChannel) | ||
|
||
|
@@ -160,6 +167,16 @@ async def on_command_error(ctx, error): | |
elif isinstance(error, commands.CommandOnCooldown): | ||
await ctx.send(embed=error_embed(description=f"{ctx.author.mention}, this command is still on cooldown for " | ||
f"{str(error.retry_after)}s.")) | ||
elif isinstance(error, commands.CheckFailure): | ||
if database_manager.fetch_guild_setup_status(ctx.guild.id) == 0: | ||
await ctx.send(embed=error_embed(description="In order to use this command. You must agree to the Terms & Conditions " \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error doesn't seem to show up. Instead nothing is sent to the user. needs fixing |
||
"of KoalaBot and confirm you have read and understand our Privacy Policy. " \ | ||
"For legal documents relating to this, please view the following link: http://legal.koalabot.uk/ " \ | ||
"Use k!setup to agree.")) | ||
elif not is_admin(ctx): | ||
await ctx.send(embed=error_embed(description="You do not have access to this command as you must be an admin")) | ||
else: | ||
await ctx.send(embed=error_embed(description="Have you enabled the extension")) | ||
else: | ||
await ctx.send(embed=error_embed(description=error)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,12 +25,13 @@ | |
BASE_LEGAL_MESSAGE = """This server utilizes KoalaBot. In joining this server, you agree to the Terms & Conditions of | ||
KoalaBot and confirm you have read and understand our Privacy Policy. For legal documents relating to this, please view | ||
the following link: http://legal.koalabot.uk/""" | ||
DEFAULT_WELCOME_MESSAGE = "Hello. This is a default welcome message because the guild that this came from did not configure a welcome message! Please see below." | ||
DEFAULT_WELCOME_MESSAGE = "" | ||
# Variables | ||
DBManager = KoalaDBManager.KoalaDBManager(KoalaBot.DATABASE_PATH, KoalaBot.DB_KEY) | ||
|
||
|
||
def wait_for_message(bot: discord.Client, ctx: commands.Context, timeout=60.0) -> (discord.Message, discord.TextChannel): | ||
def wait_for_message(bot: discord.Client, ctx: commands.Context, timeout=60.0) -> ( | ||
discord.Message, discord.TextChannel): | ||
try: | ||
confirmation = bot.wait_for('message', timeout=timeout, check=lambda message: message.author == ctx.author) | ||
return confirmation | ||
|
@@ -72,7 +73,11 @@ def get_guild_welcome_message(guild_id: int): | |
msg = DBManager.fetch_guild_welcome_message(guild_id) | ||
if msg is None: | ||
msg = DBManager.new_guild_welcome_message(guild_id) | ||
return f"{msg}\r\n{BASE_LEGAL_MESSAGE}" | ||
return msg | ||
elif msg == "": | ||
return msg | ||
else: | ||
return f"{msg}\r\n{BASE_LEGAL_MESSAGE}" | ||
|
||
|
||
def get_non_bot_members(guild: discord.Guild): | ||
|
@@ -88,35 +93,61 @@ class IntroCog(commands.Cog, name="KoalaBot"): | |
""" | ||
|
||
def __init__(self, bot): | ||
|
||
self.bot = bot | ||
|
||
async def send_setup_message(self, guild): | ||
""" | ||
On bot joining guild, sends the basic legal information to the server, blocks access to the bot commands until | ||
legal terms are agreed | ||
:param guild: Guild object of the guild you are sending the setup message to. | ||
""" | ||
setup_message = "In order for KoalaBot to store data on this server, you must agree to the Terms & Conditions " \ | ||
"of KoalaBot and confirm you have read and understand our Privacy Policy. " \ | ||
"For legal documents relating to this, please view the following link: http://legal.koalabot.uk/ " \ | ||
"Use k!setup to agree" | ||
for channel in guild.text_channels: | ||
if channel.permissions_for(guild.me).send_messages: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if it doesn't have access, what happens? Also this would be very infuriating to most people as when joining KoalaBot may post in a public announcement channel. Instead it would be best to DM the user that invited Koala, or just wait to send this message when a Koala command is sent in any channel, and respond with this instead |
||
await channel.send(setup_message) | ||
break | ||
|
||
@commands.Cog.listener() | ||
async def on_guild_join(self, guild: discord.Guild): | ||
""" | ||
On bot joining guild, add this guild to the database of guild welcome messages. | ||
Also sets up the status of the guild | ||
:param guild: Guild KoalaBot just joined | ||
""" | ||
DBManager.new_guild_welcome_message(guild.id) | ||
DBManager.insert_setup_status(guild.id) | ||
KoalaBot.logger.info(f"KoalaBot joined new guild, id = {guild.id}, name = {guild.name}.") | ||
await self.send_setup_message(guild) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move to the failed terms agreed check |
||
|
||
@commands.Cog.listener() | ||
async def on_member_join(self, member: discord.Member): | ||
""" | ||
On member joining guild, send DM to member with welcome message. | ||
On member joining guild, send DM to member with welcome message, if the server opts for this option | ||
:param member: Member which just joined guild | ||
""" | ||
await KoalaBot.dm_group_message([member], get_guild_welcome_message(member.guild.id)) | ||
KoalaBot.logger.info(f"New member {member.name} joined guild id {member.guild.id}. Sent them welcome message.") | ||
if get_guild_welcome_message(member.guild.id) == "" or get_guild_welcome_message(member.guild.id) is None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it not be best to get the welcome message once, and store as a variable? removes multiple redundant DB queries being run |
||
KoalaBot.logger.info( | ||
f"New member {member.name} joined guild id {member.guild.id}. No welcome message set up.") | ||
else: | ||
await KoalaBot.dm_group_message([member], get_guild_welcome_message(member.guild.id)) | ||
KoalaBot.logger.info( | ||
f"New member {member.name} joined guild id {member.guild.id}. Sent them welcome message.") | ||
|
||
@commands.Cog.listener() | ||
async def on_guild_remove(self, guild: discord.Guild): | ||
""" | ||
On bot leaving guild, remove the guild from the database of guild welcome messages | ||
:param guild: Guild KoalaBot just left | ||
""" | ||
DBManager.remove_guild_status(guild.id) | ||
count = DBManager.remove_guild_welcome_message(guild.id) | ||
KoalaBot.logger.info( | ||
f"KoalaBot left guild, id = {guild.id}, name = {guild.name}. Removed {count} rows from GuildWelcomeMessages") | ||
f"KoalaBot left guild, id = {guild.id}, name = {guild.name}. Removed {count} rows from GuildWelcomeMessages" | ||
f"Removed guild status for id = {guild.id}") | ||
|
||
@commands.cooldown(1, 60, commands.BucketType.guild) | ||
@commands.check(KoalaBot.is_admin) | ||
|
@@ -145,13 +176,15 @@ async def send_welcome_message(self, ctx): | |
return False | ||
|
||
@commands.cooldown(1, 60, commands.BucketType.guild) | ||
@commands.check(KoalaBot.terms_agreed) | ||
@commands.check(KoalaBot.is_admin) | ||
@commands.command(name="welcomeUpdateMsg", aliases=["update_welcome_message"]) | ||
async def update_welcome_message(self, ctx, *, new_message: str): | ||
""" | ||
"""` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. was this change intentional? |
||
Allows admins to change their customisable part of the welcome message of a guild. Has a 60 second cooldown per | ||
guild. | ||
|
||
|
||
:param ctx: Context of the command | ||
:param new_message: New customised part of the welcome message | ||
""" | ||
|
@@ -175,6 +208,7 @@ async def update_welcome_message(self, ctx, *, new_message: str): | |
except None: | ||
await ctx.send("Something went wrong, please contact the bot developers for support.") | ||
else: | ||
|
||
await ctx.send("Okay, I won't update the welcome message then.") | ||
|
||
@commands.check(KoalaBot.is_admin) | ||
|
@@ -190,6 +224,15 @@ async def on_update_error(self, ctx, error): | |
if isinstance(error, discord.ext.commands.MissingRequiredArgument): | ||
await ctx.send('Please put in a welcome message to update to.') | ||
|
||
@commands.check(KoalaBot.is_admin) | ||
@commands.command() | ||
async def setup(self, ctx): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead it would be good to have a wait_for with a link to the terms and conditions as people may not have seen the terms and conditions yet. Instead, conversation should be:
either:
or:
|
||
""" | ||
Allows access to configure the bot, once legal terms are agreed | ||
""" | ||
DBManager.update_guild_setup_status(ctx.guild.id) | ||
await ctx.send("Terms and Conditions agreed, you can now configure the bot") | ||
|
||
|
||
def setup(bot: KoalaBot) -> None: | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changelog should be in the same format as previously. Use subheadings for different Cogs/ base KoalaBot, and 'other' for anything else mainly dev related