aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config-default.toml4
-rw-r--r--metricity/bot.py46
-rw-r--r--metricity/config.py2
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."""