lunarflu HF staff commited on
Commit
6dd716b
1 Parent(s): 2033364

Synced repo using 'sync_with_huggingface' Github Action

Browse files
Files changed (1) hide show
  1. app.py +35 -22
app.py CHANGED
@@ -40,7 +40,6 @@ async def on_message(message):
40
  lunarflu = bot.get_user(811235357663297546) #811235357663297546
41
  cakiki = bot.get_user(416019758492680203)
42
  log_channel = bot.get_channel(1036960509586587689)
43
- print(log_channel)
44
 
45
  """Backup"""
46
  number_of_messages = number_of_messages + 1
@@ -48,7 +47,7 @@ async def on_message(message):
48
  job = test.submit(message.content, api_name="/predict")
49
  while not job.done():
50
  await asyncio.sleep(0.2)
51
- #await bot.log_channel.send( later, after testing
52
  dm_message = await lunarflu.send(f"{number_of_messages}| {job.outputs()[0]['label']}| {message_link} |{message.author}: {message.content}")
53
 
54
  """Antispam"""
@@ -127,7 +126,8 @@ async def on_message_edit(before, after):
127
  try:
128
  if before.author == bot.user:
129
  return
130
-
 
131
  if before.content != after.content:
132
  embed = Embed(color=Color.orange())
133
  embed.set_author(name=f"{before.author} ID: {before.author.id}", icon_url=before.author.avatar.url if before.author.avatar else bot.user.avatar.url)
@@ -144,7 +144,7 @@ async def on_message_edit(before, after):
144
  embed.add_field(name="Attachments", value=attachment_urls, inline=False)
145
  #embed.set_footer(text=f"{datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')}")
146
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
147
- await bot.log_channel.send(embed=embed)
148
 
149
  except Exception as e:
150
  print(f"on_message_edit Error: {e}")
@@ -154,7 +154,8 @@ async def on_message_delete(message):
154
  try:
155
  if message.author == bot.user:
156
  return
157
-
 
158
  embed = Embed(color=Color.red())
159
  embed.set_author(name=f"{message.author} ID: {message.author.id}", icon_url=message.author.avatar.url if message.author.avatar else bot.user.avatar.url)
160
  embed.title = "Message Deleted"
@@ -170,7 +171,7 @@ async def on_message_delete(message):
170
  embed.add_field(name="Attachments", value=attachment_urls, inline=False)
171
  #embed.set_footer(text=f"{datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')}")
172
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
173
- await bot.log_channel.send(embed=embed)
174
 
175
  except Exception as e:
176
  print(f"on_message_delete Error: {e}")
@@ -184,6 +185,7 @@ async def on_member_update(before, after):
184
  async for entry in before.guild.audit_logs(limit=5):
185
  print(f'{entry.user} did {entry.action} to {entry.target}')
186
  """
 
187
  if before.nick != after.nick:
188
  embed = Embed(color=Color.orange())
189
  embed.set_author(name=f"{after} ID: {after.id}", icon_url=after.avatar.url if after.avatar else bot.user.avatar.url)
@@ -192,7 +194,7 @@ async def on_member_update(before, after):
192
  embed.add_field(name="Old", value=before.nick, inline=True)
193
  embed.add_field(name="New", value=after.nick, inline=True)
194
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
195
- await bot.log_channel.send(embed=embed)
196
 
197
  except Exception as e:
198
  print(f"on_member_update Error: {e}")
@@ -201,6 +203,7 @@ async def on_member_update(before, after):
201
  @bot.event
202
  async def on_member_ban(guild, banned_user):
203
  try:
 
204
  await asyncio.sleep(1)
205
  entry1 = await guild.fetch_ban(banned_user)
206
  ban_reason = entry1.reason
@@ -227,7 +230,7 @@ async def on_member_ban(guild, banned_user):
227
 
228
  #user = bot.get_user(811235357663297546)
229
  #dm_message = await user.send(content=content, embed=embed)
230
- await bot.log_channel.send(content=content, embed=embed)
231
 
232
  except Exception as e:
233
  print(f"on_member_ban Error: {e}")
@@ -236,7 +239,7 @@ async def on_member_ban(guild, banned_user):
236
  @bot.event
237
  async def on_member_unban(guild, unbanned_user):
238
  try:
239
- await asyncio.sleep(5)
240
  async for entry in guild.audit_logs(action=discord.AuditLogAction.unban, limit=1):
241
  if unbanned_user == entry.target: # verify that unbanned user is in audit log
242
  moderator = entry.user
@@ -254,7 +257,7 @@ async def on_member_unban(guild, unbanned_user):
254
 
255
  #user = bot.get_user(811235357663297546)
256
  #dm_message = await user.send(content=content, embed=embed)
257
- await bot.log_channel.send(content=content, embed=embed)
258
 
259
  except Exception as e:
260
  print(f"on_member_unban Error: {e}")
@@ -265,7 +268,7 @@ async def on_member_unban(guild, unbanned_user):
265
  @bot.event
266
  async def on_member_join(member):
267
  try:
268
- await asyncio.sleep(5)
269
  embed = Embed(color=Color.blue())
270
  avatar_url = member.avatar.url if member.avatar else bot.user.avatar.url
271
  embed.set_author(name=f"{member} ID: {member.id}", icon_url=avatar_url)
@@ -274,7 +277,7 @@ async def on_member_join(member):
274
  embed.add_field(name="Nickname", value=member.nick, inline=True)
275
  embed.add_field(name="Account Created At", value=member.created_at, inline=True)
276
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
277
- await bot.log_channel.send(embed=embed)
278
 
279
  except Exception as e:
280
  print(f"on_member_join Error: {e}")
@@ -283,6 +286,7 @@ async def on_member_join(member):
283
  @bot.event
284
  async def on_member_remove(member):
285
  try:
 
286
  embed = Embed(color=Color.blue())
287
  embed.set_author(name=f"{member} ID: {member.id}", icon_url=member.avatar.url if member.avatar else bot.user.avatar.url)
288
  embed.title = "User Left"
@@ -290,7 +294,7 @@ async def on_member_remove(member):
290
  embed.add_field(name="Nickname", value=member.nick, inline=True)
291
  embed.add_field(name="Account Created At", value=member.created_at, inline=True)
292
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
293
- await bot.log_channel.send(embed=embed)
294
 
295
  except Exception as e:
296
  print(f"on_member_remove Error: {e}")
@@ -300,8 +304,9 @@ async def on_member_remove(member):
300
  async def on_guild_channel_create(channel):
301
  try:
302
  # creating channels
 
303
  embed = Embed(description=f'Channel {channel.mention} was created', color=Color.green())
304
- await bot.log_channel.send(embed=embed)
305
  except Exception as e:
306
  print(f"on_guild_channel_create Error: {e}")
307
 
@@ -310,8 +315,9 @@ async def on_guild_channel_create(channel):
310
  async def on_guild_channel_delete(channel):
311
  try:
312
  # deleting channels, should ping @alerts for this
 
313
  embed = Embed(description=f'Channel {channel.name} ({channel.mention}) was deleted', color=Color.red())
314
- await bot.log_channel.send(embed=embed)
315
  except Exception as e:
316
  print(f"on_guild_channel_delete Error: {e}")
317
 
@@ -320,8 +326,9 @@ async def on_guild_channel_delete(channel):
320
  async def on_guild_role_create(role):
321
  try:
322
  # creating roles
 
323
  embed = Embed(description=f'Role {role.mention} was created', color=Color.green())
324
- await bot.log_channel.send(embed=embed)
325
  except Exception as e:
326
  print(f"on_guild_role_create Error: {e}")
327
 
@@ -330,8 +337,9 @@ async def on_guild_role_create(role):
330
  async def on_guild_role_delete(role):
331
  try:
332
  # deleting roles, should ping @alerts for this
 
333
  embed = Embed(description=f'Role {role.name} ({role.mention}) was deleted', color=Color.red())
334
- await bot.log_channel.send(embed=embed)
335
  except Exception as e:
336
  print(f"on_guild_role_delete Error: {e}")
337
 
@@ -340,15 +348,16 @@ async def on_guild_role_delete(role):
340
  async def on_guild_role_update(before, after):
341
  try:
342
  # editing roles, could expand this
 
343
  if before.name != after.name:
344
  embed = Embed(description=f'Role {before.mention} was renamed to {after.name}', color=Color.orange())
345
- await bot.log_channel.send(embed=embed)
346
 
347
  if before.permissions.administrator != after.permissions.administrator:
348
  # changes involving the administrator permission / sensitive permissions (can help to prevent mistakes)
349
  content = "<@&1108342563628404747>" # @alerts role
350
  embed = Embed(description=f'Role {after.mention} had its administrator permission {"enabled" if after.permissions.administrator else "disabled"}', color=Color.red())
351
- await bot.log_channel.send(content=content, embed=embed)
352
  except Exception as e:
353
  print(f"on_guild_role_update Error: {e}")
354
 
@@ -356,15 +365,16 @@ async def on_guild_role_update(before, after):
356
  @bot.event
357
  async def on_voice_state_update(member, before, after):
358
  try:
 
359
  if before.mute != after.mute:
360
  # muting members
361
  embed = Embed(description=f'{member} was {"muted" if after.mute else "unmuted"} in voice chat', color=Color.orange())
362
- await bot.log_channel.send(embed=embed)
363
 
364
  if before.deaf != after.deaf:
365
  # deafening members
366
  embed = Embed(description=f'{member} was {"deafened" if after.deaf else "undeafened"} in voice chat', color=Color.orange())
367
- await bot.log_channel.send(embed=embed)
368
  except Exception as e:
369
  print(f"on_voice_state_update Error: {e}")
370
 
@@ -386,8 +396,11 @@ async def check_github():
386
 
387
  @bot.event
388
  async def on_ready():
 
389
  print('Logged on as', bot.user)
390
-
 
 
391
 
392
 
393
 
 
40
  lunarflu = bot.get_user(811235357663297546) #811235357663297546
41
  cakiki = bot.get_user(416019758492680203)
42
  log_channel = bot.get_channel(1036960509586587689)
 
43
 
44
  """Backup"""
45
  number_of_messages = number_of_messages + 1
 
47
  job = test.submit(message.content, api_name="/predict")
48
  while not job.done():
49
  await asyncio.sleep(0.2)
50
+ #await log_channel.send( later, after testing
51
  dm_message = await lunarflu.send(f"{number_of_messages}| {job.outputs()[0]['label']}| {message_link} |{message.author}: {message.content}")
52
 
53
  """Antispam"""
 
126
  try:
127
  if before.author == bot.user:
128
  return
129
+
130
+ log_channel = bot.get_channel(1036960509586587689)
131
  if before.content != after.content:
132
  embed = Embed(color=Color.orange())
133
  embed.set_author(name=f"{before.author} ID: {before.author.id}", icon_url=before.author.avatar.url if before.author.avatar else bot.user.avatar.url)
 
144
  embed.add_field(name="Attachments", value=attachment_urls, inline=False)
145
  #embed.set_footer(text=f"{datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')}")
146
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
147
+ await log_channel.send(embed=embed)
148
 
149
  except Exception as e:
150
  print(f"on_message_edit Error: {e}")
 
154
  try:
155
  if message.author == bot.user:
156
  return
157
+
158
+ log_channel = bot.get_channel(1036960509586587689)
159
  embed = Embed(color=Color.red())
160
  embed.set_author(name=f"{message.author} ID: {message.author.id}", icon_url=message.author.avatar.url if message.author.avatar else bot.user.avatar.url)
161
  embed.title = "Message Deleted"
 
171
  embed.add_field(name="Attachments", value=attachment_urls, inline=False)
172
  #embed.set_footer(text=f"{datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')}")
173
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
174
+ await log_channel.send(embed=embed)
175
 
176
  except Exception as e:
177
  print(f"on_message_delete Error: {e}")
 
185
  async for entry in before.guild.audit_logs(limit=5):
186
  print(f'{entry.user} did {entry.action} to {entry.target}')
187
  """
188
+ log_channel = bot.get_channel(1036960509586587689)
189
  if before.nick != after.nick:
190
  embed = Embed(color=Color.orange())
191
  embed.set_author(name=f"{after} ID: {after.id}", icon_url=after.avatar.url if after.avatar else bot.user.avatar.url)
 
194
  embed.add_field(name="Old", value=before.nick, inline=True)
195
  embed.add_field(name="New", value=after.nick, inline=True)
196
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
197
+ await log_channel.send(embed=embed)
198
 
199
  except Exception as e:
200
  print(f"on_member_update Error: {e}")
 
203
  @bot.event
204
  async def on_member_ban(guild, banned_user):
205
  try:
206
+ log_channel = bot.get_channel(1036960509586587689)
207
  await asyncio.sleep(1)
208
  entry1 = await guild.fetch_ban(banned_user)
209
  ban_reason = entry1.reason
 
230
 
231
  #user = bot.get_user(811235357663297546)
232
  #dm_message = await user.send(content=content, embed=embed)
233
+ await log_channel.send(content=content, embed=embed)
234
 
235
  except Exception as e:
236
  print(f"on_member_ban Error: {e}")
 
239
  @bot.event
240
  async def on_member_unban(guild, unbanned_user):
241
  try:
242
+ log_channel = bot.get_channel(1036960509586587689)
243
  async for entry in guild.audit_logs(action=discord.AuditLogAction.unban, limit=1):
244
  if unbanned_user == entry.target: # verify that unbanned user is in audit log
245
  moderator = entry.user
 
257
 
258
  #user = bot.get_user(811235357663297546)
259
  #dm_message = await user.send(content=content, embed=embed)
260
+ await log_channel.send(content=content, embed=embed)
261
 
262
  except Exception as e:
263
  print(f"on_member_unban Error: {e}")
 
268
  @bot.event
269
  async def on_member_join(member):
270
  try:
271
+ log_channel = bot.get_channel(1036960509586587689)
272
  embed = Embed(color=Color.blue())
273
  avatar_url = member.avatar.url if member.avatar else bot.user.avatar.url
274
  embed.set_author(name=f"{member} ID: {member.id}", icon_url=avatar_url)
 
277
  embed.add_field(name="Nickname", value=member.nick, inline=True)
278
  embed.add_field(name="Account Created At", value=member.created_at, inline=True)
279
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
280
+ await log_channel.send(embed=embed)
281
 
282
  except Exception as e:
283
  print(f"on_member_join Error: {e}")
 
286
  @bot.event
287
  async def on_member_remove(member):
288
  try:
289
+ log_channel = bot.get_channel(1036960509586587689)
290
  embed = Embed(color=Color.blue())
291
  embed.set_author(name=f"{member} ID: {member.id}", icon_url=member.avatar.url if member.avatar else bot.user.avatar.url)
292
  embed.title = "User Left"
 
294
  embed.add_field(name="Nickname", value=member.nick, inline=True)
295
  embed.add_field(name="Account Created At", value=member.created_at, inline=True)
296
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
297
+ await log_channel.send(embed=embed)
298
 
299
  except Exception as e:
300
  print(f"on_member_remove Error: {e}")
 
304
  async def on_guild_channel_create(channel):
305
  try:
306
  # creating channels
307
+ log_channel = bot.get_channel(1036960509586587689)
308
  embed = Embed(description=f'Channel {channel.mention} was created', color=Color.green())
309
+ await log_channel.send(embed=embed)
310
  except Exception as e:
311
  print(f"on_guild_channel_create Error: {e}")
312
 
 
315
  async def on_guild_channel_delete(channel):
316
  try:
317
  # deleting channels, should ping @alerts for this
318
+ log_channel = bot.get_channel(1036960509586587689)
319
  embed = Embed(description=f'Channel {channel.name} ({channel.mention}) was deleted', color=Color.red())
320
+ await log_channel.send(embed=embed)
321
  except Exception as e:
322
  print(f"on_guild_channel_delete Error: {e}")
323
 
 
326
  async def on_guild_role_create(role):
327
  try:
328
  # creating roles
329
+ log_channel = bot.get_channel(1036960509586587689)
330
  embed = Embed(description=f'Role {role.mention} was created', color=Color.green())
331
+ await log_channel.send(embed=embed)
332
  except Exception as e:
333
  print(f"on_guild_role_create Error: {e}")
334
 
 
337
  async def on_guild_role_delete(role):
338
  try:
339
  # deleting roles, should ping @alerts for this
340
+ log_channel = bot.get_channel(1036960509586587689)
341
  embed = Embed(description=f'Role {role.name} ({role.mention}) was deleted', color=Color.red())
342
+ await log_channel.send(embed=embed)
343
  except Exception as e:
344
  print(f"on_guild_role_delete Error: {e}")
345
 
 
348
  async def on_guild_role_update(before, after):
349
  try:
350
  # editing roles, could expand this
351
+ log_channel = bot.get_channel(1036960509586587689)
352
  if before.name != after.name:
353
  embed = Embed(description=f'Role {before.mention} was renamed to {after.name}', color=Color.orange())
354
+ await log_channel.send(embed=embed)
355
 
356
  if before.permissions.administrator != after.permissions.administrator:
357
  # changes involving the administrator permission / sensitive permissions (can help to prevent mistakes)
358
  content = "<@&1108342563628404747>" # @alerts role
359
  embed = Embed(description=f'Role {after.mention} had its administrator permission {"enabled" if after.permissions.administrator else "disabled"}', color=Color.red())
360
+ await log_channel.send(content=content, embed=embed)
361
  except Exception as e:
362
  print(f"on_guild_role_update Error: {e}")
363
 
 
365
  @bot.event
366
  async def on_voice_state_update(member, before, after):
367
  try:
368
+ log_channel = bot.get_channel(1036960509586587689)
369
  if before.mute != after.mute:
370
  # muting members
371
  embed = Embed(description=f'{member} was {"muted" if after.mute else "unmuted"} in voice chat', color=Color.orange())
372
+ await log_channel.send(embed=embed)
373
 
374
  if before.deaf != after.deaf:
375
  # deafening members
376
  embed = Embed(description=f'{member} was {"deafened" if after.deaf else "undeafened"} in voice chat', color=Color.orange())
377
+ await log_channel.send(embed=embed)
378
  except Exception as e:
379
  print(f"on_voice_state_update Error: {e}")
380
 
 
396
 
397
  @bot.event
398
  async def on_ready():
399
+ await asyncio.sleep(3)
400
  print('Logged on as', bot.user)
401
+ await asyncio.sleep(3)
402
+ log_channel = bot.get_channel(1036960509586587689)
403
+ print(f"log channel on_ready: {log_channel}")
404
 
405
 
406