aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-07-03 12:39:04 +0100
committerGravatar Gareth Coles <[email protected]>2018-07-03 12:39:04 +0100
commit5c58c50f7dc5ec45b7ff913c319be3a61886c0d7 (patch)
treeb243f17ed8ec1efce14b962041b3c10b41aca18e
parent[RMQ] Ack messages (diff)
Announcements role system, and verification improvements
* Subscribe to announcement notifications, giving you the role * Verification instructional message now sticks around for 20s instead of 10s * The bot will attempt to DM a welcome message to users that verify themselves
-rw-r--r--bot/cogs/verification.py69
-rw-r--r--bot/constants.py2
-rw-r--r--config-default.yml2
3 files changed, 68 insertions, 5 deletions
diff --git a/bot/cogs/verification.py b/bot/cogs/verification.py
index ac5da7d87..a5ad657a3 100644
--- a/bot/cogs/verification.py
+++ b/bot/cogs/verification.py
@@ -4,16 +4,34 @@ from discord import Message, NotFound, Object
from discord.ext.commands import Bot, Context, command
from bot.constants import Channels, Roles
-from bot.decorators import in_channel, without_role
-
+from bot.decorators import in_channel, with_role, without_role
log = logging.getLogger(__name__)
+WELCOME_MESSAGE = f"""
+Hello! Welcome to the server, and thanks for verifying yourself!
+
+For your records, these are the documents you accepted:
+
+`1)` Our rules, here: <https://pythondiscord.com/about/rules>
+`2)` Our privacy policy, here: <https://pythondiscord.com/about/privacy> - you can find information on how to have \
+your information removed here as well.
+
+Feel free to review them at any point!
+
+Additionally, if you'd like to receive notifications for the announcements we post in <#{Channels.announcements}> \
+from time to time, you can send `self.subscribe()` to <#{Channels.bot}> at any time to assign yourself the \
+**Announcements** role. We'll mention this role every time we make an announcement.
+
+If you'd like to unsubscribe from the announcement notifications, simply send `self.unsubscribe()` to <#{Channels.bot}>.
+"""
+
class Verification:
"""
- User verification
+ User verification and role self-management
"""
+
def __init__(self, bot: Bot):
self.bot = bot
@@ -38,7 +56,7 @@ class Verification:
await ctx.send(
f"{ctx.author.mention} Please type `self.accept()` to verify that you accept our rules, "
f"and gain access to the rest of the server.",
- delete_after=10
+ delete_after=20
)
log.trace(f"Deleting the message posted by {ctx.author}")
@@ -56,8 +74,49 @@ class Verification:
Accept our rules and gain access to the rest of the server
"""
- log.debug(f"{ctx.author} called self.accept(). Assigning the user 'Developer' role.")
+ log.debug(f"{ctx.author} called self.accept(). Assigning the 'Developer' role.")
await ctx.author.add_roles(Object(Roles.verified), reason="Accepted the rules")
+ try:
+ await ctx.author.send(WELCOME_MESSAGE)
+ except Exception:
+ # Catch the exception, in case they have DMs off or something
+ log.exception(f"Unable to send welcome message to user {ctx.author}.")
+
+ log.trace(f"Deleting the message posted by {ctx.author}.")
+
+ try:
+ await ctx.message.delete()
+ except NotFound:
+ log.trace("No message found, it must have been deleted by another bot.")
+
+ @command(name="subscribe", aliases=["subscribe()"])
+ @without_role(Roles.announcements)
+ @in_channel(Channels.bot)
+ async def subscribe(self, ctx: Context, *_): # We don't actually care about the args
+ """
+ Subscribe to announcement notifications by assigning yourself the role
+ """
+
+ log.debug(f"{ctx.author} called self.subscribe(). Assigning the 'Announcements' role.")
+ await ctx.author.add_roles(Object(Roles.announcements), reason="Subscribed to announcements")
+
+ log.trace(f"Deleting the message posted by {ctx.author}.")
+
+ try:
+ await ctx.message.delete()
+ except NotFound:
+ log.trace("No message found, it must have been deleted by another bot.")
+
+ @command(name="unsubscribe", aliases=["unsubscribe()"])
+ @with_role(Roles.announcements)
+ @in_channel(Channels.bot)
+ async def unsubscribe(self, ctx: Context, *_): # We don't actually care about the args
+ """
+ Unsubscribe from announcement notifications by removing the role from yourself
+ """
+
+ log.debug(f"{ctx.author} called self.unsubscribe(). Removing the 'Announcements' role.")
+ await ctx.author.remove_roles(Object(Roles.announcements), reason="Unsubscribed from announcements")
log.trace(f"Deleting the message posted by {ctx.author}.")
diff --git a/bot/constants.py b/bot/constants.py
index 48e0a95a8..ce8fbb1cb 100644
--- a/bot/constants.py
+++ b/bot/constants.py
@@ -180,6 +180,7 @@ class Channels(metaclass=YAMLGetter):
section = "guild"
subsection = "channels"
+ announcements: int
bot: int
checkpoint_test: int
devlog: int
@@ -200,6 +201,7 @@ class Roles(metaclass=YAMLGetter):
subsection = "roles"
admin: int
+ announcements: int
champion: int
contributor: int
devops: int
diff --git a/config-default.yml b/config-default.yml
index 147c2f7a6..b58666ca1 100644
--- a/config-default.yml
+++ b/config-default.yml
@@ -16,6 +16,7 @@ guild:
id: 267624335836053506
channels:
+ announcements: 354619224620138496
bot: 267659945086812160
checkpoint_test: 422077681434099723
devlog: 409308876241108992
@@ -35,6 +36,7 @@ guild:
roles:
admin: 267628507062992896
+ announcements: 463658397560995840
champion: 430492892331769857
contributor: 295488872404484098
devops: 409416496733880320