diff options
author | 2020-08-25 19:03:20 +0100 | |
---|---|---|
committer | 2020-08-25 19:03:20 +0100 | |
commit | 86e9fcb5d7f5e318179d9afa01c7d8f3a7baa1bb (patch) | |
tree | eb75d66a2c2b2a0df8b1d9586913abca18e55e2c | |
parent | Major adjustments to data storage, strings instead of bigints for metabase co... (diff) |
Add opt-in/opt-out commands
-rw-r--r-- | config-default.toml | 4 | ||||
-rw-r--r-- | metricity/bot.py | 46 | ||||
-rw-r--r-- | metricity/config.py | 2 |
3 files changed, 51 insertions, 1 deletions
diff --git a/config-default.toml b/config-default.toml index cd48cce..1af0e9e 100644 --- a/config-default.toml +++ b/config-default.toml @@ -33,10 +33,14 @@ staff_categories = [ 430484673248886784 ] +# Don't report messages for the following categories ignore_categories = [ 714494672835444826 ] +# Respond to opt-in/opt-out commands in the following channel +bot_commands_channel = 267659945086812160 + [database] # Postgres! diff --git a/metricity/bot.py b/metricity/bot.py index 1380c9d..84ee05b 100644 --- a/metricity/bot.py +++ b/metricity/bot.py @@ -10,7 +10,7 @@ from discord import ( Message as DiscordMessage, VoiceChannel ) from discord.abc import Messageable -from discord.ext.commands import Bot +from discord.ext.commands import Bot, Context from metricity.config import BotConfig from metricity.database import connect @@ -247,3 +247,47 @@ async def on_message(message: DiscordMessage) -> None: author_id=str(message.author.id), created_at=message.created_at ) + + if message.channel.id in BotConfig.bot_commands_channel: + await bot.process_commands(message) + + +async def opt_in(ctx: Context) -> None: + """Opt-in to the server analytics system.""" + user = await User.get(str(ctx.author.id)) + + if not user: + return await ctx.send( + f"Sorry {ctx.author.mention}, I don't have a record for you yet" + " which probably means you joined recently enough to have missed" + " the user synchronisation. Please check back soon or contact" + " `joe#1337` for additional help." + ) + + await user.update(opt_out=False).apply() + + await ctx.send("Your preferences have been updated.") + + +async def opt_out(ctx: Context) -> None: + """ + Opt-out to the server analytics system. + + This only disables message reporting, user information is kept + in accordance with our privacy policy. + """ + user = await User.get(str(ctx.author.id)) + + if not user: + return await ctx.send( + f"Sorry {ctx.author.mention}, I don't have a record for you yet" + " which probably means you joined recently enough to have missed" + " the user synchronisation. Please check back soon or contact" + " `joe#1337` for additional help." + ) + + await user.update(opt_out=True).apply() + + await ctx.send("Your preferences have been updated.") diff --git a/metricity/config.py b/metricity/config.py index 8b043f5..1cf7dfa 100644 --- a/metricity/config.py +++ b/metricity/config.py @@ -118,6 +118,8 @@ class BotConfig(metaclass=ConfigSection): staff_categories: List[int] ignore_categories: List[int] + bot_commands_channel: int + class DatabaseConfig(metaclass=ConfigSection): """Configuration about the database Metricity will use.""" |