-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlogs.py
230 lines (187 loc) · 6.5 KB
/
logs.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
"""Beadless Bot event logging methods."""
from collections.abc import Sequence
from typing import Final
import nextcord
from misc import ProfUrl, bb_embed, content_check, fetch_avatar, truncate_time
# TODO: Implement log thread locked/unlocked
# https://github.com/LevBernstein/BeardlessBot/issues/45
MaxPurgedMsgs: Final[int] = 99
def log_delete_msg(message: nextcord.Message) -> nextcord.Embed:
assert hasattr(message.channel, "mention")
prefix = (
f"**Deleted message sent by {message.author.mention} in "
f"**{message.channel.mention}\n"
)
return bb_embed(
value=f"{prefix}{content_check(message, len(prefix))}",
col=0xFF0000,
show_time=True,
).set_author(name=message.author, icon_url=fetch_avatar(message.author))
def log_purge(
msg: nextcord.Message, messages: Sequence[nextcord.Message],
) -> nextcord.Embed:
def purge_report(msg_list: Sequence[nextcord.Message]) -> str:
return (
f"{MaxPurgedMsgs}+"
if len(msg_list) > MaxPurgedMsgs
else str(len(msg_list) - 1)
)
assert hasattr(msg.channel, "mention")
return bb_embed(
"",
f"Purged {purge_report(messages)} messages in {msg.channel.mention}.",
0xFF0000,
show_time=True,
).set_author(name="Purge!", icon_url=ProfUrl)
def log_edit_msg(
before: nextcord.Message, after: nextcord.Message,
) -> nextcord.Embed:
assert hasattr(before.channel, "mention")
jump_link = f"\n[Jump to Message]({after.jump_url})"
return bb_embed(
"",
f"Messaged edited by {before.author.mention}"
f" in {before.channel.mention}.",
0xFFFF00,
show_time=True,
).set_author(
name=before.author, icon_url=fetch_avatar(before.author),
).add_field(
name="Before:", value=content_check(before, 7), inline=False,
).add_field(
name="After:",
value=f"{content_check(after, len(jump_link))}{jump_link}",
inline=False,
)
def log_clear_reacts(
message: nextcord.Message, reactions: list[nextcord.Reaction],
) -> nextcord.Embed:
assert hasattr(message.channel, "mention")
jump_link = f"\n[Jump to Message]({message.jump_url})"
return bb_embed(
"",
f"Reactions cleared from message sent by {message.author.mention}"
f" in {message.channel.mention}.",
0xFF0000,
show_time=True,
).set_author(
name=message.author, icon_url=fetch_avatar(message.author),
).add_field(
name="Message content:",
value=content_check(message, len(jump_link)) + jump_link,
).add_field(
name="Reactions:", value=", ".join(str(r) for r in reactions),
)
def log_delete_channel(channel: nextcord.abc.GuildChannel) -> nextcord.Embed:
return bb_embed(
"", f"Channel \"{channel.name}\" deleted.", 0xFF0000, show_time=True,
).set_author(name="Channel deleted", icon_url=ProfUrl)
def log_create_channel(channel: nextcord.abc.GuildChannel) -> nextcord.Embed:
return bb_embed(
"", f"Channel \"{channel.name}\" created.", 0x00FF00, show_time=True,
).set_author(name="Channel created", icon_url=ProfUrl)
def log_member_join(member: nextcord.Member) -> nextcord.Embed:
return bb_embed(
"",
f"Member {member.mention} joined\nAccount registered"
f" on {truncate_time(member)}\nID: {member.id}",
0x0000FF,
show_time=True,
).set_author(
name=f"{member} joined the server", icon_url=fetch_avatar(member),
)
def log_member_remove(member: nextcord.Member) -> nextcord.Embed:
emb = bb_embed(
value=f"Member {member.mention} left\nID: {member.id}",
col=0xFF0000,
show_time=True,
).set_author(
name=f"{member} left the server", icon_url=fetch_avatar(member),
)
if len(member.roles) > 1:
emb.add_field(
name="Roles:",
value=", ".join(role.mention for role in member.roles[:0:-1]),
)
return emb
def log_member_nick_change(
before: nextcord.Member, after: nextcord.Member,
) -> nextcord.Embed:
return bb_embed(
"", f"Nickname of {after.mention} changed.", 0xFFFF00, show_time=True,
).set_author(
name=after, icon_url=fetch_avatar(after),
).add_field(
name="Before:", value=before.nick, inline=False,
).add_field(name="After:", value=after.nick, inline=False)
def log_member_roles_change(
before: nextcord.Member, after: nextcord.Member,
) -> nextcord.Embed:
verb, color = (
("removed from", 0xFF0000)
if len(before.roles) > len(after.roles)
else ("added to", 0x00FF00)
)
role = set(after.roles).symmetric_difference(set(before.roles)).pop()
return bb_embed(
value=f"Role {role.mention} {verb} {after.mention}.",
col=color,
show_time=True,
).set_author(name=after, icon_url=fetch_avatar(after))
def log_ban(member: nextcord.Member) -> nextcord.Embed:
return bb_embed(
value=f"Member {member.mention} banned\n{member.name}",
col=0xFF0000,
show_time=True,
).set_author(
name="Member banned", icon_url=fetch_avatar(member),
).set_thumbnail(url=fetch_avatar(member))
def log_unban(member: nextcord.Member) -> nextcord.Embed:
return bb_embed(
value=f"Member {member.mention} unbanned\n{member.name}",
col=0x00FF00,
show_time=True,
).set_author(
name="Member unbanned", icon_url=fetch_avatar(member),
).set_thumbnail(url=fetch_avatar(member))
def log_mute(
member: nextcord.Member, message: nextcord.Message, duration: str | None,
) -> nextcord.Embed:
assert hasattr(message.channel, "mention")
mid = f" for {duration}" if duration else ""
return bb_embed(
"Beardless Bot Mute",
f"Muted {member.mention}{mid} in {message.channel.mention}.",
0xFF0000,
show_time=True,
).set_author(name=message.author, icon_url=fetch_avatar(message.author))
def log_unmute(
member: nextcord.Member, author: nextcord.Member,
) -> nextcord.Embed:
return bb_embed(
"Beardless Bot Mute",
f"Unmuted {member.mention}.",
0x00FF00,
show_time=True,
).set_author(name=author, icon_url=fetch_avatar(author))
def log_create_thread(thread: nextcord.Thread) -> nextcord.Embed:
assert isinstance(thread.parent, nextcord.abc.GuildChannel)
return bb_embed(
"",
f"Thread \"{thread.name}\" created in"
f" parent channel {thread.parent.mention}.",
0x00FF00,
show_time=True,
).set_author(name="Thread created", icon_url=ProfUrl)
def log_delete_thread(thread: nextcord.Thread) -> nextcord.Embed:
return bb_embed(
"", f"Thread \"{thread.name}\" deleted.", 0xFF0000, show_time=True,
).set_author(name="Thread deleted", icon_url=ProfUrl)
def log_thread_archived(thread: nextcord.Thread) -> nextcord.Embed:
return bb_embed(
"", f"Thread \"{thread.name}\" archived.", 0xFFFF00, show_time=True,
).set_author(name="Thread archived", icon_url=ProfUrl)
def log_thread_unarchived(thread: nextcord.Thread) -> nextcord.Embed:
return bb_embed(
"", f"Thread \"{thread.name}\" unarchived.", 0xFFFF00, show_time=True,
).set_author(name="Thread unarchived", icon_url=ProfUrl)