-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathunflag.py
101 lines (81 loc) · 2.77 KB
/
unflag.py
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
import discord
from discord.ext import commands
from prisma.enums import CaseType
from tux.bot import Tux
from tux.database.controllers.case import CaseController
from tux.utils import checks
from tux.utils.flags import UnFlagFlags, generate_usage
from . import ModerationCogBase
class Flag(ModerationCogBase):
def __init__(self, bot: Tux) -> None:
super().__init__(bot)
self.case_controller = CaseController()
self.unflag.usage = generate_usage(self.unflag, UnFlagFlags)
@commands.hybrid_command(
name="unflag",
aliases=["ufl"],
)
@commands.guild_only()
@checks.has_pl(2)
async def unflag(
self,
ctx: commands.Context[Tux],
member: discord.Member,
*,
flags: UnFlagFlags,
) -> None:
"""
Unflag a member from the server.
Parameters
----------
ctx : commands.Context[Tux]
The context in which the command is being invoked.
member : discord.Member
The member to unflag.
flags : UnFlagFlags
The flags for the command. (reason: str, silent: bool)
"""
assert ctx.guild
if not await self.is_flagged(ctx.guild.id, member.id):
await ctx.send("User is not flagged.", delete_after=30, ephemeral=True)
return
moderator = ctx.author
if not await self.check_conditions(ctx, member, moderator, "unflag"):
return
case = await self.db.case.insert_case(
case_user_id=member.id,
case_moderator_id=ctx.author.id,
case_type=CaseType.UNFLAG,
case_reason=flags.reason,
guild_id=ctx.guild.id,
)
await self.handle_case_response(
ctx,
CaseType.UNFLAG,
case.case_number,
flags.reason,
member,
dm_sent=False,
silent_action=True,
)
async def is_flagged(self, guild_id: int, user_id: int) -> bool:
"""
Check if a user is flagged.
Parameters
----------
guild_id : int
The ID of the guild to check in.
user_id : int
The ID of the user to check.
Returns
-------
bool
True if the user is flagged, False otherwise.
"""
flag_cases = await self.case_controller.get_all_cases_by_type(guild_id, CaseType.FLAG)
unflag_cases = await self.case_controller.get_all_cases_by_type(guild_id, CaseType.UNFLAG)
flag_count = sum(case.case_user_id == user_id for case in flag_cases)
unflag_count = sum(case.case_user_id == user_id for case in unflag_cases)
return flag_count > unflag_count
async def setup(bot: Tux) -> None:
await bot.add_cog(Flag(bot))