-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdelete_all.py
More file actions
143 lines (119 loc) · 5.71 KB
/
delete_all.py
File metadata and controls
143 lines (119 loc) · 5.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
"""Contains cog classes for any delete_all interactions."""
from typing import TYPE_CHECKING
import discord
from db.core.models import (
AssignedCommitteeAction,
DiscordMemberStrikes,
DiscordReminder,
GroupMadeMember,
SentGetRolesReminderMember,
SentOneOffIntroductionReminderMember,
)
from utils import CommandChecks, TeXBotBaseCog
if TYPE_CHECKING:
from collections.abc import Sequence
from db.core.models.utils import AsyncBaseModel
from utils import TeXBotApplicationContext
__all__: "Sequence[str]" = ("DeleteAllCommandsCog",)
class DeleteAllCommandsCog(TeXBotBaseCog):
"""Cog class that defines the "/delete-all" command group and command call-back methods."""
delete_all: discord.SlashCommandGroup = discord.SlashCommandGroup(
name="delete-all",
description=(
"Delete all instances of the selected object type from the backend database"
),
)
@staticmethod
async def _delete_all(
ctx: "TeXBotApplicationContext", delete_model: type["AsyncBaseModel"]
) -> None:
"""Perform the actual deletion process of all instances of the given model class."""
await delete_model._default_manager.all().adelete()
delete_model_instances_name_plural: str = (
delete_model.INSTANCES_NAME_PLURAL
if hasattr(delete_model, "INSTANCES_NAME_PLURAL")
else "objects"
)
await ctx.respond(
f"All {delete_model_instances_name_plural} deleted successfully.", ephemeral=True
)
@delete_all.command(
name="reminders", description="Deletes all Reminders from the backend database."
)
@CommandChecks.check_interaction_user_has_committee_role
@CommandChecks.check_interaction_user_in_main_guild
async def delete_all_reminders(self, ctx: "TeXBotApplicationContext") -> None:
"""
Definition & callback response of the "delete_all_reminders" command.
The "delete_all_reminders" command uses the _delete_all() function
to delete all `DiscordReminder` instance objects stored in the database.
"""
await self._delete_all(ctx, delete_model=DiscordReminder)
@delete_all.command(
name="group-made-members",
description="Deletes all Group Made Members from the backend database.",
)
@CommandChecks.check_interaction_user_has_committee_role
@CommandChecks.check_interaction_user_in_main_guild
async def delete_all_group_made_members(self, ctx: "TeXBotApplicationContext") -> None:
"""
Definition & callback response of the "delete_all_group_made_members" command.
The "delete_all_group_made_members" command uses the _delete_all() function
to delete all `GroupMadeMember` instance objects stored in the database.
"""
await self._delete_all(ctx, delete_model=GroupMadeMember)
@delete_all.command(
name="actions", description="Deletes all the Actions from the backend database."
)
@CommandChecks.check_interaction_user_has_committee_role
@CommandChecks.check_interaction_user_in_main_guild
async def delete_all_actions(self, ctx: "TeXBotApplicationContext") -> None:
"""
Definition & callback respoonse of the "delete-all-actions" command.
The "delete-all-actions" command uses the _delete_all() function
to delete all `Action` instance objects stored in the database.
"""
await self._delete_all(ctx, delete_model=AssignedCommitteeAction)
@delete_all.command(
name="strikes", description="Deletes all the Strikes from the backend database."
)
@CommandChecks.check_interaction_user_has_committee_role
@CommandChecks.check_interaction_user_in_main_guild
async def delete_all_strikes(self, ctx: "TeXBotApplicationContext") -> None:
"""
Definition & callback response of the "delete-all-strikes" command.
The "delete-all-strikes" command uses the _delete_all() function
to delete all `Strike` instance objects stored in the database.
"""
await self._delete_all(ctx, delete_model=DiscordMemberStrikes)
@delete_all.command(
name="sent-get-roles-reminders",
description="Deletes all SentGetRolesReminderMember objects from the backend database.", # noqa: E501
)
@CommandChecks.check_interaction_user_has_committee_role
@CommandChecks.check_interaction_user_in_main_guild
async def delete_all_sent_get_role_reminders(
self, ctx: "TeXBotApplicationContext"
) -> None:
"""
Definition & callback response of the "delete_all_sent_get_role_reminders" command.
The "delete_all_sent_get_role_reminders" command uses the _delete_all() function
to delete all `SentGetRolesReminderMember` instance objects in the database.
"""
await self._delete_all(ctx, delete_model=SentGetRolesReminderMember)
@delete_all.command(
name="sent-introduction-reminders",
description="Deletes all SentOneOffIntroductionReminderMember objects from the backend database.", # noqa: E501
)
@CommandChecks.check_interaction_user_has_committee_role
@CommandChecks.check_interaction_user_in_main_guild
async def delete_all_sent_one_off_introduction_reminders(
self, ctx: "TeXBotApplicationContext"
) -> None:
"""
Definition & callback response of the "delete_all_sent_one_off_introduction_reminders" command.
The "delete_all_sent_one_off_introduction_reminders" command uses the _delete_all()
function to delete all `SentOneOffIntroductionReminderMember`
instance objects in the database.
""" # noqa: E501, W505
await self._delete_all(ctx, delete_model=SentOneOffIntroductionReminderMember)