Skip to content

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

Draft
wants to merge 33 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4b65ef8
feat: when there is no welcome message set up it will not send a welc…
jplam123 Jul 23, 2021
2f19f96
feat: added lack of message when one isn't initialised
jplam123 Jul 23, 2021
dcf4193
Added setup command that is required before any data on a server is s…
Jaddison011 Jul 23, 2021
f1c3d11
Merge branch 'WERemoveCog' of https://github.com/KoalaBotUK/KoalaBot …
Jaddison011 Jul 23, 2021
2e4bfc5
Added functionality for blocking commands
Jaddison011 Jul 23, 2021
2fab180
fixed: tests for the new behaviour of koala bot.
jplam123 Jul 23, 2021
69d3927
fixed: bot.check -> commands.check
jplam123 Jul 23, 2021
69f0aee
Fixed: Welcome message error, now posts to first available channel
jplam123 Jul 26, 2021
ba38d53
feat:added table for guild setup status
jplam123 Jul 26, 2021
122d57c
terms agreed global check now uses SQL database
Jaddison011 Jul 26, 2021
304debd
feat: fixed the setup status, added checks to commands and a special …
jplam123 Jul 27, 2021
6fdfe45
feat: added checks for GDPR reasons to ColourRole, RFR and TextFilter
jplam123 Jul 27, 2021
c08a688
Added some command blocking when legal terms aren't agreed
Jaddison011 Jul 27, 2021
e82f5d1
Merge branch 'WERemoveCog' of https://github.com/KoalaBotUK/KoalaBot …
Jaddison011 Jul 27, 2021
378b7b2
Added command to toggle verify DM for a guild on user joining a guild
Jaddison011 Jul 28, 2021
24a938c
Added email_list_status table
Jaddison011 Jul 28, 2021
aa85a26
fixed: some tests, along with some sql query issues.
jplam123 Jul 28, 2021
95d067a
Fixed some tests
Jaddison011 Jul 28, 2021
c930433
Fixed: Verification cog, and testing
jplam123 Jul 28, 2021
1da6931
Fixed some tests again
Jaddison011 Jul 29, 2021
8761098
Fixed a broken test
Jaddison011 Jul 29, 2021
50e7600
Fixed: Tests now work with the new statuses, as well as small issues …
jplam123 Jul 29, 2021
e2d957a
feat: added docstrings to a few methods and formatted according the PEP8
jplam123 Jul 29, 2021
1ec4753
feat: added to changelog
jplam123 Jul 29, 2021
af59bbb
Updated documentation.json to include the new commands
Jaddison011 Jul 29, 2021
721174e
feat: added more tests to improve coverage
jplam123 Jul 30, 2021
dd1f097
Fixed some syntax errors in documentation.json
Jaddison011 Aug 4, 2021
b5d6a53
Merge branch 'WERemoveCog' of https://github.com/KoalaBotUK/KoalaBot …
Jaddison011 Aug 4, 2021
ea4bb34
Added doc string for added methods
Jaddison011 Aug 4, 2021
7850f15
Added tests for database methods
Jaddison011 Aug 4, 2021
b5f2a40
Merge branch 'master' into WERemoveCog
jplam123 Aug 5, 2021
4b1ef73
Removed unused imports
Jaddison011 Aug 5, 2021
0646e2f
Update cogs/Verification.py
jplam123 Aug 11, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ All notable changes to KoalaBot will be documented in this file.
A lot of these commands will only be available to administrators

## [Unreleased]
### 29-07-2021
Copy link
Member

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

Added new default behaviour for welcome messages, they do not happen by default unless one is updated with a welcome message.

`k!setup` This blocks all possible sensitive commands until the command is called in the guild by an admin

`k!verifyDM <Bool>` This toggles between having the verification welcome DM on or off
### Other
- Testing updated to use builders in dpytest 0.5.0
### Colour Role
Expand Down
17 changes: 17 additions & 0 deletions KoalaBot.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def is_admin(ctx):
return ctx.author.guild_permissions.administrator or is_dpytest


def terms_agreed(ctx):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When this fails, a 'list index out of range' error is given, either displayed in console, or to the user. This should not be visible.
image
image

"""
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)

Expand Down Expand Up @@ -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 " \
Copy link
Member

Choose a reason for hiding this comment

The 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))

Expand Down
16 changes: 12 additions & 4 deletions cogs/Announce.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
MAX_MESSAGE_LENGTH = 2000




def announce_is_enabled(ctx):
"""
A command used to check if the guild has enabled announce
Expand Down Expand Up @@ -131,6 +129,7 @@ async def announce(self, ctx):
if ctx.invoked_subcommand is None:
await ctx.send(f"Please use `{KoalaBot.COMMAND_PREFIX}help announce` for more information")

@commands.check(KoalaBot.terms_agreed)
@commands.check(announce_is_enabled)
@announce.command(name="create")
async def create(self, ctx):
Expand Down Expand Up @@ -166,6 +165,7 @@ async def create(self, ctx):
await ctx.send(embed=self.construct_embed(ctx.guild))
await ctx.send(self.receiver_msg(ctx.guild))

@commands.check(KoalaBot.terms_agreed)
@commands.check(announce_is_enabled)
@announce.command(name="changeTitle")
async def change_title(self, ctx):
Expand All @@ -185,6 +185,7 @@ async def change_title(self, ctx):
else:
await ctx.send("There is currently no active announcement")

@commands.check(KoalaBot.terms_agreed)
@commands.check(announce_is_enabled)
@announce.command(name="changeContent")
async def change_content(self, ctx):
Expand All @@ -207,6 +208,7 @@ async def change_content(self, ctx):
else:
await ctx.send("There is currently no active announcement")

@commands.check(KoalaBot.terms_agreed)
@commands.check(announce_is_enabled)
@announce.command(name="addRole", aliases=["add"])
async def add_role(self, ctx):
Expand All @@ -216,7 +218,8 @@ async def add_role(self, ctx):
:return:
"""
if self.has_active_msg(ctx.guild.id):
await ctx.send("Please enter the roles you want to tag separated by space, I'll wait for 60 seconds, no rush.")
await ctx.send(
"Please enter the roles you want to tag separated by space, I'll wait for 60 seconds, no rush.")
message, channel = await wait_for_message(self.bot, ctx)
if not message:
await channel.send("Okay, I'll cancel the command.")
Expand All @@ -230,6 +233,7 @@ async def add_role(self, ctx):
else:
await ctx.send("There is currently no active announcement")

@commands.check(KoalaBot.terms_agreed)
@commands.check(announce_is_enabled)
@announce.command(name="removeRole", aliases=["remove"])
async def remove_role(self, ctx):
Expand All @@ -239,7 +243,8 @@ async def remove_role(self, ctx):
:return:
"""
if self.has_active_msg(ctx.guild.id):
await ctx.send("Please enter the roles you want to remove separated by space, I'll wait for 60 seconds, no rush.")
await ctx.send(
"Please enter the roles you want to remove separated by space, I'll wait for 60 seconds, no rush.")
message, channel = await wait_for_message(self.bot, ctx)
if not message:
await channel.send("Okay, I'll cancel the command.")
Expand All @@ -252,6 +257,7 @@ async def remove_role(self, ctx):
else:
await ctx.send("There is currently no active announcement")

@commands.check(KoalaBot.terms_agreed)
@commands.check(announce_is_enabled)
@announce.command(name="preview")
async def preview(self, ctx):
Expand All @@ -266,6 +272,7 @@ async def preview(self, ctx):
else:
await ctx.send("There is currently no active announcement")

@commands.check(KoalaBot.terms_agreed)
@commands.check(announce_is_enabled)
@announce.command(name="send")
async def send(self, ctx):
Expand All @@ -289,6 +296,7 @@ async def send(self, ctx):
else:
await ctx.send("There is currently no active announcement")

@commands.check(KoalaBot.terms_agreed)
@commands.check(announce_is_enabled)
@announce.command(name="cancel")
async def cancel(self, ctx):
Expand Down
3 changes: 3 additions & 0 deletions cogs/BaseCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ async def unload_cog(self, ctx, extension):
await ctx.send(f'{extension} Cog Unloaded')

@commands.command(name="enableExt", aliases=["enable_koala_ext"])
@commands.check(KoalaBot.terms_agreed)
@commands.check(KoalaBot.is_admin)
async def enable_koala_ext(self, ctx, koala_extension):
"""
Expand All @@ -195,6 +196,7 @@ async def enable_koala_ext(self, ctx, koala_extension):
await ctx.send(embed=embed)

@commands.command(name="disableExt", aliases=["disable_koala_ext"])
@commands.check(KoalaBot.terms_agreed)
@commands.check(KoalaBot.is_admin)
async def disable_koala_ext(self, ctx, koala_extension):
"""
Expand All @@ -215,6 +217,7 @@ async def disable_koala_ext(self, ctx, koala_extension):
await ctx.send(embed=embed)

@commands.command(name="listExt", aliases=["list_koala_ext"])
@commands.check(KoalaBot.terms_agreed)
@commands.check(KoalaBot.is_admin)
async def list_koala_ext(self, ctx):
"""
Expand Down
7 changes: 7 additions & 0 deletions cogs/ColourRole.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def get_colour_from_hex_str(self, colour_str: str) -> discord.Colour:
@commands.cooldown(1, 15, commands.BucketType.member)
@commands.check(is_allowed_to_change_colour)
@commands.check(colour_is_enabled)
@commands.check(KoalaBot.terms_agreed)
@commands.command(name="customColour", aliases=["custom_colour", "customColor", "custom_color"])
async def custom_colour(self, ctx: commands.Context, colour_str: str):
"""
Expand Down Expand Up @@ -399,6 +400,7 @@ def role_already_exists(ctx: commands.Context, colour_str: str):
return role_name in [role.name for role in guild.roles]

@commands.check(KoalaBot.is_admin)
@commands.check(KoalaBot.terms_agreed)
@commands.check(colour_is_enabled)
@commands.command(name="listProtectedRoleColours",
aliases=["list_protected_role_colours", "listInvalidCustomColours", "listProtectedRoleColors",
Expand All @@ -419,6 +421,7 @@ async def list_protected_role_colours(self, ctx: commands.Context):
await ctx.send(msg[:-1])

@commands.check(KoalaBot.is_admin)
@commands.check(KoalaBot.terms_agreed)
@commands.check(colour_is_enabled)
@commands.command(name="listCustomColourAllowedRoles",
aliases=["list_custom_colour_allowed_roles"])
Expand Down Expand Up @@ -468,6 +471,7 @@ def get_protected_roles(self, guild: discord.Guild) -> List[discord.Role]:

@commands.check(KoalaBot.is_admin)
@commands.check(colour_is_enabled)
@commands.check(KoalaBot.terms_agreed)
@commands.command(name="addProtectedRoleColour",
aliases=["add_protected_role_colour", "addInvalidCustomColourRole", "addInvalidCustomColorRole",
"addProtectedRoleColor"])
Expand All @@ -488,6 +492,7 @@ async def add_protected_role_colour(self, ctx: commands.Context, *, role_str: st
await self.rearrange_custom_colour_role_positions(ctx.guild)

@commands.check(KoalaBot.is_admin)
@commands.check(KoalaBot.terms_agreed)
@commands.check(colour_is_enabled)
@commands.command(name="removeProtectedRoleColour",
aliases=["remove_protected_role_colour", "removeProtectedRoleColor",
Expand All @@ -509,6 +514,7 @@ async def remove_protected_role_colour(self, ctx: commands.Context, *, role_str:
await self.rearrange_custom_colour_role_positions(ctx.guild)

@commands.check(KoalaBot.is_admin)
@commands.check(KoalaBot.terms_agreed)
@commands.check(colour_is_enabled)
@commands.command(name="addCustomColourAllowedRole",
aliases=["add_custom_colour_allowed_role", "addCustomColorAllowedRole"])
Expand All @@ -528,6 +534,7 @@ async def add_custom_colour_allowed_role(self, ctx: commands.Context, *, role_st
await ctx.send(f"Added {role.mention} to the list of roles allowed to have a custom colour.")

@commands.check(KoalaBot.is_admin)
@commands.check(KoalaBot.terms_agreed)
@commands.check(colour_is_enabled)
@commands.command(name="removeCustomColourAllowedRole",
aliases=["remove_custom_colour_allowed_role", "removeCustomColorAllowedRole"])
Expand Down
59 changes: 51 additions & 8 deletions cogs/IntroCog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The 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)
Copy link
Member

Choose a reason for hiding this comment

The 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:
Copy link
Member

Choose a reason for hiding this comment

The 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)
Expand Down Expand Up @@ -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):
"""
"""`
Copy link
Member

Choose a reason for hiding this comment

The 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
"""
Expand All @@ -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)
Expand All @@ -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):
Copy link
Member

Choose a reason for hiding this comment

The 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:

  • User: k!setup
  • Koala: 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/ If you agree to this, on behalf of your server, reply 'Yes' to enable the rest of Koala

either:

  • User: Y
  • Koala: Perfect, all other commands are unlocked, use k!help to find our commands

or:

  • User: No (or no answer)
  • Koala: We're sorry, without agreeing we cannot offer all parts of Koala to your server. Use k!setup again to agree to our Terms & conditions

"""
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:
"""
Expand Down
Loading