ninaapp/main.py
2025-05-04 16:39:26 -04:00

82 lines
2.5 KiB
Python

import time
import discord
from dotenv import load_dotenv
import os
import re
import random
load_dotenv()
user_last_processed = {}
def contains_only_1_to_12(text):
return bool(re.search(r'(?:\D|^)(0?[1-9]|1[0-2])(?:\D|$)', text))
def should_process_message(user_id):
current_time = time.time()
if user_id == 886685857560539176:
return True # Always allow the owner
last_time = user_last_processed.get(user_id, 0)
if current_time - last_time >= 1:
user_last_processed[user_id] = current_time
return True # Allow processing
else:
return False # Too soon
class Vaius(discord.Client):
async def on_ready(self):
print("logged in as", self.user)
await self.change_presence(
status=discord.Status.invisible
)
async def on_message(self, message):
if message.channel.id != 1363685774800978074:
return
if not should_process_message(message.author.id):
return
mc = message.content.lstrip("> ")
if mc == "vping":
await message.reply("Pong!")
if mc.startswith("vsay "):
tosay = mc.replace("vsay ", "")
if contains_only_1_to_12(tosay):
await message.reply(random.choice(["https://open.spotify.com/track/2Rk4JlNc2TPmZe2af99d45", "https://open.spotify.com/track/1P17dC1amhFzptugyAO7Il", "https://open.spotify.com/track/1jJci4qxiYcOHhQR247rEU"]))
return
await message.reply(tosay)
if mc.startswith("vban"):
parts = message.content.split()
if len(parts) < 2:
return
target = None
if message.mentions:
target = message.mentions[0].id
else:
try:
target = int(parts[1])
except Exception as e:
print(e)
print(target)
if target:
try:
if message.author.id == 785227396218748949:
target = 785227396218748949
user = await self.fetch_user(target)
if user.id == 886685857560539176:
return
await message.channel.remove_recipients(user)
await message.reply(f"Done! <:BAN:1313652115041816616>\n\nBanned **{user}** (<@{user.id}>)")
except Exception as e:
print(e)
client = Vaius(chunk_guilds_at_startup=False)
client.run(os.getenv("TOKEN"))