lunarflu HF staff commited on
Commit
7c48ec1
1 Parent(s): 6dd716b
Files changed (1) hide show
  1. app.py +27 -44
app.py CHANGED
@@ -24,7 +24,6 @@ def convert_to_timezone(dt, tz):
24
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
25
  intents = discord.Intents.all()
26
  bot = commands.Bot(command_prefix='!', intents=intents)
27
- test = Client("https://lunarflu-bert-test.hf.space/--replicas/58fjw/")
28
 
29
  #rate_limiter = RateLimiter(max_calls=10, period=60) # needs testing
30
 
@@ -39,16 +38,11 @@ async def on_message(message):
39
  if message.author != bot.user:
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
46
  message_link = f"[#{message.channel.name}]({message.jump_url})"
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"""
54
  #Detecting certain unwanted strings
@@ -93,7 +87,7 @@ async def on_message(message):
93
  if test_server == 'False':
94
  alert = "<@&1108342563628404747>" # normal @alerts role
95
 
96
- await log_channel.send(
97
  f"[EXPERIMENTAL ALERT] {message.author} may be posting too quickly! \n"
98
  f"Spam count: {user_cooldowns[message.author.id]['count']}\n"
99
  f"Message content: {message.content}\n"
@@ -126,8 +120,7 @@ async def on_message_edit(before, after):
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,7 +137,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 log_channel.send(embed=embed)
148
 
149
  except Exception as e:
150
  print(f"on_message_edit Error: {e}")
@@ -154,8 +147,7 @@ async def on_message_delete(message):
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,7 +163,7 @@ async def on_message_delete(message):
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,7 +177,6 @@ async def on_member_update(before, after):
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,7 +185,7 @@ async def on_member_update(before, after):
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,7 +194,6 @@ async def on_member_update(before, after):
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,7 +220,7 @@ async def on_member_ban(guild, banned_user):
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,7 +229,7 @@ async def on_member_ban(guild, banned_user):
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,7 +247,7 @@ async def on_member_unban(guild, unbanned_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,7 +258,7 @@ async def on_member_unban(guild, unbanned_user):
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,7 +267,7 @@ async def on_member_join(member):
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,7 +276,6 @@ async def on_member_join(member):
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,7 +283,7 @@ async def on_member_remove(member):
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,9 +293,8 @@ async def on_member_remove(member):
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,9 +303,8 @@ async def on_guild_channel_create(channel):
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,9 +313,8 @@ async def on_guild_channel_delete(channel):
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,9 +323,8 @@ async def on_guild_role_create(role):
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,16 +333,15 @@ async def on_guild_role_delete(role):
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,16 +349,15 @@ async def on_guild_role_update(before, after):
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,12 +379,12 @@ async def check_github():
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
 
407
  def run_bot():
@@ -413,4 +396,4 @@ def greet(name):
413
  return "Hello " + name + "!"
414
 
415
  demo = gr.Interface(fn=greet, inputs="text", outputs="text")
416
- demo.launch()
 
24
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
25
  intents = discord.Intents.all()
26
  bot = commands.Bot(command_prefix='!', intents=intents)
 
27
 
28
  #rate_limiter = RateLimiter(max_calls=10, period=60) # needs testing
29
 
 
38
  if message.author != bot.user:
39
  lunarflu = bot.get_user(811235357663297546) #811235357663297546
40
  cakiki = bot.get_user(416019758492680203)
 
41
 
42
  """Backup"""
43
  number_of_messages = number_of_messages + 1
44
  message_link = f"[#{message.channel.name}]({message.jump_url})"
45
+ dm_message = await lunarflu.send(f"{number_of_messages}| {message_link} |{message.author}: {message.content}")
 
 
 
 
46
 
47
  """Antispam"""
48
  #Detecting certain unwanted strings
 
87
  if test_server == 'False':
88
  alert = "<@&1108342563628404747>" # normal @alerts role
89
 
90
+ await bot.log_channel.send(
91
  f"[EXPERIMENTAL ALERT] {message.author} may be posting too quickly! \n"
92
  f"Spam count: {user_cooldowns[message.author.id]['count']}\n"
93
  f"Message content: {message.content}\n"
 
120
  try:
121
  if before.author == bot.user:
122
  return
123
+
 
124
  if before.content != after.content:
125
  embed = Embed(color=Color.orange())
126
  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)
 
137
  embed.add_field(name="Attachments", value=attachment_urls, inline=False)
138
  #embed.set_footer(text=f"{datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')}")
139
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
140
+ await bot.log_channel.send(embed=embed)
141
 
142
  except Exception as e:
143
  print(f"on_message_edit Error: {e}")
 
147
  try:
148
  if message.author == bot.user:
149
  return
150
+
 
151
  embed = Embed(color=Color.red())
152
  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)
153
  embed.title = "Message Deleted"
 
163
  embed.add_field(name="Attachments", value=attachment_urls, inline=False)
164
  #embed.set_footer(text=f"{datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')}")
165
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
166
+ await bot.log_channel.send(embed=embed)
167
 
168
  except Exception as e:
169
  print(f"on_message_delete Error: {e}")
 
177
  async for entry in before.guild.audit_logs(limit=5):
178
  print(f'{entry.user} did {entry.action} to {entry.target}')
179
  """
 
180
  if before.nick != after.nick:
181
  embed = Embed(color=Color.orange())
182
  embed.set_author(name=f"{after} ID: {after.id}", icon_url=after.avatar.url if after.avatar else bot.user.avatar.url)
 
185
  embed.add_field(name="Old", value=before.nick, inline=True)
186
  embed.add_field(name="New", value=after.nick, inline=True)
187
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
188
+ await bot.log_channel.send(embed=embed)
189
 
190
  except Exception as e:
191
  print(f"on_member_update Error: {e}")
 
194
  @bot.event
195
  async def on_member_ban(guild, banned_user):
196
  try:
 
197
  await asyncio.sleep(1)
198
  entry1 = await guild.fetch_ban(banned_user)
199
  ban_reason = entry1.reason
 
220
 
221
  #user = bot.get_user(811235357663297546)
222
  #dm_message = await user.send(content=content, embed=embed)
223
+ await bot.log_channel.send(content=content, embed=embed)
224
 
225
  except Exception as e:
226
  print(f"on_member_ban Error: {e}")
 
229
  @bot.event
230
  async def on_member_unban(guild, unbanned_user):
231
  try:
232
+ await asyncio.sleep(5)
233
  async for entry in guild.audit_logs(action=discord.AuditLogAction.unban, limit=1):
234
  if unbanned_user == entry.target: # verify that unbanned user is in audit log
235
  moderator = entry.user
 
247
 
248
  #user = bot.get_user(811235357663297546)
249
  #dm_message = await user.send(content=content, embed=embed)
250
+ await bot.log_channel.send(content=content, embed=embed)
251
 
252
  except Exception as e:
253
  print(f"on_member_unban Error: {e}")
 
258
  @bot.event
259
  async def on_member_join(member):
260
  try:
261
+ await asyncio.sleep(5)
262
  embed = Embed(color=Color.blue())
263
  avatar_url = member.avatar.url if member.avatar else bot.user.avatar.url
264
  embed.set_author(name=f"{member} ID: {member.id}", icon_url=avatar_url)
 
267
  embed.add_field(name="Nickname", value=member.nick, inline=True)
268
  embed.add_field(name="Account Created At", value=member.created_at, inline=True)
269
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
270
+ await bot.log_channel.send(embed=embed)
271
 
272
  except Exception as e:
273
  print(f"on_member_join Error: {e}")
 
276
  @bot.event
277
  async def on_member_remove(member):
278
  try:
 
279
  embed = Embed(color=Color.blue())
280
  embed.set_author(name=f"{member} ID: {member.id}", icon_url=member.avatar.url if member.avatar else bot.user.avatar.url)
281
  embed.title = "User Left"
 
283
  embed.add_field(name="Nickname", value=member.nick, inline=True)
284
  embed.add_field(name="Account Created At", value=member.created_at, inline=True)
285
  embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
286
+ await bot.log_channel.send(embed=embed)
287
 
288
  except Exception as e:
289
  print(f"on_member_remove Error: {e}")
 
293
  async def on_guild_channel_create(channel):
294
  try:
295
  # creating channels
 
296
  embed = Embed(description=f'Channel {channel.mention} was created', color=Color.green())
297
+ await bot.log_channel.send(embed=embed)
298
  except Exception as e:
299
  print(f"on_guild_channel_create Error: {e}")
300
 
 
303
  async def on_guild_channel_delete(channel):
304
  try:
305
  # deleting channels, should ping @alerts for this
 
306
  embed = Embed(description=f'Channel {channel.name} ({channel.mention}) was deleted', color=Color.red())
307
+ await bot.log_channel.send(embed=embed)
308
  except Exception as e:
309
  print(f"on_guild_channel_delete Error: {e}")
310
 
 
313
  async def on_guild_role_create(role):
314
  try:
315
  # creating roles
 
316
  embed = Embed(description=f'Role {role.mention} was created', color=Color.green())
317
+ await bot.log_channel.send(embed=embed)
318
  except Exception as e:
319
  print(f"on_guild_role_create Error: {e}")
320
 
 
323
  async def on_guild_role_delete(role):
324
  try:
325
  # deleting roles, should ping @alerts for this
 
326
  embed = Embed(description=f'Role {role.name} ({role.mention}) was deleted', color=Color.red())
327
+ await bot.log_channel.send(embed=embed)
328
  except Exception as e:
329
  print(f"on_guild_role_delete Error: {e}")
330
 
 
333
  async def on_guild_role_update(before, after):
334
  try:
335
  # editing roles, could expand this
 
336
  if before.name != after.name:
337
  embed = Embed(description=f'Role {before.mention} was renamed to {after.name}', color=Color.orange())
338
+ await bot.log_channel.send(embed=embed)
339
 
340
  if before.permissions.administrator != after.permissions.administrator:
341
  # changes involving the administrator permission / sensitive permissions (can help to prevent mistakes)
342
  content = "<@&1108342563628404747>" # @alerts role
343
  embed = Embed(description=f'Role {after.mention} had its administrator permission {"enabled" if after.permissions.administrator else "disabled"}', color=Color.red())
344
+ await bot.log_channel.send(content=content, embed=embed)
345
  except Exception as e:
346
  print(f"on_guild_role_update Error: {e}")
347
 
 
349
  @bot.event
350
  async def on_voice_state_update(member, before, after):
351
  try:
 
352
  if before.mute != after.mute:
353
  # muting members
354
  embed = Embed(description=f'{member} was {"muted" if after.mute else "unmuted"} in voice chat', color=Color.orange())
355
+ await bot.log_channel.send(embed=embed)
356
 
357
  if before.deaf != after.deaf:
358
  # deafening members
359
  embed = Embed(description=f'{member} was {"deafened" if after.deaf else "undeafened"} in voice chat', color=Color.orange())
360
+ await bot.log_channel.send(embed=embed)
361
  except Exception as e:
362
  print(f"on_voice_state_update Error: {e}")
363
 
 
379
 
380
  @bot.event
381
  async def on_ready():
382
+ await asyncio.sleep(5)
383
  print('Logged on as', bot.user)
384
+ await asyncio.sleep(5)
385
+ bot.log_channel = bot.get_channel(1036960509586587689) # admin-logs
386
+ await asyncio.sleep(5)
387
+ print(bot.log_channel)
388
 
389
 
390
  def run_bot():
 
396
  return "Hello " + name + "!"
397
 
398
  demo = gr.Interface(fn=greet, inputs="text", outputs="text")
399
+ demo.launch()