lunarflu HF Staff commited on
Commit
6697a66
·
verified ·
1 Parent(s): a9668f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -89
app.py CHANGED
@@ -45,8 +45,8 @@ async def on_message(message):
45
  global number_of_messages
46
  if message.author != bot.user:
47
  message_cache[message.id] = message
48
- lunarflu = bot.get_user(811235357663297546) #811235357663297546
49
- cakiki = bot.get_user(416019758492680203)
50
 
51
  """Backup"""
52
 
@@ -72,12 +72,11 @@ async def on_message(message):
72
  r"@here",
73
  r"(https?:\/\/|http?:\/\/)?(www.)?(discord.(gg|io|me|li)|discordapp.com\/invite|discord.com\/invite)\/[^\s\/]+?(?=\b)"]
74
  if any(re.search(pattern, message.content, re.IGNORECASE) for pattern in forbidden_patterns):
75
- ignored_role_ids = [897381378172264449, 897376942817419265] #admins, huggingfolks
76
  if any(role.id in ignored_role_ids for role in message.author.roles):
77
  if message.author != lunarflu:
78
  return
79
  dm_unwanted = await lunarflu.send(f" {lunarflu.mention} [experimental] SUSPICIOUS MESSAGE: {message_link} | {message.author}: {message.content}")
80
- dm_unwanted = await cakiki.send(f" {cakiki.mention} [experimental] SUSPICIOUS MESSAGE: {message_link} | {message.author}: {message.content}")
81
  except Exception as e:
82
  print(f"Antispam->Detecting certain unwanted strings Error: {e}")
83
 
@@ -149,7 +148,7 @@ async def on_message(message):
149
  f"Message content: {message.content}\n"
150
  f"[Jump to message!](https://discord.com/channels/{message.guild.id}/{message.channel.id}/{message.id})\n"
151
  )
152
- # auto-ban
153
  """
154
  if spam_count >= timeout_threshold:
155
  try:
@@ -363,8 +362,6 @@ async def on_member_unban(guild, unbanned_user):
363
  print(f"on_member_unban Error: {e}")
364
 
365
  # admin stuff-----------------------------------------------------------------------------------------------------------------------
366
-
367
-
368
  @bot.event
369
  async def on_member_join(member):
370
  try:
@@ -483,10 +480,6 @@ async def on_guild_role_update(before, after):
483
  print(f"on_guild_role_update Error: {e}")
484
 
485
 
486
-
487
-
488
-
489
-
490
  @bot.event
491
  async def on_guild_role_update(before, after):
492
  try:
@@ -545,72 +538,6 @@ async def on_voice_state_update(member, before, after):
545
  except Exception as e:
546
  print(f"on_voice_state_update Error: {e}")
547
 
548
- # -------------------------------------------------------------------------------------------------------------------------------------
549
-
550
- # Custom persistent button that toggles a role for the clicking user.
551
- class RoleToggleButton(Button):
552
- def __init__(self, role: discord.Role):
553
- # Assign a fixed custom_id that uniquely identifies this button.
554
- # Ensure that the custom ID is unique among all buttons in your bot.
555
- super().__init__(
556
- label=role.name,
557
- style=discord.ButtonStyle.primary,
558
- custom_id=f"persistent_role_toggle_{role.id}"
559
- )
560
- self.role = role
561
-
562
- async def callback(self, interaction: discord.Interaction):
563
- if self.role in interaction.user.roles:
564
- try:
565
- await interaction.user.remove_roles(self.role)
566
- await interaction.response.send_message(
567
- f"Removed role: {self.role.name}", ephemeral=True
568
- )
569
- except Exception as e:
570
- await interaction.response.send_message(
571
- f"Error removing role: {e}", ephemeral=True
572
- )
573
- else:
574
- try:
575
- await interaction.user.add_roles(self.role)
576
- await interaction.response.send_message(
577
- f"Added role: {self.role.name}", ephemeral=True
578
- )
579
- except Exception as e:
580
- await interaction.response.send_message(
581
- f"Error adding role: {e}", ephemeral=True
582
- )
583
-
584
- # Persistent view that holds one toggle button per role.
585
- class PersistentRoleSelectionView(View):
586
- def __init__(self, roles: list):
587
- # Set timeout to None to keep the view indefinitely active.
588
- super().__init__(timeout=None)
589
- # Create a button for each role
590
- for role in roles:
591
- self.add_item(RoleToggleButton(role))
592
-
593
- # Command that sends the role buttons message.
594
- @bot.command(name="role_buttons")
595
- async def role_buttons(ctx):
596
- # Only allow lunarflu (ID 811235357663297546) to use this command.
597
- if ctx.author.id != 811235357663297546:
598
- await ctx.send("You are not authorized to use this command.", delete_after=10)
599
- return
600
-
601
- # List the role IDs you want to include (replace these with your actual role IDs).
602
- role_ids = [1014517792550166630, 1014548568238997616, 1014548769355862036, 1077250031180071023, 1093982736961785877, 1359533406102487281, 1174686719166124168, 1361696873764618381]
603
- roles = [ctx.guild.get_role(rid) for rid in role_ids if ctx.guild.get_role(rid) is not None]
604
-
605
- # Create the persistent view.
606
- view = PersistentRoleSelectionView(roles)
607
- # Send the message with the persistent view attached.
608
- await ctx.send("Click the buttons below to toggle roles:", view=view)
609
-
610
-
611
-
612
-
613
-
614
 
615
  # github test stuff -------------------------------------------------------------------------------------------------------------------
616
  """
@@ -638,11 +565,6 @@ async def on_ready():
638
  print(bot.log_channel)
639
  guild = bot.get_guild(879548962464493619)
640
 
641
- if guild:
642
- role_ids = [1014517792550166630, 1014548568238997616, 1014548769355862036, 1077250031180071023, 1093982736961785877, 1359533406102487281, 1174686719166124168, 1361696873764618381]
643
- roles = [guild.get_role(rid) for rid in role_ids if guild.get_role(rid) is not None]
644
- persistent_view = PersistentRoleSelectionView(roles)
645
- bot.add_view(persistent_view) # This makes the view persistent across restarts.
646
 
647
  for channel in guild.text_channels: # helps with more accurate logging across restarts
648
  try:
@@ -653,11 +575,6 @@ async def on_ready():
653
  await asyncio.sleep(0.1)
654
 
655
 
656
-
657
-
658
-
659
-
660
-
661
  def run_bot():
662
  bot.run(DISCORD_TOKEN)
663
 
@@ -666,7 +583,6 @@ threading.Thread(target=run_bot).start()
666
  with gr.Blocks() as demo:
667
  gr.Markdown(
668
  r"""
669
- # Client for the [HuggingFace Discord](https://hf.co/join/discord) bot
670
- All code for this bot is under the [app.py](https://huggingface.co/spaces/discord-community/HuggingMod/blob/main/app.py) file.
671
  """)
672
  demo.launch()
 
45
  global number_of_messages
46
  if message.author != bot.user:
47
  message_cache[message.id] = message
48
+ lunarflu = bot.get_user(811235357663297546) # might not need
49
+
50
 
51
  """Backup"""
52
 
 
72
  r"@here",
73
  r"(https?:\/\/|http?:\/\/)?(www.)?(discord.(gg|io|me|li)|discordapp.com\/invite|discord.com\/invite)\/[^\s\/]+?(?=\b)"]
74
  if any(re.search(pattern, message.content, re.IGNORECASE) for pattern in forbidden_patterns):
75
+ ignored_role_ids = [897381378172264449, 897376942817419265] #admins, supermods, mods
76
  if any(role.id in ignored_role_ids for role in message.author.roles):
77
  if message.author != lunarflu:
78
  return
79
  dm_unwanted = await lunarflu.send(f" {lunarflu.mention} [experimental] SUSPICIOUS MESSAGE: {message_link} | {message.author}: {message.content}")
 
80
  except Exception as e:
81
  print(f"Antispam->Detecting certain unwanted strings Error: {e}")
82
 
 
148
  f"Message content: {message.content}\n"
149
  f"[Jump to message!](https://discord.com/channels/{message.guild.id}/{message.channel.id}/{message.id})\n"
150
  )
151
+ # automatically take action based on spam_count - this doesn't work at the moment
152
  """
153
  if spam_count >= timeout_threshold:
154
  try:
 
362
  print(f"on_member_unban Error: {e}")
363
 
364
  # admin stuff-----------------------------------------------------------------------------------------------------------------------
 
 
365
  @bot.event
366
  async def on_member_join(member):
367
  try:
 
480
  print(f"on_guild_role_update Error: {e}")
481
 
482
 
 
 
 
 
483
  @bot.event
484
  async def on_guild_role_update(before, after):
485
  try:
 
538
  except Exception as e:
539
  print(f"on_voice_state_update Error: {e}")
540
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
541
 
542
  # github test stuff -------------------------------------------------------------------------------------------------------------------
543
  """
 
565
  print(bot.log_channel)
566
  guild = bot.get_guild(879548962464493619)
567
 
 
 
 
 
 
568
 
569
  for channel in guild.text_channels: # helps with more accurate logging across restarts
570
  try:
 
575
  await asyncio.sleep(0.1)
576
 
577
 
 
 
 
 
 
578
  def run_bot():
579
  bot.run(DISCORD_TOKEN)
580
 
 
583
  with gr.Blocks() as demo:
584
  gr.Markdown(
585
  r"""
586
+ # discord bot
 
587
  """)
588
  demo.launch()