lunarflu HF staff commited on
Commit
c621f1b
1 Parent(s): 3c039fb

added 5s sleep for bans + joins to fix audit logs + mentions, also separated variable names for bans

Browse files
Files changed (1) hide show
  1. app.py +10 -30
app.py CHANGED
@@ -9,14 +9,11 @@ import time
9
  import re
10
  from discord import Embed, Color
11
  from discord.ext import commands
12
-
13
  from gradio_client import Client
14
  from PIL import Image
15
  from ratelimiter import RateLimiter
16
-
17
  from datetime import datetime # for times
18
  from pytz import timezone # for times
19
-
20
  import asyncio # check if used
21
 
22
  zurich_tz = timezone("Europe/Zurich")
@@ -30,28 +27,6 @@ bot = commands.Bot(command_prefix='!', intents=intents)
30
 
31
  #rate_limiter = RateLimiter(max_calls=10, period=60) # needs testing
32
 
33
- # todo
34
- '''
35
- - test what works
36
- ->delete
37
- ->edit
38
-
39
-
40
- -x>nicknames
41
-
42
-
43
-
44
- - add role changes (moving roles)
45
-
46
- discord.gg / discord/invite (block completely, need to be cautious)
47
- attempted @everyone / @here pings, or trying to use those strings (ping @alerts)
48
- ping alerts for list of keywords
49
-
50
-
51
- - backup?
52
- - more alerts for more stuff?
53
-
54
- '''
55
  # stats stuff ---------------------------------------------------------------------------------------------------------------------------------------------------------
56
  number_of_messages = 0
57
  user_cooldowns = {}
@@ -205,13 +180,16 @@ async def on_member_update(before, after):
205
  @bot.event
206
  async def on_member_ban(guild, banned_user):
207
  try:
208
- entry = await guild.fetch_ban(banned_user)
209
- ban_reason = entry.reason
 
210
  print(f"ban_reason: {ban_reason}")
211
 
212
- async for entry in guild.audit_logs(action=discord.AuditLogAction.ban, limit=1):
213
- moderator = entry.user
214
- print(f"moderator: {moderator}")
 
 
215
 
216
  #ban_reason = f"Reason: {ban_reason}"
217
  # HF 1108342563628404747
@@ -239,6 +217,7 @@ async def on_member_ban(guild, banned_user):
239
  @bot.event
240
  async def on_member_unban(guild, unbanned_user):
241
  try:
 
242
  async for entry in guild.audit_logs(action=discord.AuditLogAction.unban, limit=1):
243
  if unbanned_user == entry.target: # verify that unbanned user is in audit log
244
  moderator = entry.user
@@ -267,6 +246,7 @@ async def on_member_unban(guild, unbanned_user):
267
  @bot.event
268
  async def on_member_join(member):
269
  try:
 
270
  embed = Embed(color=Color.blue())
271
  avatar_url = member.avatar.url if member.avatar else bot.user.avatar.url
272
  embed.set_author(name=f"{member} ID: {member.id}", icon_url=avatar_url)
 
9
  import re
10
  from discord import Embed, Color
11
  from discord.ext import commands
 
12
  from gradio_client import Client
13
  from PIL import Image
14
  from ratelimiter import RateLimiter
 
15
  from datetime import datetime # for times
16
  from pytz import timezone # for times
 
17
  import asyncio # check if used
18
 
19
  zurich_tz = timezone("Europe/Zurich")
 
27
 
28
  #rate_limiter = RateLimiter(max_calls=10, period=60) # needs testing
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  # stats stuff ---------------------------------------------------------------------------------------------------------------------------------------------------------
31
  number_of_messages = 0
32
  user_cooldowns = {}
 
180
  @bot.event
181
  async def on_member_ban(guild, banned_user):
182
  try:
183
+ await asyncio.sleep(5)
184
+ entry1 = await guild.fetch_ban(banned_user)
185
+ ban_reason = entry1.reason
186
  print(f"ban_reason: {ban_reason}")
187
 
188
+ async for entry2 in guild.audit_logs(action=discord.AuditLogAction.ban, limit=1):
189
+ if ban_reason:
190
+ print(f'{entry2.user} banned {entry2.target} for {ban_reason}')
191
+ else:
192
+ print(f'{entry2.user} banned {entry2.target} (no reason specified)')
193
 
194
  #ban_reason = f"Reason: {ban_reason}"
195
  # HF 1108342563628404747
 
217
  @bot.event
218
  async def on_member_unban(guild, unbanned_user):
219
  try:
220
+ await asyncio.sleep(5)
221
  async for entry in guild.audit_logs(action=discord.AuditLogAction.unban, limit=1):
222
  if unbanned_user == entry.target: # verify that unbanned user is in audit log
223
  moderator = entry.user
 
246
  @bot.event
247
  async def on_member_join(member):
248
  try:
249
+ await asyncio.sleep(5)
250
  embed = Embed(color=Color.blue())
251
  avatar_url = member.avatar.url if member.avatar else bot.user.avatar.url
252
  embed.set_author(name=f"{member} ID: {member.id}", icon_url=avatar_url)