Update configuration and README for improved setup and security; disable default API and emoji sync, and enhance Discord permission checks in API routes.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
148
bot/cogs/antinuke/antiIntegration.py
Normal file
148
bot/cogs/antinuke/antiIntegration.py
Normal file
@@ -0,0 +1,148 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiIntegration(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
async def fetch_audit_logs(self, guild, action):
|
||||
try:
|
||||
async for entry in guild.audit_logs(action=action, limit=1):
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
created_at = entry.created_at
|
||||
difference = (now - created_at).total_seconds() * 1000
|
||||
|
||||
if difference >= 3600000:
|
||||
return None
|
||||
|
||||
return entry
|
||||
|
||||
except Exception:
|
||||
return None
|
||||
return None
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=6, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if guild_id in self.cooldowns and event_name in self.cooldowns[guild_id]:
|
||||
if (now - self.cooldowns[guild_id][event_name]).total_seconds() < cooldown_duration:
|
||||
return False
|
||||
del self.cooldowns[guild_id][event_name]
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
async def is_blacklisted_guild(self, guild_id):
|
||||
async with aiosqlite.connect('db/block.db') as block_db:
|
||||
cursor = await block_db.execute("SELECT 1 FROM guild_blacklist WHERE guild_id = ?", (str(guild_id),))
|
||||
return await cursor.fetchone() is not None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_integrations_update(self, guild):
|
||||
if await self.is_blacklisted_guild(guild.id):
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(guild.id, 'integration_create'):
|
||||
return
|
||||
|
||||
logs = await self.fetch_audit_logs(guild, discord.AuditLogAction.integration_create)
|
||||
if logs is None:
|
||||
return
|
||||
|
||||
executor = logs.user
|
||||
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
extraowner_status = await cursor.fetchone()
|
||||
|
||||
if extraowner_status:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT mngweb FROM whitelisted_users WHERE guild_id = ? AND user_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
await self.ban_executor(guild, executor)
|
||||
|
||||
async def ban_executor(self, guild, executor):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.ban(executor, reason="Integration Create | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
|
||||
async def revert_integration_changes(self, guild):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.edit(integrations=[])
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except Exception:
|
||||
return
|
||||
144
bot/cogs/antinuke/anti_member_update.py
Normal file
144
bot/cogs/antinuke/anti_member_update.py
Normal file
@@ -0,0 +1,144 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiMemberUpdate(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
async def is_blacklisted_guild(self, guild_id):
|
||||
async with aiosqlite.connect('db/block.db') as block_db:
|
||||
cursor = await block_db.execute("SELECT 1 FROM guild_blacklist WHERE guild_id = ?", (str(guild_id),))
|
||||
return await cursor.fetchone() is not None
|
||||
|
||||
async def fetch_audit_logs(self, guild, action, target_id):
|
||||
if not guild.me.guild_permissions.ban_members:
|
||||
return None
|
||||
try:
|
||||
async for entry in guild.audit_logs(action=action, limit=1):
|
||||
if entry.target.id == target_id:
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
created_at = entry.created_at
|
||||
difference = (now - created_at).total_seconds() * 1000
|
||||
if difference < 3600000:
|
||||
return entry
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=5, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if guild_id in self.cooldowns and event_name in self.cooldowns[guild_id]:
|
||||
if (now - self.cooldowns[guild_id][event_name]).total_seconds() < cooldown_duration:
|
||||
return False
|
||||
del self.cooldowns[guild_id][event_name]
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_member_update(self, before, after):
|
||||
guild = before.guild
|
||||
|
||||
if await self.is_blacklisted_guild(guild.id):
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(guild.id, 'member_update'):
|
||||
return
|
||||
|
||||
log_entry = await self.fetch_audit_logs(guild, discord.AuditLogAction.member_role_update, after.id)
|
||||
if log_entry is None:
|
||||
return
|
||||
|
||||
executor = log_entry.user
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
if extra_owner_status:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT memup FROM whitelisted_users WHERE guild_id = ? AND user_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
try:
|
||||
new_role = next(role for role in after.roles if role not in before.roles)
|
||||
except StopIteration:
|
||||
return
|
||||
|
||||
if any([
|
||||
new_role.permissions.ban_members,
|
||||
new_role.permissions.administrator,
|
||||
new_role.permissions.manage_guild,
|
||||
new_role.permissions.manage_channels,
|
||||
new_role.permissions.manage_roles,
|
||||
new_role.permissions.mention_everyone,
|
||||
new_role.permissions.manage_webhooks
|
||||
]):
|
||||
await self.take_action_and_revert(after, executor, new_role)
|
||||
await asyncio.sleep(3)
|
||||
|
||||
async def take_action_and_revert(self, member, executor, new_role):
|
||||
retries = 3
|
||||
reason = "Member Role Update with Dangerous Permissions | Unwhitelisted User"
|
||||
while retries > 0:
|
||||
try:
|
||||
await member.remove_roles(new_role, reason=reason)
|
||||
await member.guild.ban(executor, reason=reason)
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
return
|
||||
122
bot/cogs/antinuke/antiban.py
Normal file
122
bot/cogs/antinuke/antiban.py
Normal file
@@ -0,0 +1,122 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiBan(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=5, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if guild_id in self.cooldowns and event_name in self.cooldowns[guild_id]:
|
||||
if (now - self.cooldowns[guild_id][event_name]).total_seconds() < cooldown_duration:
|
||||
return False
|
||||
del self.cooldowns[guild_id][event_name]
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
return True
|
||||
|
||||
async def fetch_audit_logs(self, guild, action, target_id):
|
||||
if not guild.me.guild_permissions.ban_members:
|
||||
return None
|
||||
try:
|
||||
async for entry in guild.audit_logs(action=action, limit=1):
|
||||
if entry.target.id == target_id:
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
if (now - entry.created_at).total_seconds() * 1000 >= 3600000:
|
||||
return None
|
||||
return entry
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_member_ban(self, guild, user):
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(guild.id, "member_ban"):
|
||||
return
|
||||
|
||||
entry = await self.fetch_audit_logs(guild, discord.AuditLogAction.ban, user.id)
|
||||
if not entry:
|
||||
return
|
||||
|
||||
executor = entry.user
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT ban FROM whitelisted_users WHERE guild_id = ? AND user_id = ?", (guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
await self.ban_executor(guild, executor, user)
|
||||
|
||||
async def ban_executor(self, guild, executor, user, retries=3):
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.ban(executor, reason="Member Ban | Unwhitelisted User")
|
||||
await guild.unban(user, reason="Reverting ban by unwhitelisted user")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
break
|
||||
except Exception:
|
||||
return
|
||||
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.unban(user, reason="Reverting ban by unwhitelisted user")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
break
|
||||
except Exception:
|
||||
return
|
||||
|
||||
136
bot/cogs/antinuke/antibotadd.py
Normal file
136
bot/cogs/antinuke/antibotadd.py
Normal file
@@ -0,0 +1,136 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiBotAdd(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=5, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if guild_id in self.cooldowns and event_name in self.cooldowns[guild_id]:
|
||||
if (now - self.cooldowns[guild_id][event_name]).total_seconds() < cooldown_duration:
|
||||
return False
|
||||
del self.cooldowns[guild_id][event_name]
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
return True
|
||||
|
||||
async def fetch_audit_logs(self, guild, action, target_id):
|
||||
if not guild.me.guild_permissions.kick_members:
|
||||
return None
|
||||
try:
|
||||
async for entry in guild.audit_logs(action=action, limit=1):
|
||||
if entry.target.id == target_id:
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
if (now - entry.created_at).total_seconds() * 1000 >= 3600000:
|
||||
return None
|
||||
return entry
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_member_join(self, member):
|
||||
if not member.bot:
|
||||
return
|
||||
|
||||
guild = member.guild
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(guild.id, "bot_add"):
|
||||
return
|
||||
|
||||
logs = await self.fetch_audit_logs(guild, discord.AuditLogAction.bot_add, member.id)
|
||||
if logs is None:
|
||||
return
|
||||
|
||||
executor = logs.user
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT botadd FROM whitelisted_users WHERE guild_id = ? AND user_id = ?", (guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?", (guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
|
||||
if extra_owner_status and extra_owner_status[0]:
|
||||
return
|
||||
|
||||
await self.take_action_and_kick_bot(guild, executor, member, "Unwhitelisted user added a bot")
|
||||
|
||||
async def take_action_and_kick_bot(self, guild, executor, bot_member, reason, retries=3):
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.kick(bot_member, reason=reason)
|
||||
await guild.ban(executor, reason=reason)
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
break
|
||||
except Exception:
|
||||
return
|
||||
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.ban(executor, reason=reason)
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
break
|
||||
except Exception:
|
||||
return
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(AntiBotAdd(bot))
|
||||
119
bot/cogs/antinuke/antichcr.py
Normal file
119
bot/cogs/antinuke/antichcr.py
Normal file
@@ -0,0 +1,119 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiChannelCreate(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=6, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
return True
|
||||
|
||||
async def fetch_audit_logs(self, guild, action, target_id, delay=1):
|
||||
if not guild.me.guild_permissions.ban_members:
|
||||
return None
|
||||
try:
|
||||
async for entry in guild.audit_logs(action=action, limit=1):
|
||||
if entry.target.id == target_id:
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
if (now - entry.created_at).total_seconds() * 1000 >= 3600000:
|
||||
return None
|
||||
await asyncio.sleep(delay)
|
||||
return entry
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
async def move_role_below_bot(self, guild):
|
||||
bot_top_role = guild.me.top_role
|
||||
most_populated_role = max(
|
||||
[role for role in guild.roles if role.position < bot_top_role.position and not role.managed and role != guild.default_role],
|
||||
key=lambda r: len(r.members),
|
||||
default=None
|
||||
)
|
||||
if most_populated_role:
|
||||
try:
|
||||
await most_populated_role.edit(position=bot_top_role.position - 1, reason="Emergency: Adjusting roles for security")
|
||||
except discord.Forbidden:
|
||||
pass
|
||||
except discord.HTTPException:
|
||||
pass
|
||||
|
||||
async def delete_channel_and_ban(self, channel, executor, delay=2, retries=3):
|
||||
while retries > 0:
|
||||
try:
|
||||
await channel.delete(reason="Channel created by unwhitelisted user")
|
||||
#await asyncio.sleep(delay)
|
||||
await channel.guild.ban(executor, reason="Channel Create | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After', delay)
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_channel_create(self, channel):
|
||||
guild = channel.guild
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(guild.id, "channel_create"):
|
||||
await self.move_role_below_bot(guild)
|
||||
await asyncio.sleep(5)
|
||||
|
||||
logs = await self.fetch_audit_logs(guild, discord.AuditLogAction.channel_create, channel.id, delay=2)
|
||||
if logs is None:
|
||||
return
|
||||
|
||||
executor = logs.user
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?", (guild.id, executor.id)) as cursor:
|
||||
if await cursor.fetchone():
|
||||
return
|
||||
|
||||
async with db.execute("SELECT chcr FROM whitelisted_users WHERE guild_id = ? AND user_id = ?", (guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
await self.delete_channel_and_ban(channel, executor, delay=2)
|
||||
130
bot/cogs/antinuke/antichdl.py
Normal file
130
bot/cogs/antinuke/antichdl.py
Normal file
@@ -0,0 +1,130 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiChannelDelete(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=5, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if guild_id in self.cooldowns and event_name in self.cooldowns[guild_id]:
|
||||
if (now - self.cooldowns[guild_id][event_name]).total_seconds() < cooldown_duration:
|
||||
return False
|
||||
del self.cooldowns[guild_id][event_name]
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
return True
|
||||
|
||||
async def fetch_audit_logs(self, guild, action, target_id):
|
||||
if not guild.me.guild_permissions.ban_members:
|
||||
return None
|
||||
try:
|
||||
async for entry in guild.audit_logs(action=action, limit=1):
|
||||
if entry.target.id == target_id:
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
if (now - entry.created_at).total_seconds() * 1000 >= 3600000:
|
||||
return None
|
||||
return entry
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_channel_delete(self, channel):
|
||||
guild = channel.guild
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(guild.id, "channel_delete"):
|
||||
return
|
||||
|
||||
logs = await self.fetch_audit_logs(guild, discord.AuditLogAction.channel_delete, channel.id)
|
||||
if logs is None:
|
||||
return
|
||||
|
||||
executor = logs.user
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?", (guild.id, executor.id)) as cursor:
|
||||
if await cursor.fetchone():
|
||||
return
|
||||
|
||||
async with db.execute("SELECT chdl FROM whitelisted_users WHERE guild_id = ? AND user_id = ?", (guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
await self.recreate_channel_and_ban(channel, executor)
|
||||
await asyncio.sleep(3)
|
||||
|
||||
async def recreate_channel_and_ban(self, channel, executor, retries=3):
|
||||
while retries > 0:
|
||||
try:
|
||||
new_channel = await channel.clone(reason="Channel Delete | Unwhitelisted User")
|
||||
await new_channel.edit(position=channel.position)
|
||||
break
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
break
|
||||
except Exception:
|
||||
return
|
||||
|
||||
if retries == 0:
|
||||
return
|
||||
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await channel.guild.ban(executor, reason="Channel Delete | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
break
|
||||
except Exception:
|
||||
return
|
||||
137
bot/cogs/antinuke/antichup.py
Normal file
137
bot/cogs/antinuke/antichup.py
Normal file
@@ -0,0 +1,137 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiChannelUpdate(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=5, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if guild_id in self.cooldowns and event_name in self.cooldowns[guild_id]:
|
||||
if (now - self.cooldowns[guild_id][event_name]).total_seconds() < cooldown_duration:
|
||||
return False
|
||||
del self.cooldowns[guild_id][event_name]
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
return True
|
||||
|
||||
async def fetch_audit_logs(self, guild, action, target_id):
|
||||
if not guild.me.guild_permissions.ban_members:
|
||||
return None
|
||||
try:
|
||||
async for entry in guild.audit_logs(action=action, limit=1):
|
||||
if entry.target.id == target_id:
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
if (now - entry.created_at).total_seconds() * 1000 >= 3600000:
|
||||
return None
|
||||
return entry
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_channel_update(self, before, after):
|
||||
guild = before.guild
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(guild.id, "channel_update"):
|
||||
return
|
||||
|
||||
logs = await self.fetch_audit_logs(guild, discord.AuditLogAction.channel_update, after.id)
|
||||
if logs is None:
|
||||
return
|
||||
|
||||
executor = logs.user
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?", (guild.id, executor.id)) as cursor:
|
||||
if await cursor.fetchone():
|
||||
return
|
||||
|
||||
async with db.execute("SELECT chup FROM whitelisted_users WHERE guild_id = ? AND user_id = ?", (guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
await self.revert_channel_update_and_ban(before, after, executor)
|
||||
await asyncio.sleep(3)
|
||||
|
||||
async def revert_channel_update_and_ban(self, before, after, executor, retries=3):
|
||||
while retries > 0:
|
||||
try:
|
||||
await after.edit(
|
||||
name=before.name,
|
||||
topic=before.topic,
|
||||
position=before.position,
|
||||
nsfw=before.nsfw,
|
||||
bitrate=before.bitrate if hasattr(before, 'bitrate') else None,
|
||||
user_limit=before.user_limit if hasattr(before, 'user_limit') else None,
|
||||
reason="Channel Update | Unwhitelisted User"
|
||||
)
|
||||
break
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
break
|
||||
except Exception:
|
||||
return
|
||||
|
||||
if retries == 0:
|
||||
return
|
||||
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await before.guild.ban(executor, reason="Channel Update | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
break
|
||||
except Exception:
|
||||
return
|
||||
139
bot/cogs/antinuke/antieveryone.py
Normal file
139
bot/cogs/antinuke/antieveryone.py
Normal file
@@ -0,0 +1,139 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
from datetime import timedelta
|
||||
|
||||
class AntiEveryone(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
|
||||
async def can_message_delete(self, guild_id, event_name, max_requests=5, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, message):
|
||||
if message.guild is None or not message.mention_everyone:
|
||||
return
|
||||
|
||||
guild = message.guild
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if message.author.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?", (guild.id, message.author.id)) as cursor:
|
||||
extraowner_status = await cursor.fetchone()
|
||||
|
||||
if extraowner_status:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT meneve FROM whitelisted_users WHERE guild_id = ? AND user_id = ?", (guild.id, message.author.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
|
||||
if not await self.can_message_delete(guild.id, 'mention_everyone'):
|
||||
return
|
||||
|
||||
try:
|
||||
await self.timeout_user(message.author)
|
||||
await self.delete_everyone_messages(message.channel)
|
||||
except Exception as e:
|
||||
print(f"An unexpected error occurred while handling {message.author.id}: {e}")
|
||||
|
||||
async def timeout_user(self, user):
|
||||
retries = 3
|
||||
duration = 60 * 60
|
||||
while retries > 0:
|
||||
try:
|
||||
await user.edit(timed_out_until=discord.utils.utcnow() + timedelta(seconds=duration), reason="Mentioned Everyone/Here | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
print(f"Failed to timeout {user.id} due to HTTPException: {e}")
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
print(f"Rate limit encountered while timing out. Retrying after {retry_after} seconds.")
|
||||
await asyncio.sleep(retry_after)
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
print(f"Rate limit encountered while timing out: {e}. Retrying in {e.retry_after} seconds.")
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception as e:
|
||||
print(f"An unexpected error occurred while timing out {user.id}: {e}")
|
||||
return
|
||||
|
||||
print(f"Failed to timeout {user.id} after multiple attempts due to rate limits.")
|
||||
|
||||
async def delete_everyone_messages(self, channel):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
async for msg in channel.history(limit=100):
|
||||
if msg.mention_everyone:
|
||||
await msg.delete()
|
||||
await asyncio.sleep(3)
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
print(f"Failed to delete messages due to HTTPException: {e}")
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
print(f"Rate limit encountered while deleting messages. Retrying after {retry_after} seconds.")
|
||||
await asyncio.sleep(retry_after)
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
print(f"Rate limit encountered while deleting messages: {e}. Retrying in {e.retry_after} seconds.")
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception as e:
|
||||
print(f"An unexpected error occurred while deleting messages: {e}")
|
||||
return
|
||||
|
||||
print(f"Failed to delete messages after multiple attempts due to rate limits.")
|
||||
189
bot/cogs/antinuke/antiguild.py
Normal file
189
bot/cogs/antinuke/antiguild.py
Normal file
@@ -0,0 +1,189 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiGuildUpdate(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
async def fetch_audit_logs(self, guild, action):
|
||||
try:
|
||||
async for entry in guild.audit_logs(action=action, limit=1):
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
created_at = entry.created_at
|
||||
difference = (now - created_at).total_seconds() * 1000
|
||||
|
||||
if difference >= 3600000:
|
||||
return None
|
||||
|
||||
return entry
|
||||
|
||||
except Exception:
|
||||
return None
|
||||
return None
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=5, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if guild_id in self.cooldowns and event_name in self.cooldowns[guild_id]:
|
||||
if (now - self.cooldowns[guild_id][event_name]).total_seconds() < cooldown_duration:
|
||||
return False
|
||||
del self.cooldowns[guild_id][event_name]
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
async def is_blacklisted_guild(self, guild_id):
|
||||
async with aiosqlite.connect('db/block.db') as block_db:
|
||||
cursor = await block_db.execute("SELECT 1 FROM guild_blacklist WHERE guild_id = ?", (str(guild_id),))
|
||||
return await cursor.fetchone() is not None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_update(self, before, after):
|
||||
guild = before
|
||||
if await self.is_blacklisted_guild(guild.id):
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(guild.id, 'guild_update'):
|
||||
return
|
||||
|
||||
logs = await self.fetch_audit_logs(guild, discord.AuditLogAction.guild_update)
|
||||
if logs is None:
|
||||
return
|
||||
|
||||
executor = logs.user
|
||||
difference = discord.utils.utcnow() - logs.created_at
|
||||
if difference.total_seconds() > 3600:
|
||||
return
|
||||
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT serverup FROM whitelisted_users WHERE guild_id = ? AND user_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
|
||||
if extra_owner_status and extra_owner_status[0]:
|
||||
return
|
||||
|
||||
await self.ban_executor_and_revert_changes(before, after, executor)
|
||||
|
||||
async def ban_executor_and_revert_changes(self, before, after, executor):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await self.ban_executor(before, executor)
|
||||
await self.revert_guild_changes(before, after)
|
||||
await asyncio.sleep(3)
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
await asyncio.sleep(retry_after)
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
|
||||
return
|
||||
|
||||
async def ban_executor(self, guild, executor):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.ban(executor, reason="Guild Update | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
|
||||
async def revert_guild_changes(self, before, after):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
if before.name != after.name:
|
||||
await after.edit(name=before.name)
|
||||
if before.icon != after.icon:
|
||||
await after.edit(icon=before.icon)
|
||||
if before.splash != after.splash:
|
||||
await after.edit(splash=before.splash)
|
||||
if before.banner != after.banner:
|
||||
await after.edit(banner=before.banner)
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
await asyncio.sleep(retry_after)
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except Exception:
|
||||
return
|
||||
|
||||
return
|
||||
127
bot/cogs/antinuke/antikick.py
Normal file
127
bot/cogs/antinuke/antikick.py
Normal file
@@ -0,0 +1,127 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiKick(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
async def is_blacklisted_guild(self, guild_id):
|
||||
async with aiosqlite.connect('db/block.db') as block_db:
|
||||
cursor = await block_db.execute("SELECT 1 FROM guild_blacklist WHERE guild_id = ?", (str(guild_id),))
|
||||
return await cursor.fetchone() is not None
|
||||
|
||||
async def fetch_audit_logs(self, guild, action, target_id):
|
||||
if not guild.me.guild_permissions.ban_members:
|
||||
return None
|
||||
try:
|
||||
async for entry in guild.audit_logs(action=action, limit=1):
|
||||
if entry.target.id == target_id:
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
created_at = entry.created_at
|
||||
difference = (now - created_at).total_seconds() * 1000
|
||||
if difference >= 3600000:
|
||||
return None
|
||||
return entry
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=6, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if guild_id in self.cooldowns and event_name in self.cooldowns[guild_id]:
|
||||
if (now - self.cooldowns[guild_id][event_name]).total_seconds() < cooldown_duration:
|
||||
return False
|
||||
del self.cooldowns[guild_id][event_name]
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_member_remove(self, member):
|
||||
if await self.is_blacklisted_guild(member.guild.id):
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (member.guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(member.guild.id, 'kick'):
|
||||
return
|
||||
|
||||
log_entry = await self.fetch_audit_logs(member.guild, discord.AuditLogAction.kick, member.id)
|
||||
if log_entry is None:
|
||||
return
|
||||
|
||||
executor = log_entry.user
|
||||
if executor.id in {member.guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
|
||||
(member.guild.id, executor.id)) as cursor:
|
||||
extraowner_status = await cursor.fetchone()
|
||||
if extraowner_status:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT kick FROM whitelisted_users WHERE guild_id = ? AND user_id = ?",
|
||||
(member.guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
await self.ban_executor(member.guild, executor)
|
||||
await asyncio.sleep(2)
|
||||
|
||||
async def ban_executor(self, guild, executor):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.ban(executor, reason="Member Kick | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
return
|
||||
104
bot/cogs/antinuke/antiprune.py
Normal file
104
bot/cogs/antinuke/antiprune.py
Normal file
@@ -0,0 +1,104 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import datetime
|
||||
import asyncio
|
||||
import pytz
|
||||
|
||||
class AntiPrune(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
async def fetch_audit_logs(self, guild, action):
|
||||
try:
|
||||
async for entry in guild.audit_logs(action=action, limit=1):
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
created_at = entry.created_at
|
||||
difference = (now - created_at).total_seconds() * 1000
|
||||
|
||||
if difference >= 3600000:
|
||||
return None
|
||||
|
||||
return entry
|
||||
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_member_remove(self, member):
|
||||
guild = member.guild
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
log_entry = await self.fetch_audit_logs(guild, discord.AuditLogAction.member_prune)
|
||||
if log_entry is None:
|
||||
return
|
||||
|
||||
executor = log_entry.user
|
||||
|
||||
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT prune FROM whitelisted_users WHERE guild_id = ? AND user_id = ?", (guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?", (guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
|
||||
if extra_owner_status:
|
||||
return
|
||||
|
||||
await self.ban_executor(guild, executor)
|
||||
|
||||
async def ban_executor(self, guild, executor):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.ban(executor, reason="Member Prune | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
print(f"Failed to ban {executor.id} due to missing permissions.")
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
print(f"Rate limit encountered. Retrying after {retry_after} seconds.")
|
||||
await asyncio.sleep(retry_after)
|
||||
retries -= 1
|
||||
else:
|
||||
print(f"HTTPException encountered: {e}")
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
print(f"Rate limit encountered while banning: {e}. Retrying in {e.retry_after} seconds.")
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception as e:
|
||||
print(f"An unexpected error occurred while banning {executor.id}: {e}")
|
||||
return
|
||||
|
||||
print(f"Failed to ban {executor.id} after multiple attempts due to rate limits.")
|
||||
152
bot/cogs/antinuke/antirlcr.py
Normal file
152
bot/cogs/antinuke/antirlcr.py
Normal file
@@ -0,0 +1,152 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiRoleCreate(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
async def is_blacklisted_guild(self, guild_id):
|
||||
async with aiosqlite.connect('db/block.db') as block_db:
|
||||
cursor = await block_db.execute("SELECT 1 FROM guild_blacklist WHERE guild_id = ?", (str(guild_id),))
|
||||
return await cursor.fetchone() is not None
|
||||
|
||||
async def fetch_audit_logs(self, guild, action):
|
||||
if not guild.me.guild_permissions.ban_members:
|
||||
return None
|
||||
try:
|
||||
async for entry in guild.audit_logs(action=action, limit=1):
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
created_at = entry.created_at
|
||||
difference = (now - created_at).total_seconds() * 1000
|
||||
|
||||
if difference >= 3600000:
|
||||
return None
|
||||
return entry
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=5, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if guild_id in self.cooldowns and event_name in self.cooldowns[guild_id]:
|
||||
if (now - self.cooldowns[guild_id][event_name]).total_seconds() < cooldown_duration:
|
||||
return False
|
||||
del self.cooldowns[guild_id][event_name]
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_role_create(self, role):
|
||||
guild = role.guild
|
||||
if await self.is_blacklisted_guild(guild.id):
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(guild.id, 'role_create'):
|
||||
return
|
||||
|
||||
log_entry = await self.fetch_audit_logs(guild, discord.AuditLogAction.role_create)
|
||||
if log_entry is None:
|
||||
return
|
||||
|
||||
executor = log_entry.user
|
||||
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
if extra_owner_status:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT rlcr FROM whitelisted_users WHERE guild_id = ? AND user_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
await self.ban_executor_and_delete_role(guild, executor, role)
|
||||
await asyncio.sleep(3)
|
||||
|
||||
async def ban_executor_and_delete_role(self, guild, executor, role):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await self.ban_executor(guild, executor)
|
||||
await role.delete(reason="Role created by unwhitelisted user")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
|
||||
async def ban_executor(self, guild, executor):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.ban(executor, reason="Role Create | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
return
|
||||
173
bot/cogs/antinuke/antirldl.py
Normal file
173
bot/cogs/antinuke/antirldl.py
Normal file
@@ -0,0 +1,173 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiRoleDelete(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
async def is_blacklisted_guild(self, guild_id):
|
||||
async with aiosqlite.connect('db/block.db') as block_db:
|
||||
cursor = await block_db.execute("SELECT 1 FROM guild_blacklist WHERE guild_id = ?", (str(guild_id),))
|
||||
return await cursor.fetchone() is not None
|
||||
|
||||
async def fetch_audit_logs(self, guild, action):
|
||||
if not guild.me.guild_permissions.ban_members:
|
||||
return None
|
||||
try:
|
||||
async for entry in guild.audit_logs(action=action, limit=1):
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
created_at = entry.created_at
|
||||
difference = (now - created_at).total_seconds() * 1000
|
||||
|
||||
if difference >= 3600000:
|
||||
return None
|
||||
return entry
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=5, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if guild_id in self.cooldowns and event_name in self.cooldowns[guild_id]:
|
||||
if (now - self.cooldowns[guild_id][event_name]).total_seconds() < cooldown_duration:
|
||||
return False
|
||||
del self.cooldowns[guild_id][event_name]
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_role_delete(self, role):
|
||||
guild = role.guild
|
||||
if await self.is_blacklisted_guild(guild.id):
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(guild.id, 'role_delete'):
|
||||
return
|
||||
|
||||
log_entry = await self.fetch_audit_logs(guild, discord.AuditLogAction.role_delete)
|
||||
if log_entry is None:
|
||||
return
|
||||
|
||||
executor = log_entry.user
|
||||
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
if extra_owner_status:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT rldl FROM whitelisted_users WHERE guild_id = ? AND user_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
await self.ban_executor_and_recreate_role(guild, executor, role)
|
||||
await asyncio.sleep(2)
|
||||
|
||||
async def ban_executor_and_recreate_role(self, guild, executor, role):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await self.ban_executor(guild, executor)
|
||||
await self.recreate_role(guild, role)
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
return
|
||||
|
||||
async def ban_executor(self, guild, executor):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.ban(executor, reason="Role Delete | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
return
|
||||
|
||||
async def recreate_role(self, guild, role):
|
||||
try:
|
||||
await guild.create_role(
|
||||
name=role.name,
|
||||
permissions=role.permissions,
|
||||
color=role.color,
|
||||
hoist=role.hoist,
|
||||
mentionable=role.mentionable,
|
||||
reason="Role deleted by unwhitelisted user"
|
||||
)
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
except Exception:
|
||||
return
|
||||
160
bot/cogs/antinuke/antirlup.py
Normal file
160
bot/cogs/antinuke/antirlup.py
Normal file
@@ -0,0 +1,160 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiRoleUpdate(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
async def is_blacklisted_guild(self, guild_id):
|
||||
async with aiosqlite.connect('db/block.db') as block_db:
|
||||
cursor = await block_db.execute("SELECT 1 FROM guild_blacklist WHERE guild_id = ?", (str(guild_id),))
|
||||
return await cursor.fetchone() is not None
|
||||
|
||||
async def fetch_audit_logs(self, guild, action, target_id):
|
||||
if not guild.me.guild_permissions.ban_members:
|
||||
return None
|
||||
try:
|
||||
async for entry in guild.audit_logs(action=action, limit=1):
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
created_at = entry.created_at
|
||||
difference = (now - created_at).total_seconds() * 1000
|
||||
if difference >= 3600000:
|
||||
return None
|
||||
if entry.target.id == target_id:
|
||||
return entry
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=5, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if guild_id in self.cooldowns and event_name in self.cooldowns[guild_id]:
|
||||
if (now - self.cooldowns[guild_id][event_name]).total_seconds() < cooldown_duration:
|
||||
return False
|
||||
del self.cooldowns[guild_id][event_name]
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_role_update(self, before, after):
|
||||
guild = before.guild
|
||||
if await self.is_blacklisted_guild(guild.id):
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(guild.id, 'role_update'):
|
||||
return
|
||||
|
||||
log_entry = await self.fetch_audit_logs(guild, discord.AuditLogAction.role_update, before.id)
|
||||
if log_entry is None:
|
||||
return
|
||||
|
||||
executor = log_entry.user
|
||||
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT rlup FROM whitelisted_users WHERE guild_id = ? AND user_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
if extra_owner_status:
|
||||
return
|
||||
|
||||
await self.ban_executor_and_revert_role_update(guild, executor, before, after)
|
||||
await asyncio.sleep(3)
|
||||
|
||||
async def ban_executor_and_revert_role_update(self, guild, executor, before, after):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await self.ban_executor(guild, executor)
|
||||
await after.edit(
|
||||
name=before.name,
|
||||
permissions=before.permissions,
|
||||
color=before.color,
|
||||
hoist=before.hoist,
|
||||
mentionable=before.mentionable,
|
||||
reason="Role updated by unwhitelisted user"
|
||||
)
|
||||
return
|
||||
except discord.Forbidden:
|
||||
print(f"Failed to ban {executor.id} or revert the role update {before.id} due to missing permissions.")
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
|
||||
async def ban_executor(self, guild, executor):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.ban(executor, reason="Role Update | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
print(f"Failed to ban {executor.id} due to missing permissions.")
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
134
bot/cogs/antinuke/antiwebhook.py
Normal file
134
bot/cogs/antinuke/antiwebhook.py
Normal file
@@ -0,0 +1,134 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiWebhookUpdate(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
async def fetch_audit_logs(self, guild, action, target_id):
|
||||
try:
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
logs = [entry async for entry in guild.audit_logs(action=action, limit=1)]
|
||||
for entry in logs:
|
||||
if entry.target.id == target_id:
|
||||
difference = (now - entry.created_at).total_seconds() * 1000
|
||||
if difference < 3600000: # Only consider entries from the last hour
|
||||
return entry
|
||||
except Exception:
|
||||
return None
|
||||
return None
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=6, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if guild_id in self.cooldowns and event_name in self.cooldowns[guild_id]:
|
||||
if (now - self.cooldowns[guild_id][event_name]).total_seconds() < cooldown_duration:
|
||||
return False
|
||||
del self.cooldowns[guild_id][event_name]
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
async def is_blacklisted_guild(self, guild_id):
|
||||
async with aiosqlite.connect('db/block.db') as block_db:
|
||||
cursor = await block_db.execute("SELECT 1 FROM guild_blacklist WHERE guild_id = ?", (str(guild_id),))
|
||||
return await cursor.fetchone() is not None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_webhooks_update(self, channel):
|
||||
guild = channel.guild
|
||||
if await self.is_blacklisted_guild(guild.id):
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(guild.id, 'webhook_update'):
|
||||
return
|
||||
|
||||
entry = await self.fetch_audit_logs(guild, discord.AuditLogAction.webhook_update, channel.id)
|
||||
if entry is None:
|
||||
return
|
||||
|
||||
executor = entry.user
|
||||
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT mngweb FROM whitelisted_users WHERE guild_id = ? AND user_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
|
||||
if extra_owner_status and extra_owner_status[0]:
|
||||
return
|
||||
|
||||
try:
|
||||
await self.ban_executor_and_delete_webhook(guild, executor, entry.target)
|
||||
await asyncio.sleep(3)
|
||||
except Exception:
|
||||
return
|
||||
|
||||
async def ban_executor_and_delete_webhook(self, guild, executor, webhook):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.ban(executor, reason="Webhook Update | Unwhitelisted User")
|
||||
if webhook:
|
||||
await webhook.delete(reason="Webhook updated by unwhitelisted user")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
|
||||
retries -= 1
|
||||
134
bot/cogs/antinuke/antiwebhookcr.py
Normal file
134
bot/cogs/antinuke/antiwebhookcr.py
Normal file
@@ -0,0 +1,134 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiWebhookCreate(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
async def fetch_audit_logs(self, guild, action, target_id):
|
||||
try:
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
logs = [entry async for entry in guild.audit_logs(action=action, limit=1)]
|
||||
for entry in logs:
|
||||
if entry.target.id == target_id:
|
||||
difference = (now - entry.created_at).total_seconds() * 1000
|
||||
if difference < 3600000:
|
||||
return entry
|
||||
except Exception:
|
||||
return None
|
||||
return None
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=6, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if guild_id in self.cooldowns and event_name in self.cooldowns[guild_id]:
|
||||
if (now - self.cooldowns[guild_id][event_name]).total_seconds() < cooldown_duration:
|
||||
return False
|
||||
del self.cooldowns[guild_id][event_name]
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
async def is_blacklisted_guild(self, guild_id):
|
||||
async with aiosqlite.connect('db/block.db') as block_db:
|
||||
cursor = await block_db.execute("SELECT 1 FROM guild_blacklist WHERE guild_id = ?", (str(guild_id),))
|
||||
return await cursor.fetchone() is not None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_webhooks_create(self, channel):
|
||||
guild = channel.guild
|
||||
if await self.is_blacklisted_guild(guild.id):
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(guild.id, 'webhook_create'):
|
||||
return
|
||||
|
||||
entry = await self.fetch_audit_logs(guild, discord.AuditLogAction.webhook_create, channel.id)
|
||||
if entry is None:
|
||||
return
|
||||
|
||||
executor = entry.user
|
||||
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT mngweb FROM whitelisted_users WHERE guild_id = ? AND user_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
|
||||
if extra_owner_status and extra_owner_status[0]:
|
||||
return
|
||||
|
||||
try:
|
||||
await self.ban_executor_and_delete_webhook(guild, executor, entry.target)
|
||||
await asyncio.sleep(3)
|
||||
except Exception:
|
||||
return
|
||||
|
||||
async def ban_executor_and_delete_webhook(self, guild, executor, webhook):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.ban(executor, reason="Webhook Create | Unwhitelisted User")
|
||||
if webhook:
|
||||
await webhook.delete(reason="Webhook Created by unwhitelisted user")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
|
||||
retries -= 1
|
||||
132
bot/cogs/antinuke/antiwebhookdl.py
Normal file
132
bot/cogs/antinuke/antiwebhookdl.py
Normal file
@@ -0,0 +1,132 @@
|
||||
# ╔══════════════════════════════════════════════════════════════════╗
|
||||
# ║ ║
|
||||
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
|
||||
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
|
||||
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
|
||||
# ║ ║
|
||||
# ║ © 2026 CodeX Devs — All Rights Reserved ║
|
||||
# ║ ║
|
||||
# ║ discord ── https://discord.gg/codexdev ║
|
||||
# ║ youtube ── https://youtube.com/@CodeXDevs ║
|
||||
# ║ github ── https://github.com/RayExo ║
|
||||
# ║ ║
|
||||
# ╚══════════════════════════════════════════════════════════════════╝
|
||||
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import datetime
|
||||
import pytz
|
||||
|
||||
class AntiWebhookDelete(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.event_limits = {}
|
||||
self.cooldowns = {}
|
||||
|
||||
async def fetch_audit_logs(self, guild, action, target_id):
|
||||
try:
|
||||
now = datetime.datetime.now(pytz.utc)
|
||||
logs = [entry async for entry in guild.audit_logs(action=action, limit=1)]
|
||||
for entry in logs:
|
||||
if entry.target.id == target_id:
|
||||
difference = (now - entry.created_at).total_seconds() * 1000
|
||||
if difference < 3600000: # Only consider entries from the last hour
|
||||
return entry
|
||||
except Exception:
|
||||
return None
|
||||
return None
|
||||
|
||||
def can_fetch_audit(self, guild_id, event_name, max_requests=6, interval=10, cooldown_duration=300):
|
||||
now = datetime.datetime.now()
|
||||
self.event_limits.setdefault(guild_id, {}).setdefault(event_name, []).append(now)
|
||||
|
||||
timestamps = self.event_limits[guild_id][event_name]
|
||||
timestamps = [t for t in timestamps if (now - t).total_seconds() <= interval]
|
||||
self.event_limits[guild_id][event_name] = timestamps
|
||||
|
||||
if guild_id in self.cooldowns and event_name in self.cooldowns[guild_id]:
|
||||
if (now - self.cooldowns[guild_id][event_name]).total_seconds() < cooldown_duration:
|
||||
return False
|
||||
del self.cooldowns[guild_id][event_name]
|
||||
|
||||
if len(timestamps) > max_requests:
|
||||
self.cooldowns.setdefault(guild_id, {})[event_name] = now
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
async def is_blacklisted_guild(self, guild_id):
|
||||
async with aiosqlite.connect('db/block.db') as block_db:
|
||||
cursor = await block_db.execute("SELECT 1 FROM guild_blacklist WHERE guild_id = ?", (str(guild_id),))
|
||||
return await cursor.fetchone() is not None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_webhooks_delete(self, channel):
|
||||
guild = channel.guild
|
||||
if await self.is_blacklisted_guild(guild.id):
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
if not self.can_fetch_audit(guild.id, 'webhook_delete'):
|
||||
return
|
||||
|
||||
entry = await self.fetch_audit_logs(guild, discord.AuditLogAction.webhook_delete, channel.id)
|
||||
if entry is None:
|
||||
return
|
||||
|
||||
executor = entry.user
|
||||
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT mngweb FROM whitelisted_users WHERE guild_id = ? AND user_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
|
||||
(guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
|
||||
if extra_owner_status and extra_owner_status[0]:
|
||||
return
|
||||
|
||||
try:
|
||||
await self.ban_executor(guild, executor)
|
||||
await asyncio.sleep(3)
|
||||
except Exception:
|
||||
return
|
||||
|
||||
async def ban_executor(self, guild, executor):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.ban(executor, reason="Webhook Delete | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
await asyncio.sleep(float(retry_after))
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception:
|
||||
return
|
||||
|
||||
retries -= 1
|
||||
94
bot/cogs/antinuke/extra events (unused)/antiemocr.py
Normal file
94
bot/cogs/antinuke/extra events (unused)/antiemocr.py
Normal file
@@ -0,0 +1,94 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import random
|
||||
import datetime
|
||||
|
||||
class AntiEmojiCreate(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
async def fetch_audit_logs(self, guild, action):
|
||||
try:
|
||||
await asyncio.sleep(random.uniform(0.5, 2.0))
|
||||
logs = [entry async for entry in guild.audit_logs(action=action, limit=1, after=datetime.datetime.now() - datetime.timedelta(seconds=3))]
|
||||
if logs:
|
||||
return logs[0]
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
await asyncio.sleep(retry_after)
|
||||
return await self.fetch_audit_logs(guild, action)
|
||||
except Exception as e:
|
||||
print(f"An error occurred while fetching audit logs: {e}")
|
||||
return None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_emojis_update(self, guild, before, after):
|
||||
if len(after) > len(before):
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
logs = await self.fetch_audit_logs(guild, discord.AuditLogAction.emoji_create)
|
||||
if logs is None:
|
||||
return
|
||||
executor = logs.user
|
||||
difference = discord.utils.utcnow() - logs.created_at
|
||||
if difference.total_seconds() > 3600:
|
||||
return
|
||||
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT mngstemo FROM whitelisted_users WHERE guild_id = ? AND user_id = ?", (guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?", (guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
|
||||
if extra_owner_status:
|
||||
return
|
||||
|
||||
await self.kick_executor(guild, executor)
|
||||
|
||||
async def kick_executor(self, guild, executor):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.kick(executor, reason="Emoji Create | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
print(f"Failed to kick {executor.id} due to missing permissions.")
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
print(f"Failed to kick {executor.id} due to HTTPException: {e}")
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
print(f"Rate limit encountered while kicking. Retrying after {retry_after} seconds.")
|
||||
await asyncio.sleep(retry_after)
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
print(f"Rate limit encountered while kicking: {e}. Retrying in {e.retry_after} seconds.")
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception as e:
|
||||
print(f"An unexpected error occurred while kicking {executor.id}: {e}")
|
||||
return
|
||||
|
||||
print(f"Failed to kick {executor.id} after multiple attempts due to rate limits.")
|
||||
95
bot/cogs/antinuke/extra events (unused)/antiemodl.py
Normal file
95
bot/cogs/antinuke/extra events (unused)/antiemodl.py
Normal file
@@ -0,0 +1,95 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import random
|
||||
import datetime
|
||||
|
||||
class AntiEmojiDelete(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
async def fetch_audit_logs(self, guild, action):
|
||||
try:
|
||||
await asyncio.sleep(random.uniform(0.5, 2.0))
|
||||
logs = [entry async for entry in guild.audit_logs(action=action, limit=1, after=datetime.datetime.utcnow() - datetime.timedelta(seconds=3))]
|
||||
if logs:
|
||||
return logs[0]
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
await asyncio.sleep(retry_after)
|
||||
return await self.fetch_audit_logs(guild, action)
|
||||
except Exception as e:
|
||||
print(f"An error occurred while fetching audit logs: {e}")
|
||||
return None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_emojis_update(self, guild, before, after):
|
||||
if len(after) < len(before):
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
logs = await self.fetch_audit_logs(guild, discord.AuditLogAction.emoji_delete)
|
||||
if logs is None:
|
||||
return
|
||||
|
||||
executor = logs.user
|
||||
difference = discord.utils.utcnow() - logs.created_at
|
||||
if difference.total_seconds() > 3600:
|
||||
return
|
||||
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT mngstemo FROM whitelisted_users WHERE guild_id = ? AND user_id = ?", (guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?", (guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
|
||||
if extra_owner_status:
|
||||
return
|
||||
|
||||
await self.kick_executor(guild, executor)
|
||||
|
||||
async def kick_executor(self, guild, executor):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.kick(executor, reason="Emoji Delete | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
print(f"Failed to kick {executor.id} due to missing permissions.")
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
print(f"Failed to kick {executor.id} due to HTTPException: {e}")
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
print(f"Rate limit encountered while kicking. Retrying after {retry_after} seconds.")
|
||||
await asyncio.sleep(retry_after)
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
print(f"Rate limit encountered while kicking: {e}. Retrying in {e.retry_after} seconds.")
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception as e:
|
||||
print(f"An unexpected error occurred while kicking {executor.id}: {e}")
|
||||
return
|
||||
|
||||
print(f"Failed to kick {executor.id} after multiple attempts due to rate limits.")
|
||||
95
bot/cogs/antinuke/extra events (unused)/antiemoup.py
Normal file
95
bot/cogs/antinuke/extra events (unused)/antiemoup.py
Normal file
@@ -0,0 +1,95 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
import random
|
||||
import datetime
|
||||
|
||||
class AntiEmojiUpdate(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
async def fetch_audit_logs(self, guild, action):
|
||||
try:
|
||||
await asyncio.sleep(random.uniform(0.5, 2.0))
|
||||
logs = [entry async for entry in guild.audit_logs(action=action, limit=1, after=datetime.datetime.utcnow() - datetime.timedelta(seconds=3))]
|
||||
if logs:
|
||||
return logs[0]
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
await asyncio.sleep(retry_after)
|
||||
return await self.fetch_audit_logs(guild, action)
|
||||
except Exception as e:
|
||||
print(f"An error occurred while fetching audit logs: {e}")
|
||||
return None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_emojis_update(self, guild, before, after):
|
||||
if len(after) == len(before): # An emoji was updated
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
logs = await self.fetch_audit_logs(guild, discord.AuditLogAction.emoji_update)
|
||||
if logs is None:
|
||||
return
|
||||
|
||||
executor = logs.user
|
||||
difference = discord.utils.utcnow() - logs.created_at
|
||||
if difference.total_seconds() > 3600:
|
||||
return
|
||||
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT mngstemo FROM whitelisted_users WHERE guild_id = ? AND user_id = ?", (guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?", (guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
|
||||
if extra_owner_status:
|
||||
return
|
||||
|
||||
await self.kick_executor(guild, executor)
|
||||
|
||||
async def kick_executor(self, guild, executor):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.kick(executor, reason="Emoji Update | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
print(f"Failed to kick {executor.id} due to missing permissions.")
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
print(f"Failed to kick {executor.id} due to HTTPException: {e}")
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
print(f"Rate limit encountered while kicking. Retrying after {retry_after} seconds.")
|
||||
await asyncio.sleep(retry_after)
|
||||
retries -= 1
|
||||
else:
|
||||
return
|
||||
else:
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
print(f"Rate limit encountered while kicking: {e}. Retrying in {e.retry_after} seconds.")
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception as e:
|
||||
print(f"An unexpected error occurred while kicking {executor.id}: {e}")
|
||||
return
|
||||
|
||||
print(f"Failed to kick {executor.id} after multiple attempts due to rate limits.")
|
||||
99
bot/cogs/antinuke/extra events (unused)/antisticker.py
Normal file
99
bot/cogs/antinuke/extra events (unused)/antisticker.py
Normal file
@@ -0,0 +1,99 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from datetime import timedelta, datetime
|
||||
import aiosqlite
|
||||
import asyncio
|
||||
|
||||
class AntiSticker(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
async def fetch_audit_logs(self, guild, action):
|
||||
try:
|
||||
await asyncio.sleep(1)
|
||||
logs = [entry async for entry in guild.audit_logs(action=action, limit=1, after=discord.utils.utcnow() - timedelta(hours=1))]
|
||||
if logs:
|
||||
return logs[0]
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
await asyncio.sleep(retry_after)
|
||||
return await self.fetch_audit_logs(guild, action)
|
||||
except Exception as e:
|
||||
print(f"An error occurred while fetching audit logs: {e}")
|
||||
return None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_stickers_update(self, guild, before, after):
|
||||
if len(after) > len(before):
|
||||
action = discord.AuditLogAction.sticker_create
|
||||
elif len(after) < len(before):
|
||||
action = discord.AuditLogAction.sticker_delete
|
||||
else:
|
||||
action = discord.AuditLogAction.sticker_update
|
||||
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
log_entry = await self.fetch_audit_logs(guild, action)
|
||||
if log_entry is None:
|
||||
return
|
||||
|
||||
executor = log_entry.user
|
||||
difference = discord.utils.utcnow() - log_entry.created_at
|
||||
|
||||
if difference.total_seconds() > 3600:
|
||||
return
|
||||
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT mngstemo FROM whitelisted_users WHERE guild_id = ? AND user_id = ?", (guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?", (guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
|
||||
if extra_owner_status:
|
||||
return
|
||||
|
||||
await self.kick_executor(guild, executor)
|
||||
|
||||
async def kick_executor(self, guild, executor):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.kick(executor, reason="Sticker Action | Unwhitelisted User")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
print(f"Failed to kick {executor.id} due to missing permissions.")
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
print(f"Rate limit encountered. Retrying after {retry_after} seconds.")
|
||||
await asyncio.sleep(retry_after)
|
||||
retries -= 1
|
||||
else:
|
||||
print(f"HTTPException encountered: {e}")
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
print(f"Rate limit encountered while kicking: {e}. Retrying in {e.retry_after} seconds.")
|
||||
await asyncio.sleep(e.retry_after)
|
||||
retries -= 1
|
||||
except Exception as e:
|
||||
print(f"An unexpected error occurred while kicking {executor.id}: {e}")
|
||||
return
|
||||
|
||||
print(f"Failed to kick {executor.id} after multiple attempts due to rate limits.")
|
||||
88
bot/cogs/antinuke/extra events (unused)/antiunban.py
Normal file
88
bot/cogs/antinuke/extra events (unused)/antiunban.py
Normal file
@@ -0,0 +1,88 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import aiosqlite
|
||||
from datetime import timedelta, datetime
|
||||
import asyncio
|
||||
|
||||
class AntiUnban(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
async def fetch_audit_logs(self, guild, action, target_id):
|
||||
try:
|
||||
async for entry in guild.audit_logs(limit=1, action=action):
|
||||
if entry.target.id == target_id:
|
||||
return entry
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
await asyncio.sleep(retry_after)
|
||||
return await self.fetch_audit_logs(guild, action, target_id)
|
||||
except Exception as e:
|
||||
print(f"An error occurred while fetching audit logs: {e}")
|
||||
return None
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_member_unban(self, guild, user):
|
||||
async with aiosqlite.connect('db/anti.db') as db:
|
||||
async with db.execute("SELECT status FROM antinuke WHERE guild_id = ?", (guild.id,)) as cursor:
|
||||
antinuke_status = await cursor.fetchone()
|
||||
|
||||
if not antinuke_status or not antinuke_status[0]:
|
||||
return
|
||||
|
||||
log_entry = await self.fetch_audit_logs(guild, discord.AuditLogAction.unban, user.id)
|
||||
if log_entry is None:
|
||||
return
|
||||
|
||||
executor = log_entry.user
|
||||
|
||||
if executor.id in {guild.owner_id, self.bot.user.id}:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?", (guild.id, executor.id)) as cursor:
|
||||
extra_owner_status = await cursor.fetchone()
|
||||
|
||||
if extra_owner_status:
|
||||
return
|
||||
|
||||
async with db.execute("SELECT ban FROM whitelisted_users WHERE guild_id = ? AND user_id = ?", (guild.id, executor.id)) as cursor:
|
||||
whitelist_status = await cursor.fetchone()
|
||||
|
||||
if whitelist_status and whitelist_status[0]:
|
||||
return
|
||||
|
||||
await self.ban_executor(guild, executor, user)
|
||||
|
||||
async def ban_executor(self, guild, executor, user):
|
||||
retries = 3
|
||||
while retries > 0:
|
||||
try:
|
||||
await guild.ban(executor, reason="Member Unban | Unwhitelisted User")
|
||||
await guild.ban(user, reason="Reverting unban by unwhitelisted user")
|
||||
return
|
||||
except discord.Forbidden:
|
||||
print(f"Failed to ban {executor.id} or user due to missing permissions.")
|
||||
return
|
||||
except discord.HTTPException as e:
|
||||
if e.status == 429:
|
||||
retry_after = e.response.headers.get('Retry-After')
|
||||
if retry_after:
|
||||
retry_after = float(retry_after)
|
||||
print(f"Rate limit encountered. Retrying after {retry_after} seconds.")
|
||||
await asyncio.sleep(retry_after)
|
||||
else:
|
||||
print(f"HTTPException encountered: {e}")
|
||||
return
|
||||
except discord.errors.RateLimited as e:
|
||||
print(f"Rate limit encountered while banning: {e}. Retrying in {e.retry_after} seconds.")
|
||||
await asyncio.sleep(e.retry_after)
|
||||
except Exception as e:
|
||||
print(f"An unexpected error occurred while banning {executor.id} or user: {e}")
|
||||
return
|
||||
|
||||
retries -= 1
|
||||
|
||||
print(f"Failed to ban {executor.id} after multiple attempts due to rate limits.")
|
||||
Reference in New Issue
Block a user