lunarflu HF Staff commited on
Commit
2a9e01b
·
1 Parent(s): 9050f77
Files changed (1) hide show
  1. app.py +84 -3
app.py CHANGED
@@ -17,6 +17,8 @@ import matplotlib.pyplot as plt
17
  import matplotlib.image as mpimg
18
  import time
19
 
 
 
20
  # random + small llama #
21
 
22
 
@@ -81,9 +83,17 @@ class ButtonView(discord.ui.View):
81
  #---------------------------------------------------------------------------------------------------------------------------------------------------
82
  # Set up discord bot
83
  class MyClient(discord.Client):
 
 
 
 
 
 
 
 
84
  async def on_ready(self):
85
  print('Logged on as', self.user)
86
-
87
 
88
  async def on_message(self, message):
89
 
@@ -98,6 +108,19 @@ class MyClient(discord.Client):
98
  if message.author == self.user:
99
  return
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  # if the bot has this role, it won't run
102
  OFFLINE_ROLE_ID = 1103676632667017266 # 1103676632667017266 = @offline / under maintenance
103
  guild = message.guild
@@ -205,8 +228,66 @@ class MyClient(discord.Client):
205
  await ctx.reply('Here is the result of the second stage', file=discord.File(f, 'result.png'))
206
 
207
  #---------------------------------------------------------------------------------------------------------------------------------------------------
208
-
209
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
 
211
  DISCORD_TOKEN = os.environ.get("GRADIOTEST_TOKEN", None)
212
  intents = discord.Intents.default()
 
17
  import matplotlib.image as mpimg
18
  import time
19
 
20
+ import asyncio
21
+
22
  # random + small llama #
23
 
24
 
 
83
  #---------------------------------------------------------------------------------------------------------------------------------------------------
84
  # Set up discord bot
85
  class MyClient(discord.Client):
86
+
87
+ guild = 879548962464493619
88
+ OFFLINE_ROLE_ID = 1103676632667017266
89
+ bot_member = guild.get_member(self.user.id)
90
+
91
+ if any(role.id == OFFLINE_ROLE_ID for role in bot_member.roles):
92
+ return
93
+
94
  async def on_ready(self):
95
  print('Logged on as', self.user)
96
+ self.log_channel = self.get_channel(1036960509586587689) # 1100458786826747945 = bot test
97
 
98
  async def on_message(self, message):
99
 
 
108
  if message.author == self.user:
109
  return
110
 
111
+ #antispam---------------------------------------------------
112
+ if "discord.gg/" in message.content or "discordapp.com/invite/" in message.content:
113
+ try:
114
+ await message.delete()
115
+ await asyncio.sleep(5) # safety mechanism, can only delete slowly
116
+ except Exception as e:
117
+ print(f"An error occurred while deleting the message: {e}")
118
+ await asyncio.sleep(5)
119
+ elif "@everyone" in message.content or "@here" in message.content:
120
+ try:
121
+ await message.delete()
122
+ await asyncio.sleep(5) # safety mechanism, can only delete slowly
123
+
124
  # if the bot has this role, it won't run
125
  OFFLINE_ROLE_ID = 1103676632667017266 # 1103676632667017266 = @offline / under maintenance
126
  guild = message.guild
 
228
  await ctx.reply('Here is the result of the second stage', file=discord.File(f, 'result.png'))
229
 
230
  #---------------------------------------------------------------------------------------------------------------------------------------------------
231
+ async def on_message_delete(self, message):
232
+ if message.author == self.user:
233
+ return
234
+
235
+ embed = Embed(color=Color.red())
236
+ embed.set_author(name=f"{message.author} ID: {message.author.id}", icon_url=message.author.avatar.url)
237
+ embed.title = "Message Deleted"
238
+ embed.description = message.content or "*(empty message)*"
239
+ embed.add_field(name="Author Username", value=message.author.name, inline=True)
240
+ embed.add_field(name="Channel", value=message.channel.mention, inline=True)
241
+ embed.add_field(name="Message Created On", value=convert_to_timezone(message.created_at, zurich_tz), inline=True)
242
+ embed.add_field(name="Message ID", value=message.id, inline=True)
243
+ embed.add_field(name="Message Jump URL", value=f"[Jump to message!](https://discord.com/channels/{message.guild.id}/{message.channel.id}/{message.id})", inline=True)
244
+
245
+ if message.attachments:
246
+ attachment_urls = "\n".join([attachment.url for attachment in message.attachments])
247
+ embed.add_field(name="Attachments", value=attachment_urls, inline=False)
248
+
249
+ #embed.set_footer(text=f"{datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S UTC')}")
250
+ embed.set_footer(text=f"{convert_to_timezone(datetime.utcnow(), zurich_tz)}")
251
+
252
+ await self.log_channel.send(embed=embed)
253
+
254
+
255
+ async def on_guild_channel_create(channel):
256
+ # Channel creations
257
+ embed = Embed(description=f'Channel {channel.mention} was created', color=Color.green())
258
+ await bot.log_channel.send(embed=embed)
259
+
260
+
261
+ async def on_guild_channel_delete(channel):
262
+ # Channel deletions
263
+ embed = Embed(description=f'Channel {channel.name} ({channel.mention}) was deleted', color=Color.red())
264
+ await bot.log_channel.send(embed=embed)
265
+
266
+
267
+ async def on_guild_role_create(role):
268
+ # Creating roles
269
+ embed = Embed(description=f'Role {role.mention} was created', color=Color.green())
270
+ await bot.log_channel.send(embed=embed)
271
+
272
+
273
+ async def on_guild_role_delete(role):
274
+ # Deleting roles
275
+ embed = Embed(description=f'Role {role.name} ({role.mention}) was deleted', color=Color.red())
276
+ await bot.log_channel.send(embed=embed)
277
+
278
+
279
+ async def on_guild_role_update(before, after):
280
+ # Editing roles
281
+ if before.name != after.name:
282
+ embed = Embed(description=f'Role {before.mention} was renamed to {after.name}', color=Color.orange())
283
+ await bot.log_channel.send(embed=embed)
284
+
285
+ if before.permissions.administrator != after.permissions.administrator:
286
+ # Changes involving the administrator permission
287
+ certain_role_id = 1106995261487710411 # Replace with the actual role ID
288
+ certain_role = after.guild.get_role(certain_role_id)
289
+ embed = Embed(description=f'Role {after.mention} had its administrator permission {"enabled" if after.permissions.administrator else "disabled"}', color=Color.red())
290
+ await bot.log_channel.send(content=certain_role.mention, embed=embed)
291
 
292
  DISCORD_TOKEN = os.environ.get("GRADIOTEST_TOKEN", None)
293
  intents = discord.Intents.default()