mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-20 18:06:08 -05:00
Begin work on a data request API (#4045)
[Core] Data Deletion And Disclosure APIs - Adds a Data Deletion API - Deletion comes in a few forms based on who is requesting - Deletion must be handled by 3rd party - Adds a Data Collection Disclosure Command - Provides a dynamically generated statement from 3rd party extensions - Modifies the always available commands to be cog compatible - Also prevents them from being unloaded accidentally
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import logging
|
||||
import asyncio
|
||||
from typing import Union, List
|
||||
from typing import Union, List, Literal
|
||||
from datetime import timedelta
|
||||
from copy import copy
|
||||
import contextlib
|
||||
@@ -60,6 +60,39 @@ class Reports(commands.Cog):
|
||||
# (guild, ticket#):
|
||||
# {'tun': Tunnel, 'msgs': List[int]}
|
||||
|
||||
async def red_delete_data_for_user(
|
||||
self,
|
||||
*,
|
||||
requester: Literal["discord_deleted_user", "owner", "user", "user_strict"],
|
||||
user_id: int,
|
||||
):
|
||||
if requester != "discord_deleted_user":
|
||||
return
|
||||
|
||||
all_reports = await self.config.custom("REPORT").all()
|
||||
|
||||
steps = 0
|
||||
paths = []
|
||||
|
||||
# this doesn't use async iter intentionally due to the nested iterations
|
||||
for guild_id_str, tickets in all_reports.items():
|
||||
for ticket_number, ticket in tickets.items():
|
||||
steps += 1
|
||||
if not steps % 100:
|
||||
await asyncio.sleep(0) # yield context
|
||||
|
||||
if ticket.get("report", {}).get("user_id", 0) == user_id:
|
||||
paths.append((guild_id_str, ticket_number))
|
||||
|
||||
async with self.config.custom("REPORT").all() as all_reports:
|
||||
async for guild_id_str, ticket_number in AsyncIter(paths, steps=100):
|
||||
r = all_reports[guild_id_str][ticket_number]["report"]
|
||||
r["user_id"] = 0xDE1
|
||||
# this might include EUD, and a report of a deleted user
|
||||
# that's been unhandled for long enough for the
|
||||
# user to be deleted and the bot recieve a request like this...
|
||||
r["report"] = "[REPORT DELETED DUE TO DISCORD REQUEST]"
|
||||
|
||||
@property
|
||||
def tunnels(self):
|
||||
return [x["tun"] for x in self.tunnel_store.values()]
|
||||
|
||||
Reference in New Issue
Block a user