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:
TheOnlyMace
2026-07-21 16:00:52 +02:00
commit fdfc8de44d
925 changed files with 75254 additions and 0 deletions

66
.gitignore vendored Normal file
View File

@@ -0,0 +1,66 @@
/myenv
dashboard/node_modules
dashboard/.next
# Ignore Python cache
__pycache__/
*.py[cod]
*$py.class
# Ignore virtual environments
venv/
.venv/
env/
ENV/
# Ignore IDE files
.vscode/
.idea/
*.swp
*.swo
# Ignore OS files
.DS_Store
Thumbs.db
# Ignore logs
*.log
# Ignore build outputs
dist/
build/
# Ignore temporary files
*.tmp
*.temp
# Ignore Python packaging
*.egg-info/
.Python
# Ignore Jupyter Notebook checkpoints
.ipynb_checkpoints/
# Ignore environment variables
.env
.env.local
.env.*.local
# Ignore node_modules
node_modules/
package-lock.json
# Ignore Next.js build output
.next/
out/
# Ignore Python cache
__pycache__/
*.pyc
*.pyo
*.pyd
*.zip
*.rar

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 CodeX Devs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

425
README.md Normal file
View File

@@ -0,0 +1,425 @@
<div align="center">
```
███████╗██╗ ██╗██████╗ ██████╗ ██╗ ██╗
╚══███╔╝╚██╗ ██╔╝██╔══██╗██╔═══██╗╚██╗██╔╝
███╔╝ ╚████╔╝ ██████╔╝██║ ██║ ╚███╔╝
███╔╝ ╚██╔╝ ██╔══██╗██║ ██║ ██╔██╗
███████╗ ██║ ██║ ██║╚██████╔╝██╔╝ ██╗
╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
```
<h3>A feature-rich Discord bot paired with a sleek Next.js dashboard</h3>
<a href="https://nexiohost.in"><img src="https://img.shields.io/badge/⭐%20PREMIUM%20HOSTING-NexioHost-FFD700?style=for-the-badge&labelColor=1a1a2e&color=FFD700&logoColor=FFD700"/></a>
<p>
<a href="https://python.org"><img src="https://img.shields.io/badge/Python-3.10+-3776AB?style=for-the-badge&logo=python&logoColor=white"/></a>
<a href="https://nextjs.org"><img src="https://img.shields.io/badge/Next.js-14+-000000?style=for-the-badge&logo=nextdotjs&logoColor=white"/></a>
<a href="https://fastapi.tiangolo.com"><img src="https://img.shields.io/badge/FastAPI-Backend-009688?style=for-the-badge&logo=fastapi&logoColor=white"/></a>
<a href="https://discordpy.readthedocs.io"><img src="https://img.shields.io/badge/Discord.py-v2-5865F2?style=for-the-badge&logo=discord&logoColor=white"/></a>
</p>
<p>
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-red?style=for-the-badge"/></a>
<a href="https://discord.gg/codexdev"><img src="https://img.shields.io/badge/Discord-Join_Server-5865F2?style=for-the-badge&logo=discord&logoColor=white"/></a>
<a href="https://youtube.com/@CodeXDevs"><img src="https://img.shields.io/badge/YouTube-CodeXDevs-FF0000?style=for-the-badge&logo=youtube&logoColor=white"/></a>
<a href="https://github.com/RayExo"><img src="https://img.shields.io/badge/GitHub-RayExo-181717?style=for-the-badge&logo=github&logoColor=white"/></a>
</p>
</div>
---
## ✦ Overview
ZyroX is a fully-featured Discord bot with a modern web dashboard for managing everything from antinuke to music. Built on `discord.py v2`, `FastAPI`, and `Next.js 14` with Tailwind CSS.
```
ZyroX-CV2-With-Dashboard/
├── 🤖 bot/ Python Discord bot + FastAPI backend
│ ├── api/ Dashboard REST API (FastAPI)
│ ├── cogs/ All bot features (commands, events, antinuke, automod…)
│ ├── core/ Bot client, context, cog base
│ ├── utils/ Shared utilities (emoji, tools, sync, cloudflare tunnel…)
│ ├── games/ Standalone game modules
│ ├── assets/ Fonts, backgrounds, GIFs
│ └── CodeX.py Entry point
└── 🌐 dashboard/ Next.js frontend
├── app/ App Router pages & API routes
├── components/ Reusable UI components
├── hooks/ Custom React hooks
├── lib/ API helpers & utilities
└── types/ TypeScript type definitions
```
---
## ✦ Features
<table>
<tr>
<td width="50%">
**🛡️ Security**
- Antinuke — ban, kick, channel & role flood, webhook abuse, bot adds, prune
- Automod — spam, caps, links, invites, mass mentions, emoji spam
- Anti-member update protection
- Whitelist / unwhitelist system
- Emergency lockdown mode
</td>
<td width="50%">
**🎵 Music**
- Lavalink v4 powered playback
- YouTube, SoundCloud, JioSaavn search
- Queue, loop, autoplay, shuffle
- Seek, rewind, forward controls
- Fully configurable via `.env`
</td>
</tr>
<tr>
<td>
**⚙️ Management**
- Moderation — ban, kick, mute, warn, lock, jail, and more
- Full logging system
- Reaction roles, vanity roles, invite tracker
- Tickets, giveaways, verification
- Join-to-create voice channels
</td>
<td>
**🌐 Dashboard**
- Discord OAuth2 login
- Per-server settings management
- Live bot stats & metrics
- Fully branded & customisable
- HTTPS via Cloudflare Tunnel (permanent URL)
- Deploys to Vercel in minutes
</td>
</tr>
<tr>
<td>
**🎉 Engagement**
- Leveling & XP system with leaderboard
- Birthday tracker
- 12+ mini-games (chess, battleship, wordle, 2048…)
- AFK system, autorole, autoresponder, sticky messages
- Counting, blackjack, slots, booster perks
</td>
<td>
**🔧 Developer**
- Application emoji auto-sync on startup
- Jishaku eval support
- Slash + prefix commands
- FastAPI backend with API key auth + rate limiting
- Cloudflare Tunnel — unlimited bandwidth, permanent URL, zero system installs
- CodeX Devs watermark on every source file
</td>
</tr>
</table>
---
## ✦ Prerequisites
| Requirement | Version / Notes |
|---|---|
| Python | 3.10 or higher |
| Node.js | 18 or higher |
| Lavalink node | v4 |
| Discord bot token | — |
| Discord OAuth app | for dashboard login |
| Cloudflare account (free) | for HTTPS tunnel |
---
## ✦ Bot Setup
**1 — Clone the repo**
```bash
git clone https://github.com/RayExo/ZyroX-CV2-With-Dashboard
cd ZyroX-CV2-With-Dashboard/bot
```
**2 — Install dependencies**
```bash
python -m venv .venv
# Windows
.venv\Scripts\activate
# Linux / macOS
source .venv/bin/activate
pip install -r requirements.txt
```
**3 — Configure the environment**
Copy `.env.example` to `.env` and fill in the values:
```env
# ── Core ──────────────────────────────────────────────────────────
TOKEN = your_discord_bot_token
brand_name = 'ZyroX'
# ── Owner IDs (REQUIRED — your Discord user ID) ───────────────────
OWNER_IDS = YOUR_DISCORD_USER_ID_HERE
# ── Lavalink ──────────────────────────────────────────────────────
LAVALINK_HOST = "your-lavalink-host"
LAVALINK_PASSWORD = "your_password"
LAVALINK_SECURE = "true"
LAVALINK_PORT = ""
# ── Emoji Sync ────────────────────────────────────────────────────
EMOJI_SYNC = "false"
# ── API / Dashboard Backend ───────────────────────────────────────
API_ENABLED = "false"
API_HOST = "127.0.0.1"
API_PORT = "8000"
DASHBOARD_API_KEY = "change_this_to_a_strong_secret"
DASHBOARD_ADMIN_IDS = YOUR_DISCORD_USER_ID_HERE
CORS_ORIGINS = ""
# ── Cloudflare Tunnel (optional) ──────────────────────────────────
TUNNEL_ENABLED = "false"
CF_TUNNEL_TOKEN = "your_tunnel_token"
CF_TUNNEL_URL = "https://api.yourdomain.com"
# ── Webhooks (optional — leave unset to disable) ──────────────────
# CMD_WEBHOOK_URL = "https://discord.com/api/webhooks/ID/TOKEN"
```
**4 — Run the bot**
```bash
python CodeX.py
```
---
## ✦ Dashboard Setup
**1 — Install dependencies**
```bash
cd dashboard
npm install
```
**2 — Configure the environment**
Copy `.env.example` to `.env.local`:
```env
DASHBOARD_API_URL = http://127.0.0.1:8000/api/v1
DASHBOARD_API_KEY = same_secret_as_bot_DASHBOARD_API_KEY
NEXTAUTH_URL = http://localhost:3000
NEXTAUTH_SECRET = a_long_random_string
DISCORD_CLIENT_ID = your_discord_oauth_client_id
DISCORD_CLIENT_SECRET = your_discord_oauth_client_secret
ADMIN_IDS = your_discord_user_id
NEXT_PUBLIC_ADMIN_IDS = your_discord_user_id
NEXT_PUBLIC_BRAND_NAME = "ZyroX"
NEXT_PUBLIC_BRAND_NAME_WORD = "ZX"
```
**3 — Run locally**
```bash
npm run dev
```
Open [http://localhost:3000](http://localhost:3000)
---
## ✦ Environment Reference
### Bot — `bot/.env`
| Variable | Default | Description |
|---|---|---|
| `TOKEN` | — | Discord bot token |
| `OWNER_IDS` | _(required)_ | Comma-separated owner Discord user IDs — **must be your own ID** |
| `LAVALINK_HOST` | — | Lavalink server hostname (no protocol) |
| `LAVALINK_PASSWORD` | — | Lavalink password |
| `LAVALINK_SECURE` | `true` | `true` = HTTPS, `false` = HTTP |
| `LAVALINK_PORT` | _(empty)_ | Port — only needed when `LAVALINK_SECURE=false` |
| `EMOJI_SYNC` | `false` | Run application emoji sync on startup |
| `JISHAKU_ENABLED` | `false` | Enable owner debug REPL (disable in production) |
| `API_ENABLED` | `false` | Start the FastAPI dashboard backend |
| `API_HOST` | `127.0.0.1` | Bind address — use `127.0.0.1` unless behind a reverse proxy |
| `API_PORT` | `8000` | Port the backend listens on |
| `DASHBOARD_API_KEY` | — | Shared secret between bot API and dashboard (server-side only) |
| `DASHBOARD_ADMIN_IDS` | — | Discord user IDs allowed to use admin API routes |
| `CORS_ORIGINS` | _(empty)_ | Extra CORS-allowed origins, comma-separated |
| `CMD_WEBHOOK_URL` | _(empty)_ | Optional Discord webhook for command logging |
| `TUNNEL_ENABLED` | `false` | Expose the API over HTTPS via Cloudflare Tunnel |
| `CF_TUNNEL_TOKEN` | — | Token from Cloudflare Zero Trust dashboard |
| `CF_TUNNEL_URL` | — | Your permanent public URL (e.g. `https://api.yourdomain.com`) |
| `LOG_CHANNEL_ID` | _(empty)_ | Optional channel for join/leave logs |
### Dashboard — `dashboard/.env.local`
| Variable | Description |
|---|---|
| `DASHBOARD_API_URL` | Bot API URL (server-side, e.g. `http://127.0.0.1:8000/api/v1`) |
| `DASHBOARD_API_KEY` | Must match `DASHBOARD_API_KEY` in the bot — **never use NEXT_PUBLIC_** |
| `NEXTAUTH_URL` | Your dashboard's public URL |
| `NEXTAUTH_SECRET` | Random secret for NextAuth session signing |
| `DISCORD_CLIENT_ID` | Discord OAuth2 client ID |
| `DISCORD_CLIENT_SECRET` | Discord OAuth2 client secret |
| `ADMIN_IDS` | Comma-separated Discord user IDs with admin panel access (server-side) |
| `NEXT_PUBLIC_ADMIN_IDS` | Same IDs for client-side admin UI visibility |
| `NEXT_PUBLIC_BRAND_NAME` | Bot name shown in the dashboard UI |
| `NEXT_PUBLIC_BRAND_NAME_WORD` | Short abbreviation shown in the dashboard |
> **API security:** Guild routes require a valid Discord OAuth token with Manage Server permission. The dashboard forwards this automatically via `/api/proxy`.
---
## ✦ HTTPS Tunnel (Cloudflare)
The bot uses **pycloudflared** — a Python package that downloads the `cloudflared` binary automatically on first run. No CLI installs, no system packages — works on Pterodactyl and any Python host.
**Why Cloudflare over ngrok:**
- ✅ Unlimited bandwidth & requests — no monthly caps
- ✅ Permanent URL that never changes between restarts
- ✅ Free — no paid plan needed
- ✅ Zero system installs — binary downloads via Python
**Setup (browser only, no CLI needed):**
1. Go to [one.dash.cloudflare.com](https://one.dash.cloudflare.com) → **Networks → Tunnels → Create a tunnel**
2. Choose **Cloudflared**, give it a name (e.g. `zyrox-api`), save
3. On the **Install connector** step, copy the token from the command shown:
```
cloudflared tunnel run --token <COPY_THIS>
```
4. Go to **Public Hostname** tab → add a hostname:
- Subdomain: `api` · Domain: `yourdomain.com` · Service: `http://localhost:8000`
5. Add to `bot/.env`:
```env
CF_TUNNEL_TOKEN = "eyJhIjoiXXXX..."
CF_TUNNEL_URL = "https://api.yourdomain.com"
```
On every startup the console prints:
```
◈ Tunnel: cloudflared binary ready — starting tunnel on port 8000…
◈ Tunnel: API is live at https://api.yourdomain.com
↳ NEXT_PUBLIC_API_URL = https://api.yourdomain.com/api/v1
```
---
## ✦ Deployment
### 🤖 Bot — any Python host
1. Upload the entire `bot/` folder to your host (Pterodactyl, Render, Railway, Fly.io, VPS…)
2. Set the start command to `python CodeX.py`
3. Add all environment variables
4. `pycloudflared` downloads the binary automatically on first run — no extra steps
> Recommended free/cheap hosts: Render · Railway · Fly.io · VPS
>
> ⭐ **[NexioHost](https://nexiohost.in)** — Premium bot hosting, built for Discord bots. Fast, reliable, and affordable.
### 🌐 Dashboard — Vercel
1. Go to [vercel.com](https://vercel.com) → **Add New Project** → connect your GitHub repo
2. Set root directory to `dashboard/`
3. Add all environment variables under **Settings → Environment Variables**
4. Add the OAuth redirect URI in Discord Developer Portal:
```
https://your-app.vercel.app/api/auth/callback/discord
```
5. Hit **Deploy** — done ✓
---
## ✦ Emoji Sync
Runs automatically on startup when `EMOJI_SYNC=true`:
```
★ Starting Application Emoji Sync — 144 unique emojis found in emoji.py
◈ Found 144 templates | Application hosts 202 emojis
↑ Uploading: ztick (not in application emojis)
✔ Uploaded: ztick [saved as ID: 1234567890]
✔ emoji.py patched in-place to reflect current API state.
★ Restarting bot to load updated emoji IDs...
```
| Event | Action |
|---|---|
| New emoji found | Uploaded to application, ID written to `emoji.py` |
| Stale ID detected | `emoji.py` patched automatically |
| No changes | Sync completes instantly, no restart |
| After any patch | Bot restarts itself so fresh IDs are live |
---
## ✦ Troubleshooting
| Problem | Fix |
|---|---|
| Bot fails to start | Check `TOKEN` is set and bot has correct gateway intents |
| Music not working | Verify `LAVALINK_HOST`, `LAVALINK_SECURE`, and `LAVALINK_PORT` |
| Dashboard auth error | Check Discord OAuth client ID/secret and redirect URI |
| Dashboard can't load data | Confirm `API_ENABLED=true`, bot running, `DASHBOARD_API_URL` correct, user logged in via Discord |
| API 403 on guild routes | User needs Manage Server or Admin permission on that Discord server |
| API key rejected (401) | `DASHBOARD_API_KEY` must exactly match in bot and dashboard `.env` |
| Emojis showing as plain text | Run with `EMOJI_SYNC=true` once to upload and patch IDs |
| CORS errors from dashboard | Add your Vercel URL to `CORS_ORIGINS` in `bot/.env` |
| Tunnel not starting | Check `CF_TUNNEL_TOKEN` is valid and `pycloudflared` is installed |
| Tunnel URL changed | Set `CF_TUNNEL_URL` — named tunnels always produce the same URL |
---
## ✦ Security
- Never commit `.env` files — `.gitignore` already covers them
- Use a strong, unique `NEXTAUTH_SECRET` and `DASHBOARD_API_KEY`
- Rotate any secret that gets accidentally exposed
- The bot API is always behind an API key — never expose it without one
---
<div align="center">
## ✦ CodeX Devs
*Built for protection. Designed for style.*
<a href="https://discord.gg/codexdev"><img src="https://discord.com/api/guilds/1301573144817045524/widget.png?style=banner2" alt="CodeX Development Discord Server" width="480"/></a>
<p>
<a href="https://discord.gg/codexdev"><img src="https://img.shields.io/badge/Discord-Join_Server-5865F2?style=for-the-badge&logo=discord&logoColor=white"/></a>
<a href="https://youtube.com/@CodeXDevs"><img src="https://img.shields.io/badge/YouTube-CodeXDevs-FF0000?style=for-the-badge&logo=youtube&logoColor=white"/></a>
<a href="https://github.com/RayExo"><img src="https://img.shields.io/badge/GitHub-RayExo-181717?style=for-the-badge&logo=github&logoColor=white"/></a>
<a href="https://nexiohost.in"><img src="https://img.shields.io/badge/⭐%20PREMIUM%20HOSTING-NexioHost-FFD700?style=for-the-badge&labelColor=1a1a2e&color=FFD700&logoColor=FFD700"/></a>
</p>
© 2026 CodeX Devs — MIT License
</div>

43
bot/.env.example Normal file
View File

@@ -0,0 +1,43 @@
TOKEN=TOKEN_HERE
brand_name='ZyroX'
NEXT_PUBLIC_BRAND_NAME='ZyroX'
# ── Owner / Staff IDs (REQUIRED — comma-separated Discord user IDs) ───────────
# Set your own Discord user ID(s). No foreign IDs are used as fallback.
OWNER_IDS=YOUR_DISCORD_USER_ID_HERE
# ── Optional: debug REPL for owners (disabled by default) ─────────────────────
JISHAKU_ENABLED=false
# ── Optional: Discord log / stats channels (leave empty to disable) ───────────
# LOG_CHANNEL_ID=
# SERVER_COUNT_CHANNEL_ID=
# USER_COUNT_CHANNEL_ID=
# ── Lavalink ──────────────────────────────────────────────────────────────────
LAVALINK_HOST="lavalink.jirayu.net"
LAVALINK_PASSWORD="youshallnotpass"
LAVALINK_SECURE="false"
LAVALINK_PORT="13592"
# ── Emoji Sync ────────────────────────────────────────────────────────────────
EMOJI_SYNC="false"
# ── API / Dashboard Backend ───────────────────────────────────────────────────
API_ENABLED="false"
API_HOST="127.0.0.1"
API_PORT="8000"
DASHBOARD_API_KEY="generate_a_long_random_secret_here"
# Discord user IDs allowed to use /api/v1/admin (comma-separated; falls back to OWNER_IDS)
DASHBOARD_ADMIN_IDS=YOUR_DISCORD_USER_ID_HERE
CORS_ORIGINS=""
# ── Webhooks (leave empty or unset to disable command logging) ────────────────
# CMD_WEBHOOK_URL must be a full Discord webhook URL to enable logging.
# CMD_WEBHOOK_URL=
# ── Cloudflare Tunnel (disabled by default) ───────────────────────────────────
TUNNEL_ENABLED="false"
TUNNEL_ALLOW_BINARY_DOWNLOAD="false"
# CF_TUNNEL_TOKEN=
# CF_TUNNEL_URL=

366
bot/CodeX.py Normal file
View File

@@ -0,0 +1,366 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import os
import subprocess
# os.system("")
import asyncio
import traceback
from threading import Thread
from datetime import datetime
import random
import time
import aiohttp
import discord
from discord import Spotify
from discord.ext import commands, tasks
from core import Context
from core.Cog import Cog
from core.zyrox import zyrox
from utils.Tools import *
from utils.config import *
from utils.emoji import SUCCESS, ERROR, TICK, CROSS, REACTION_TEST_EMOJIS
from utils.sync_emojis import run_sync
import cogs
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv("TOKEN")
if JISHAKU_ENABLED:
os.environ["JISHAKU_NO_DM_TRACEBACK"] = "False"
os.environ["JISHAKU_HIDE"] = "True"
os.environ["JISHAKU_NO_UNDERSCORE"] = "True"
os.environ["JISHAKU_FORCE_PAGINATOR"] = "True"
if not OWNER_IDS:
print("\033[33m⚠ OWNER_IDS is not set in .env — no bot owners configured.\033[0m")
print("\033[33m Set OWNER_IDS=YOUR_DISCORD_USER_ID before running in production.\033[0m")
client = zyrox()
tree = client.tree
# --- Background Task for Stats ---
async def update_stats():
"""Update server/user counts in channel names when channel IDs are configured."""
if not SERVER_COUNT_CHANNEL_ID and not USER_COUNT_CHANNEL_ID:
return
await client.wait_until_ready()
while not client.is_closed():
try:
servers = len(client.guilds)
users = sum(guild.member_count for guild in client.guilds if guild.member_count is not None)
if SERVER_COUNT_CHANNEL_ID:
server_channel = client.get_channel(SERVER_COUNT_CHANNEL_ID)
if server_channel:
await server_channel.edit(name=f"Servers: {servers}")
if USER_COUNT_CHANNEL_ID:
user_channel = client.get_channel(USER_COUNT_CHANNEL_ID)
if user_channel:
await user_channel.edit(name=f"Users: {users}")
except Exception as e:
print(f"Error updating stats: {e}")
await asyncio.sleep(600)
# --- Event Handlers ---
@client.event
async def on_ready():
await client.wait_until_ready()
print("""
\033[1;31m
██████╗ ██████╗ ██████╗ ███████╗██╗ ██╗
██╔════╝██╔═══██╗██╔══██╗██╔════╝╚██╗██╔╝
██║ ██║ ██║██║ ██║█████╗ ╚███╔╝
██║ ██║ ██║██║ ██║██╔══╝ ██╔██╗
╚██████╗╚██████╔╝██████╔╝███████╗██╔╝ ██╗
╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝
\033[0m
""")
print("Loaded & Online!")
print(f"Logged in as: {client.user}")
print(f"Connected to: {len(client.guilds)} guilds")
print(f"Connected to: {len(client.users)} users")
# Sync application emojis on startup
await run_sync(TOKEN)
async def sync_commands():
try:
synced = await client.tree.sync()
all_commands = list(client.commands)
print(f"Synced Total {len(all_commands)} Client Commands and {len(synced)} Slash Commands")
except Exception as e:
print(f"Error syncing command tree: {e}")
client.loop.create_task(sync_commands())
if SERVER_COUNT_CHANNEL_ID or USER_COUNT_CHANNEL_ID:
client.loop.create_task(update_stats())
@client.event
async def on_guild_join(guild: discord.Guild):
if not LOG_CHANNEL_ID:
return
log_channel = client.get_channel(LOG_CHANNEL_ID)
if log_channel:
await log_channel.send(f"{BRAND_NAME} has been added to the server: **{guild.name}** (ID: `{guild.id}`)")
@client.event
async def on_command_completion(context: commands.Context) -> None:
if not CMD_WEBHOOK_URL or context.command is None or context.author.id in OWNER_IDS:
return
full_command_name = context.command.qualified_name
split = full_command_name.split("\n")
executed_command = str(split[0])
embed_color = 0xFF0000
embed = discord.Embed(color=embed_color)
avatar_url = context.author.display_avatar.url
embed.set_author(name=f"Cmd Executed: {executed_command}", icon_url=avatar_url)
embed.set_thumbnail(url=avatar_url)
if context.guild is not None:
embed.add_field(name="User", value=f"{context.author.mention} (`{context.author.id}`)", inline=False)
embed.add_field(name="Server", value=f"{context.guild.name} (`{context.guild.id}`)", inline=False)
embed.add_field(name="Channel", value=f"{context.channel.mention} (`{context.channel.id}`)", inline=False)
else:
embed.add_field(name="User (DM)", value=f"{context.author.mention} (`{context.author.id}`)", inline=False)
embed.timestamp = discord.utils.utcnow()
embed.set_footer(text=f"{BRAND_NAME} Development™ ❤️", icon_url=client.user.display_avatar.url)
try:
async with aiohttp.ClientSession() as session:
webhook = discord.Webhook.from_url(CMD_WEBHOOK_URL, session=session)
await webhook.send(embed=embed)
except Exception as e:
print(f'Command log webhook failed: {e}')
# --- Utility Commands ---
@client.command(name='spotify')
async def spotify(ctx: Context, user: discord.Member = None):
"""Shows what a user is listening to on Spotify."""
user = user or ctx.author
spotify_activity = next((activity for activity in user.activities if isinstance(activity, Spotify)), None)
if not spotify_activity:
return await ctx.send(f"{user.name} is not listening to Spotify.")
embed = discord.Embed(
title=f"{user.name}'s Spotify",
description=f"**Listening to:** {spotify_activity.title}",
color=0x1DB954 # Spotify Green
)
embed.set_thumbnail(url=spotify_activity.album_cover_url)
embed.add_field(name="Artist", value=spotify_activity.artist)
embed.add_field(name="Album", value=spotify_activity.album)
embed.set_footer(text=f"Song started at {spotify_activity.created_at.strftime('%H:%M')}")
await ctx.send(embed=embed)
@client.command(name='makeinvite', aliases=['createinvite', 'makeinv'])
@commands.is_owner()
async def make_invite(ctx: Context, guild_id: int = None):
"""Creates an invite for a specified server (owner only)."""
if guild_id is None:
return await ctx.send("Please provide a Guild ID.")
guild = client.get_guild(guild_id)
if not guild:
return await ctx.send("Invalid Guild ID. I am not in that server.")
if guild.system_channel and guild.system_channel.permissions_for(guild.me).create_instant_invite:
try:
invite = await guild.system_channel.create_invite(max_age=0, max_uses=0, unique=True, reason="Owner requested invite.")
return await ctx.send(f"Invite for **{guild.name}**:\n{invite.url}")
except Exception:
pass
for channel in guild.text_channels:
if channel.permissions_for(guild.me).create_instant_invite:
try:
invite = await channel.create_invite(max_age=0, max_uses=0, unique=True, reason="Owner requested invite.")
return await ctx.send(f"Invite for **{guild.name}** (from #{channel.name}):\n{invite.url}")
except Exception:
continue
await ctx.send(f"I don't have 'Create Instant Invite' permission in any channel in **{guild.name}**.")
# --- Webhook Management Commands ---
@client.command(name='create_hook', aliases=['makehook'])
@commands.has_permissions(administrator=True)
async def create_hook(ctx: Context, *, name: str = None):
"""Creates a webhook in the current channel."""
if name is None:
return await ctx.send("Please provide a name for the webhook.")
try:
webhook = await ctx.channel.create_webhook(name=name, reason=f"Created by {ctx.author}")
embed = discord.Embed(
title=f"{SUCCESS} Webhook Created",
description=f"A webhook named **{webhook.name}** was created.",
color=0xFF0000
)
await ctx.author.send(f"Webhook URL for **{webhook.name}** in **{ctx.channel.name}**:\n||{webhook.url}||", embed=embed)
await ctx.send("Webhook created. I've sent the URL to your DMs.")
except discord.Forbidden:
await ctx.send("I don't have permission to create webhooks here.")
except Exception:
await ctx.send(f"Webhook created: **{webhook.name}**\n||{webhook.url}||\n(I could not DM you the URL.)")
@client.command(name='delete_hook', aliases=['delhook'])
@commands.has_permissions(administrator=True)
async def delete_hook(ctx: Context, webhook_url: str = None):
"""Deletes a webhook using its URL."""
if webhook_url is None:
return await ctx.send("Please provide the webhook URL to delete.")
try:
async with aiohttp.ClientSession() as session:
webhook = await discord.Webhook.from_url(webhook_url, session=session)
await webhook.delete(reason=f"Deleted by {ctx.author}")
await ctx.send(f"{SUCCESS} Webhook deleted successfully.")
except (discord.NotFound, ValueError):
await ctx.send(f"{ERROR} Webhook not found or URL is invalid.")
@client.command(name='list_hooks', aliases=['hooks'])
@commands.has_permissions(administrator=True)
async def list_hooks(ctx: Context):
"""Lists all webhooks in the current channel."""
try:
webhooks = await ctx.channel.webhooks()
if not webhooks:
return await ctx.send("No webhooks found in this channel.")
embed = discord.Embed(title=f"Webhooks in #{ctx.channel.name}", color=0xFF0000)
description = "\n".join([f"**Name:** {wh.name} | **ID:** `{wh.id}`" for wh in webhooks])
embed.description = description
await ctx.send(embed=embed)
except discord.Forbidden:
await ctx.send("I don't have permission to view webhooks in this channel.")
# --- Game Command ---
@client.command()
async def reaction(ctx: Context):
"""See how fast you can react to the correct emoji."""
emojis = ["🍪", "🎉", "🧋", "🍒", "🍑", "💸", "🌙", "💕"]
correct_emoji = random.choice(emojis)
random.shuffle(emojis)
embed = discord.Embed(
title="Reaction Test",
description="I will show an emoji in a few seconds. Get ready to click it!",
color=0xFF0000
)
message = await ctx.send(embed=embed)
for emoji in emojis:
await message.add_reaction(emoji)
await asyncio.sleep(random.uniform(2.0, 7.0))
embed.description = f"**GET THE {correct_emoji} EMOJI!**"
await message.edit(embed=embed)
start_time = time.time()
def check(reaction, user):
return (
reaction.message.id == message.id
and str(reaction.emoji) == correct_emoji
and user == ctx.author
)
try:
reaction, user = await client.wait_for("reaction_add", timeout=15.0, check=check)
end_time = time.time()
reaction_time = end_time - start_time
embed.description = f"{user.mention} got the {correct_emoji} in **{reaction_time:.2f} seconds**!"
await message.edit(embed=embed)
except asyncio.TimeoutError:
embed.description = "Timeout! You were too slow."
await message.edit(embed=embed)
# ---API Server for Dashboard Backend ---
import uvicorn
from threading import Thread
from api.server import create_app
from api.dependencies import set_bot
fastapi_app = create_app()
fastapi_app.state.bot = client
set_bot(client)
def run_api():
uvicorn.run(fastapi_app, host=API_HOST, port=API_PORT, log_level="warning")
def keep_alive():
if not API_ENABLED:
print(f"\033[33m◈ API Server: Disabled via API_ENABLED=false\033[0m")
return
print(f"\033[32m◈ API Server: Starting on {API_HOST}:{API_PORT}\033[0m")
if API_HOST in ("0.0.0.0", "::"):
print("\033[33m ⚠ API bound to all interfaces — use API_HOST=127.0.0.1 unless behind a reverse proxy.\033[0m")
server = Thread(target=run_api, daemon=True)
server.start()
keep_alive()
# --- Cloudflare Tunnel (HTTPS for API) — only when explicitly enabled ---
from utils.tunnel import start_tunnel
start_tunnel()
# --- Main Bot Execution ---
async def main():
async with client:
os.system("clear")
if JISHAKU_ENABLED:
await client.load_extension("jishaku")
print("\033[33m◈ Jishaku: enabled (owner-only debug REPL)\033[0m")
else:
print("\033[32m◈ Jishaku: disabled (set JISHAKU_ENABLED=true to enable)\033[0m")
max_retries = 5
for attempt in range(max_retries):
try:
await client.start(TOKEN)
break
except discord.HTTPException as e:
if e.status == 429: # Rate limited
wait_time = min((2 ** attempt) + random.random(), 60)
print(f"Rate limited. Retrying in {wait_time:.2f} seconds...")
await asyncio.sleep(wait_time)
else:
raise
else:
raise Exception("Bot failed to start after multiple retries due to rate limiting.")
if __name__ == "__main__":
asyncio.run(main())

21
bot/LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 CodeX Devs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

349
bot/README.md Normal file
View File

@@ -0,0 +1,349 @@
<div align="center">
```
███████╗██╗ ██╗██████╗ ██████╗ ██╗ ██╗
╚══███╔╝╚██╗ ██╔╝██╔══██╗██╔═══██╗╚██╗██╔╝
███╔╝ ╚████╔╝ ██████╔╝██║ ██║ ╚███╔╝
███╔╝ ╚██╔╝ ██╔══██╗██║ ██║ ██╔██╗
███████╗ ██║ ██║ ██║╚██████╔╝██╔╝ ██╗
╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
```
<h3>ZyroX Bot — Python Discord Bot + FastAPI Backend</h3>
<a href="https://nexiohost.in"><img src="https://img.shields.io/badge/⭐%20PREMIUM%20HOSTING-NexioHost-FFD700?style=for-the-badge&labelColor=1a1a2e&color=FFD700&logoColor=FFD700"/></a>
<p>
<a href="https://python.org"><img src="https://img.shields.io/badge/Python-3.10+-3776AB?style=for-the-badge&logo=python&logoColor=white"/></a>
<a href="https://fastapi.tiangolo.com"><img src="https://img.shields.io/badge/FastAPI-Backend-009688?style=for-the-badge&logo=fastapi&logoColor=white"/></a>
<a href="https://discordpy.readthedocs.io"><img src="https://img.shields.io/badge/Discord.py-v2-5865F2?style=for-the-badge&logo=discord&logoColor=white"/></a>
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-red?style=for-the-badge"/></a>
</p>
<p>
<a href="https://discord.gg/codexdev"><img src="https://img.shields.io/badge/Discord-Join_Server-5865F2?style=for-the-badge&logo=discord&logoColor=white"/></a>
<a href="https://youtube.com/@CodeXDevs"><img src="https://img.shields.io/badge/YouTube-CodeXDevs-FF0000?style=for-the-badge&logo=youtube&logoColor=white"/></a>
<a href="https://github.com/RayExo"><img src="https://img.shields.io/badge/GitHub-RayExo-181717?style=for-the-badge&logo=github&logoColor=white"/></a>
</p>
</div>
---
## ✦ Overview
This folder contains the ZyroX Discord bot built on `discord.py v2` alongside a `FastAPI` backend that powers the web dashboard. Everything runs from a single `python CodeX.py` command.
```
bot/
├── api/ FastAPI backend (routes, schemas, db manager)
│ └── routes/ /bot /guilds /admin
├── cogs/
│ ├── antinuke/ Antinuke protection event listeners
│ ├── automod/ Automod enforcement event listeners
│ ├── commands/ All slash & prefix command modules
│ ├── events/ General Discord event listeners
│ ├── moderation/ Moderation action modules
│ └── zyrox/ Core ZyroX feature cogs
├── core/ Bot client, context, cog base classes
├── games/ Standalone game logic + button views
├── utils/ Emoji, tools, sync, Cloudflare tunnel
├── assets/ Fonts, backgrounds, GIFs
└── CodeX.py Entry point
```
---
## ✦ Features
<table>
<tr>
<td width="50%">
**🛡️ Antinuke**
- Mass ban, kick, channel & role flood detection
- Webhook abuse, bot add, prune protection
- Anti-member update
- Whitelist / unwhitelist system
- Emergency lockdown mode
</td>
<td width="50%">
**🤖 Automod**
- Anti-spam, anti-caps, anti-links
- Anti-invites, mass mention, emoji spam
- Fully configurable per server
- Works alongside Discord's native automod
</td>
</tr>
<tr>
<td>
**🎵 Music**
- Lavalink v4 powered playback
- YouTube, SoundCloud, JioSaavn support
- Queue, loop, shuffle, autoplay
- Seek, rewind, forward controls
</td>
<td>
**⚙️ Moderation**
- Ban, kick, mute, warn, lock, jail
- Snipe, message management
- Full logging system
- Reaction roles, vanity roles, invite tracker
</td>
</tr>
<tr>
<td>
**🎉 Engagement**
- Leveling & XP with leaderboard
- Birthday tracker
- Counting, AFK, autorole, autoresponder
- Sticky messages, booster perks, giveaways
</td>
<td>
**🎮 Games**
- Chess, Battleship, Connect Four
- Wordle, Typeracer, 2048, Memory
- Reaction test, RPS, Tic-tac-toe
- Country guess, Number slider, Lights out
</td>
</tr>
<tr>
<td>
**🌐 API Backend**
- FastAPI with API key auth
- SlowAPI rate limiting
- Structured JSON request logging
- CORS configured for your dashboard domain
- `CORS_ORIGINS` env var for extra domains
</td>
<td>
**🔧 Developer**
- Jishaku eval support
- Application emoji auto-sync
- Slash + prefix commands
- Cloudflare Tunnel via pycloudflared — zero system installs, unlimited traffic
- Single `OWNER_IDS` env var controls all permission checks
- CodeX Devs watermark on every source file
</td>
</tr>
</table>
---
## ✦ Prerequisites
| Requirement | Notes |
|---|---|
| Python 3.10+ | — |
| Lavalink v4 node | for music features |
| Discord bot token | from Developer Portal |
| Cloudflare account (free) | for HTTPS tunnel — browser setup only |
---
## ✦ Setup
### 1 — Install dependencies
```bash
python -m venv .venv
# Windows
.venv\Scripts\activate
# Linux / macOS
source .venv/bin/activate
pip install -r requirements.txt
```
### 2 — Configure environment
Create a `.env` file (copy from `.env.example`):
```env
# ── Core ──────────────────────────────────────────────────────────
TOKEN = your_discord_bot_token
brand_name = 'ZyroX'
# ── Owner IDs (REQUIRED — your Discord user ID) ───────────────────
OWNER_IDS = YOUR_DISCORD_USER_ID_HERE
# ── Lavalink ──────────────────────────────────────────────────────
LAVALINK_HOST = "your-lavalink-host"
LAVALINK_PASSWORD = "your_password"
LAVALINK_SECURE = "true"
LAVALINK_PORT = ""
# ── Emoji Sync ────────────────────────────────────────────────────
EMOJI_SYNC = "false"
# ── API / Dashboard Backend ───────────────────────────────────────
API_ENABLED = "false"
API_HOST = "127.0.0.1"
API_PORT = "8000"
DASHBOARD_API_KEY = "change_this_to_a_strong_secret"
DASHBOARD_ADMIN_IDS = YOUR_DISCORD_USER_ID_HERE
CORS_ORIGINS = ""
# ── Cloudflare Tunnel (optional) ──────────────────────────────────
TUNNEL_ENABLED = "false"
CF_TUNNEL_TOKEN = "your_tunnel_token"
CF_TUNNEL_URL = "https://api.yourdomain.com"
# ── Webhooks (optional) ─────────────────────────────────────────────
# CMD_WEBHOOK_URL = "https://discord.com/api/webhooks/ID/TOKEN"
```
### 3 — Run
```bash
python CodeX.py
```
---
## ✦ Environment Reference
| Variable | Default | Description |
|---|---|---|
| `TOKEN` | — | Discord bot token |
| `OWNER_IDS` | _(required)_ | Comma-separated owner Discord user IDs — **your own ID only** |
| `LAVALINK_HOST` | — | Lavalink server hostname (no protocol) |
| `LAVALINK_PASSWORD` | — | Lavalink password |
| `LAVALINK_SECURE` | `true` | `true` = HTTPS, `false` = HTTP |
| `LAVALINK_PORT` | _(empty)_ | Port — only when `LAVALINK_SECURE=false` |
| `EMOJI_SYNC` | `false` | Auto-sync application emojis on startup |
| `JISHAKU_ENABLED` | `false` | Enable owner debug REPL (disable in production) |
| `API_ENABLED` | `false` | Start the FastAPI dashboard backend |
| `API_HOST` | `127.0.0.1` | Bind address for the API server |
| `API_PORT` | `8000` | Port the backend listens on |
| `DASHBOARD_API_KEY` | — | Shared secret with dashboard (server-side only) |
| `DASHBOARD_ADMIN_IDS` | — | Discord user IDs for admin API routes |
| `CORS_ORIGINS` | _(empty)_ | Extra CORS-allowed origins, comma-separated |
| `CMD_WEBHOOK_URL` | _(empty)_ | Optional webhook for command logging |
| `TUNNEL_ENABLED` | `false` | Expose API over HTTPS via Cloudflare Tunnel |
| `CF_TUNNEL_TOKEN` | — | Token from Cloudflare Zero Trust dashboard |
| `CF_TUNNEL_URL` | — | Your permanent public URL |
| `LOG_CHANNEL_ID` | _(empty)_ | Optional channel for join/leave logs |
> **API security:** All `/api/v1/guilds/*` routes verify Discord Manage Server permission via `X-Discord-Access-Token` header.
---
## ✦ HTTPS Tunnel (Cloudflare)
Uses **pycloudflared** — downloads the `cloudflared` binary automatically on first run. No system installs, no CLI, works on Pterodactyl and any Python host.
**Why Cloudflare over ngrok:**
| | Cloudflare Tunnel | ngrok free |
|---|---|---|
| Bandwidth | Unlimited | 1 GB/month |
| Requests | Unlimited | 10k/month |
| URL stability | Permanent | Permanent (1 domain) |
| System install | ❌ Not needed | ❌ Not needed |
| Cost | Free | Free |
**Setup (browser only — no CLI needed):**
1. Go to [one.dash.cloudflare.com](https://one.dash.cloudflare.com) → **Networks → Tunnels → Create a tunnel**
2. Choose **Cloudflared**, name it (e.g. `zyrox-api`), save
3. On **Install connector**, copy the token from the command shown:
```
cloudflared tunnel run --token <COPY_THIS_TOKEN>
```
4. On **Public Hostname** tab → add a hostname:
- Subdomain: `api` · Domain: `yourdomain.com` · Service: `http://localhost:8000`
5. Add to `.env`:
```env
CF_TUNNEL_TOKEN = "eyJhIjoiXXXX..."
CF_TUNNEL_URL = "https://api.yourdomain.com"
```
On every startup the console prints:
```
◈ Tunnel: cloudflared binary ready — starting tunnel on port 8000…
◈ Tunnel: API is live at https://api.yourdomain.com
↳ DASHBOARD_API_URL = https://api.yourdomain.com/api/v1
```
Set `TUNNEL_ENABLED=false` to disable.
---
## ✦ Emoji Sync
When `EMOJI_SYNC=true`, the bot syncs application emojis on every startup:
| Event | Action |
|---|---|
| New emoji found | Uploaded to application, ID written to `emoji.py` |
| Stale ID detected | `emoji.py` patched automatically |
| No changes | Sync completes instantly, no restart |
| After any patch | Bot restarts so fresh IDs are live |
---
## ✦ Deployment
Upload the entire `bot/` folder to your host and set the start command to:
```bash
python CodeX.py
```
`pycloudflared` downloads the binary on first run — no extra steps on any host.
> Recommended free hosts: Render · Railway · Fly.io · Pterodactyl
>
> ⭐ **[NexioHost](https://nexiohost.in)** — Premium bot hosting, built for Discord bots. Fast, reliable, and affordable.
---
## ✦ Troubleshooting
| Problem | Fix |
|---|---|
| Bot fails to start | Check `TOKEN` and gateway intents in Developer Portal |
| Music not working | Verify `LAVALINK_HOST`, `LAVALINK_SECURE`, `LAVALINK_PORT` |
| Dashboard can't reach API | Check `API_ENABLED=true`, `DASHBOARD_API_URL` in dashboard, and Discord login |
| CORS errors | Add your Vercel URL to `CORS_ORIGINS` in `.env` |
| Emojis showing as plain text | Run once with `EMOJI_SYNC=true` to upload and patch IDs |
| Tunnel not starting | Check `CF_TUNNEL_TOKEN` is valid and `pycloudflared` is installed |
| Want to add an owner | Add their ID to `OWNER_IDS` in `.env` — no code changes needed |
---
<div align="center">
## ✦ CodeX Devs
*Built for protection. Designed for style.*
<a href="https://discord.gg/codexdev"><img src="https://discord.com/api/guilds/1301573144817045524/widget.png?style=banner2" alt="CodeX Development Discord Server" width="480"/></a>
<p>
<a href="https://discord.gg/codexdev"><img src="https://img.shields.io/badge/Discord-Join_Server-5865F2?style=for-the-badge&logo=discord&logoColor=white"/></a>
<a href="https://youtube.com/@CodeXDevs"><img src="https://img.shields.io/badge/YouTube-CodeXDevs-FF0000?style=for-the-badge&logo=youtube&logoColor=white"/></a>
<a href="https://github.com/RayExo"><img src="https://img.shields.io/badge/GitHub-RayExo-181717?style=for-the-badge&logo=github&logoColor=white"/></a>
<a href="https://nexiohost.in"><img src="https://img.shields.io/badge/⭐%20PREMIUM%20HOSTING-NexioHost-FFD700?style=for-the-badge&labelColor=1a1a2e&color=FFD700&logoColor=FFD700"/></a>
</p>
© 2026 CodeX Devs — MIT License
</div>

14
bot/api/__init__.py Normal file
View File

@@ -0,0 +1,14 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝

54
bot/api/db_manager.py Normal file
View File

@@ -0,0 +1,54 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import aiosqlite
import asyncio
from typing import Dict
class DatabaseManager:
"""
A simple manager for persistent SQLite connections to avoid
opening/closing files on every API request.
"""
def __init__(self):
self._connections: Dict[str, aiosqlite.Connection] = {}
self._lock = asyncio.Lock()
async def get_connection(self, db_path: str) -> aiosqlite.Connection:
"""
Retrieves an existing connection or creates a new one for the given path.
"""
async with self._lock:
if db_path not in self._connections:
# We use check_same_thread=False because aiosqlite handles
# thread safety by running queries in a dedicated thread.
conn = await aiosqlite.connect(db_path, check_same_thread=False)
conn.row_factory = aiosqlite.Row
self._connections[db_path] = conn
return self._connections[db_path]
async def close_all(self):
"""
Closes all open connections. Called on API shutdown.
"""
async with self._lock:
for path, conn in self._connections.items():
try:
await conn.close()
except:
pass
self._connections.clear()
# Singleton instance
db_manager = DatabaseManager()

75
bot/api/dependencies.py Normal file
View File

@@ -0,0 +1,75 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import os
from typing import Optional, TYPE_CHECKING
from fastapi import HTTPException, Depends, Security
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
from slowapi import Limiter
from slowapi.util import get_remote_address
if TYPE_CHECKING:
from core.zyrox import zyrox
# Initialize rate limiter
limiter = Limiter(key_func=get_remote_address, default_limits=["1000 per minute"])
# Global reference to the bot instance
_bot_instance: Optional["zyrox"] = None
# Security scheme
security = HTTPBearer()
def verify_api_key(credentials: HTTPAuthorizationCredentials = Security(security)):
"""
Dependency to verify the API key from the Authorization header.
Expected: Authorization: Bearer <API_KEY>
"""
api_key = os.getenv("DASHBOARD_API_KEY")
# If no key is set in env, we might want to allow for local testing or force it.
# The requirement says "Read API key from environment variable", implying it's required.
if not api_key:
raise HTTPException(
status_code=500,
detail="DASHBOARD_API_KEY environment variable is not set."
)
if credentials.credentials != api_key:
raise HTTPException(
status_code=401,
detail="Invalid or missing API key."
)
return credentials.credentials
def set_bot(bot_instance: "zyrox"):
"""
Sets the global bot instance.
This should be called in CodeX.py during startup.
"""
global _bot_instance
_bot_instance = bot_instance
def get_bot() -> "zyrox":
"""
FastAPI dependency to retrieve the Discord bot instance.
Usage: bot: zyrox = Depends(get_bot)
"""
if _bot_instance is None:
raise HTTPException(
status_code=503,
detail="Discord bot instance is not initialized yet."
)
return _bot_instance

130
bot/api/discord_auth.py Normal file
View File

@@ -0,0 +1,130 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ Discord OAuth permission checks for dashboard API requests ║
# ╚══════════════════════════════════════════════════════════════════╝
from __future__ import annotations
import re
from typing import Any
import aiohttp
from fastapi import HTTPException, Request
from utils.config import OWNER_IDS_STR
MANAGE_GUILD = 0x20
ADMINISTRATOR = 0x8
GUILD_PATH_RE = re.compile(r"^/api/v1/guilds/(\d+)(?:/|$)")
def _parse_admin_ids() -> list[str]:
import os
raw = os.getenv("DASHBOARD_ADMIN_IDS", "").strip()
if raw:
return [p.strip() for p in raw.split(",") if p.strip().isdigit()]
return list(OWNER_IDS_STR)
def can_manage_guild(guild: dict[str, Any]) -> bool:
if guild.get("owner"):
return True
try:
perms = int(guild.get("permissions", "0"))
except (TypeError, ValueError):
return False
return bool(perms & ADMINISTRATOR) or bool(perms & MANAGE_GUILD)
async def fetch_user_guilds(access_token: str) -> list[dict[str, Any]]:
async with aiohttp.ClientSession() as session:
async with session.get(
"https://discord.com/api/users/@me/guilds",
headers={"Authorization": f"Bearer {access_token}"},
) as resp:
if resp.status != 200:
raise HTTPException(
status_code=403,
detail="Invalid or expired Discord access token.",
)
data = await resp.json()
return data if isinstance(data, list) else []
async def verify_discord_token(access_token: str) -> dict[str, Any]:
async with aiohttp.ClientSession() as session:
async with session.get(
"https://discord.com/api/users/@me",
headers={"Authorization": f"Bearer {access_token}"},
) as resp:
if resp.status != 200:
raise HTTPException(
status_code=403,
detail="Invalid or expired Discord access token.",
)
return await resp.json()
async def user_can_manage_guild(access_token: str, guild_id: int) -> bool:
guilds = await fetch_user_guilds(access_token)
for guild in guilds:
if str(guild.get("id")) == str(guild_id):
return can_manage_guild(guild)
return False
async def get_manageable_guild_ids(access_token: str) -> set[str]:
guilds = await fetch_user_guilds(access_token)
return {str(g["id"]) for g in guilds if can_manage_guild(g)}
def get_discord_headers(request: Request) -> tuple[str | None, str | None]:
token = request.headers.get("X-Discord-Access-Token")
user_id = request.headers.get("X-Discord-User-Id")
return token, user_id
async def require_discord_session(request: Request) -> tuple[str, str]:
token, user_id = get_discord_headers(request)
if not token:
raise HTTPException(
status_code=403,
detail="X-Discord-Access-Token header is required.",
)
user = await verify_discord_token(token)
resolved_id = str(user.get("id", ""))
if not resolved_id:
raise HTTPException(status_code=403, detail="Could not resolve Discord user.")
if user_id and user_id != resolved_id:
raise HTTPException(status_code=403, detail="Discord user ID mismatch.")
return token, resolved_id
async def require_guild_access(request: Request, guild_id: int) -> None:
token, _ = await require_discord_session(request)
if not await user_can_manage_guild(token, guild_id):
raise HTTPException(
status_code=403,
detail="You do not have permission to manage this guild.",
)
async def require_dashboard_admin(request: Request) -> None:
token, user_id = await require_discord_session(request)
admin_ids = _parse_admin_ids()
if user_id not in admin_ids:
raise HTTPException(
status_code=403,
detail="Dashboard admin access required.",
)
def extract_guild_id_from_path(path: str) -> int | None:
match = GUILD_PATH_RE.match(path)
if not match:
return None
return int(match.group(1))

View File

@@ -0,0 +1,14 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝

128
bot/api/routes/admin.py Normal file
View File

@@ -0,0 +1,128 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
from fastapi import APIRouter, Depends, HTTPException
from api.dependencies import get_bot
from api.schemas import AdminStats, AdminNodeStatus, AdminConfig, AdminConfigUpdate
from typing import TYPE_CHECKING, List
import os
import aiosqlite
if TYPE_CHECKING:
from core.zyrox import zyrox
router = APIRouter()
CONFIG_DB = "db/admin_config.db"
async def init_db():
async with aiosqlite.connect(CONFIG_DB) as db:
await db.execute("CREATE TABLE IF NOT EXISTS config (key TEXT PRIMARY KEY, value TEXT)")
# Default values
await db.execute("INSERT OR IGNORE INTO config (key, value) VALUES ('maintenance_mode', 'false')")
await db.execute("INSERT OR IGNORE INTO config (key, value) VALUES ('global_notification', '')")
await db.commit()
import psutil
import time
@router.get("/stats", response_model=AdminStats)
async def get_admin_stats(bot: "zyrox" = Depends(get_bot)):
# Calculate DB size and shard info
total_size: float = 0.0
db_count = 0
db_dir = "db"
if os.path.exists(db_dir):
for f in os.listdir(db_dir):
if f.endswith(".db"):
total_size += float(os.path.getsize(os.path.join(db_dir, f)))
db_count += 1
mb_size = total_size / (1024 * 1024)
db_size_str = f"{mb_size:.2f} MB"
if mb_size > 1024:
db_size_str = f"{(mb_size / 1024):.2f} GB"
# System Metrics
process = psutil.Process(os.getpid())
# Use a non-blocking interval check or global state for CPU
cpu_usage = psutil.cpu_percent()
ram_raw = process.memory_info().rss
ram_mb = ram_raw / (1024 * 1024)
total_commands = len(bot.commands)
loaded_cogs = len(bot.cogs or {})
# Node Healths
nodes = [
AdminNodeStatus(
name="Primary API Cluster",
status="Healthy",
load=f"CPU: {cpu_usage}% | RAM: {ram_mb:.1f}MB",
icon="Globe"
),
AdminNodeStatus(
name="Database Shards",
status="Healthy" if db_count > 0 else "Warning",
load=f"{db_count} SQLite DBs | {db_size_str}",
icon="Database"
),
AdminNodeStatus(
name="Bot Microservices",
status="Healthy" if bot.is_ready() else "Booting",
load=f"{loaded_cogs} Modules",
icon="Cpu"
),
AdminNodeStatus(
name="Auth Sockets",
status="Healthy",
load=f"Shard: {bot.shard_count} | Latency: {round(bot.latency * 1000)}ms",
icon="Lock"
)
]
total_members = sum(g.member_count or 0 for g in bot.guilds)
return AdminStats(
total_users=str(total_members),
active_servers=str(len(bot.guilds)),
api_latency=f"{round(bot.latency * 1000, 2)}ms",
db_size=db_size_str,
nodes=nodes
)
@router.get("/config", response_model=AdminConfig)
async def get_admin_config():
await init_db()
async with aiosqlite.connect(CONFIG_DB) as db:
async with db.execute("SELECT value FROM config WHERE key = 'maintenance_mode'") as cursor:
mm = await cursor.fetchone()
async with db.execute("SELECT value FROM config WHERE key = 'global_notification'") as cursor:
gn = await cursor.fetchone()
return AdminConfig(
maintenance_mode=mm[0].lower() == 'true' if mm else False,
global_notification=gn[0] if gn else None
)
@router.patch("/config")
async def patch_admin_config(data: AdminConfigUpdate):
await init_db()
async with aiosqlite.connect(CONFIG_DB) as db:
if data.maintenance_mode is not None:
await db.execute("UPDATE config SET value = ? WHERE key = 'maintenance_mode'", (str(data.maintenance_mode).lower(),))
if data.global_notification is not None:
await db.execute("UPDATE config SET value = ? WHERE key = 'global_notification'", (data.global_notification,))
await db.commit()
return {"status": "success"}

53
bot/api/routes/bot.py Normal file
View File

@@ -0,0 +1,53 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
from fastapi import APIRouter, Depends
from api.dependencies import get_bot
from api.schemas import BotInfo, BotStatus
from typing import TYPE_CHECKING
from utils.config import *
if TYPE_CHECKING:
from core.zyrox import zyrox
router = APIRouter()
@router.get("/status", response_model=BotStatus, summary="Get bot status", description="Returns real-time health metrics, latency, and scale information.")
async def get_status(bot: "zyrox" = Depends(get_bot)):
"""
Returns the live status of the bot.
"""
return BotStatus(
user=str(bot.user),
id=str(bot.user.id) if bot.user else None,
latency=bot.latency * 1000,
guild_count=len(bot.guilds),
user_count=sum(g.member_count or 0 for g in bot.guilds),
shards=bot.shard_count
)
@router.get("/info", response_model=BotInfo, summary="Get bot info", description="Returns general information about the bot including command count and user reach.")
async def get_bot_info(bot: "zyrox" = Depends(get_bot)):
"""
Get general information about the Discord bot.
"""
return BotInfo(
name=bot.user.name if bot.user else BRAND_NAME,
id=str(bot.user.id) if bot.user else None,
guilds=len(bot.guilds),
users=sum(g.member_count or 0 for g in bot.guilds),
commands=len(bot.commands),
latency=f"{round(bot.latency * 1000, 2)}ms"
)

1391
bot/api/routes/guilds.py Normal file

File diff suppressed because it is too large Load Diff

346
bot/api/schemas.py Normal file
View File

@@ -0,0 +1,346 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
from pydantic import BaseModel, HttpUrl
from typing import Dict, List, Optional
# --- Bot Schemas ---
class BotInfo(BaseModel):
name: str
id: Optional[str]
guilds: int
users: int
commands: int
latency: str
class BotStatus(BaseModel):
user: str
id: Optional[str]
latency: float
guild_count: int
user_count: int
shards: Optional[int]
# --- Guild Schemas ---
class GuildSummary(BaseModel):
id: str
name: str
icon_url: Optional[str]
owner_id: str
member_count: int
class GuildDetails(BaseModel):
id: str
name: str
icon: Optional[str]
owner_id: str
member_count: int
role_count: int
channel_count: int
class DiscordChannel(BaseModel):
id: str
name: str
type: str
class DiscordRole(BaseModel):
id: str
name: str
color: int
position: int # text, voice, category, etc.
# --- Module Configurations ---
class PrefixConfig(BaseModel):
guild_id: int
prefix: str
class AutomodConfig(BaseModel):
guild_id: int
enabled: bool
punishments: Dict[str, str]
ignored_roles: List[int]
ignored_channels: List[int]
logging_channel: Optional[int]
class TicketCategory(BaseModel):
name: str
emoji: Optional[str]
staff_roles: List[int] = []
button_style: Optional[int] = 2 # Blurple
discord_category_id: Optional[int] = None
class TicketEmbed(BaseModel):
title: Optional[str]
description: Optional[str]
color: Optional[int] = None
image_url: Optional[str] = None
thumbnail_url: Optional[str] = None
class TicketConfig(BaseModel):
guild_id: int
panel_channel: Optional[int]
panel_message: Optional[int]
logging_channel: Optional[int] = None
closed_category: Optional[int] = None
panel_type: Optional[str] = "button"
embed: TicketEmbed
categories: List[TicketCategory]
staff_roles: List[int]
open_ticket_count: int
class LevelingEmbedStyle(BaseModel):
color: str
thumbnail: bool = False
image: Optional[str] = None
class LevelingConfig(BaseModel):
guild_id: int
enabled: bool
xp_per_message: int
cooldown: int
level_up_channel: Optional[int]
embed_style: LevelingEmbedStyle
class LoggingConfig(BaseModel):
guild_id: int
log_enabled: Dict[str, bool]
log_channels: Dict[str, int]
ignore_channels: List[int]
ignore_roles: List[int]
ignore_users: List[int]
auto_delete_duration: Optional[int]
class WelcomeEmbedData(BaseModel):
message: Optional[str] = None
title: Optional[str] = None
description: Optional[str] = None
color: Optional[str] = None
footer_text: Optional[str] = None
footer_icon: Optional[str] = None
author_name: Optional[str] = None
author_icon: Optional[str] = None
thumbnail: Optional[str] = None
image: Optional[str] = None
class WelcomeConfig(BaseModel):
guild_id: int
welcome_type: Optional[str] = None
welcome_message: Optional[str] = None
channel_id: Optional[str] = None
embed_data: Optional[WelcomeEmbedData] = None
auto_delete_duration: Optional[int] = None
class AntiNukeConfig(BaseModel):
guild_id: int
status: bool
whitelisted_users: List[str] = []
class VerificationConfig(BaseModel):
guild_id: int
verification_channel_id: Optional[str] = None
verified_role_id: Optional[str] = None
log_channel_id: Optional[str] = None
verification_method: Optional[str] = "both"
enabled: Optional[bool] = True
class TrackingConfig(BaseModel):
guild_id: int
channel_id: Optional[int] = None
class TrackingUpdate(BaseModel):
channel_id: Optional[int] = None
class J2CConfig(BaseModel):
guild_id: str
join_channel_id: Optional[str] = None
control_channel_id: Optional[str] = None
category_id: Optional[str] = None
class J2CUpdate(BaseModel):
join_channel_id: Optional[str] = None
control_channel_id: Optional[str] = None
category_id: Optional[str] = None
class JoinDMConfig(BaseModel):
guild_id: str
message: Optional[str] = None
class JoinDMUpdate(BaseModel):
message: Optional[str] = None
class CustomRoleConfig(BaseModel):
guild_id: str
staff: Optional[str] = None
girl: Optional[str] = None
vip: Optional[str] = None
guest: Optional[str] = None
frnd: Optional[str] = None
reqrole: Optional[str] = None
class CustomRoleUpdate(BaseModel):
staff: Optional[str] = None
girl: Optional[str] = None
vip: Optional[str] = None
guest: Optional[str] = None
frnd: Optional[str] = None
reqrole: Optional[str] = None
class AutoReactTrigger(BaseModel):
trigger: str
emojis: str
class AutoReactConfig(BaseModel):
guild_id: str
triggers: List[AutoReactTrigger] = []
class AutoReactUpdate(BaseModel):
triggers: List[AutoReactTrigger]
class InvcConfig(BaseModel):
guild_id: str
role_id: Optional[str] = None
enabled: bool = False
class InvcUpdate(BaseModel):
role_id: Optional[str] = None
enabled: Optional[bool] = None
class ReactionRoleEntry(BaseModel):
message_id: str
emoji: str
role_id: str
class RRConfig(BaseModel):
guild_id: str
dm_enabled: bool
roles: List[ReactionRoleEntry] = []
class RRUpdate(BaseModel):
dm_enabled: Optional[bool] = None
add_role: Optional[ReactionRoleEntry] = None
remove_role_message_id: Optional[str] = None
remove_role_emoji: Optional[str] = None
class InviteStat(BaseModel):
user_id: str
total: int
fake: int
left: int
rejoin: int
class InvitesLeaderboard(BaseModel):
guild_id: str
data: List[InviteStat]
# --- Update Schemas (Input) ---
class VerificationUpdate(BaseModel):
verification_channel_id: Optional[str] = None
verified_role_id: Optional[str] = None
log_channel_id: Optional[str] = None
verification_method: Optional[str] = None
enabled: Optional[bool] = None
class VanityRoleSetup(BaseModel):
vanity: str
role_id: str
log_channel_id: str
class AutoRoleConfig(BaseModel):
guild_id: str
bots: List[str]
humans: List[str]
class AutoRoleUpdate(BaseModel):
bots: Optional[List[str]] = None
humans: Optional[List[str]] = None
class AntiNukeUpdate(BaseModel):
status: Optional[bool] = None
add_whitelist: Optional[str] = None
remove_whitelist: Optional[str] = None
class WelcomeUpdate(BaseModel):
welcome_type: Optional[str] = None
welcome_message: Optional[str] = None
channel_id: Optional[str] = None
embed_data: Optional[WelcomeEmbedData] = None
auto_delete_duration: Optional[int] = None
class PrefixUpdate(BaseModel):
prefix: str
class TicketUpdate(BaseModel):
panel_channel: Optional[int] = None
logging_channel: Optional[int] = None
closed_category: Optional[int] = None
panel_type: Optional[str] = None
embed_title: Optional[str] = None
embed_description: Optional[str] = None
embed_color: Optional[int] = None
embed_image_url: Optional[str] = None
embed_thumbnail_url: Optional[str] = None
categories: Optional[List[TicketCategory]] = None
staff_roles: Optional[List[int]] = None
class AutomodUpdate(BaseModel):
enabled: Optional[bool] = None
punishments: Optional[Dict[str, str]] = None
ignored_roles: Optional[List[int]] = None
ignored_channels: Optional[List[int]] = None
logging_channel: Optional[int] = None
class LevelingUpdate(BaseModel):
enabled: Optional[bool] = None
xp_per_message: Optional[int] = None
cooldown: Optional[int] = None
level_up_channel: Optional[int] = None
embed_color: Optional[str] = None
class LoggingUpdate(BaseModel):
log_enabled: Optional[Dict[str, bool]] = None
log_channels: Optional[Dict[str, int]] = None
class LeaderboardEntry(BaseModel):
user_id: str
name: str
level: int
xp: int
# --- Admin Schemas ---
class AdminNodeStatus(BaseModel):
name: str
status: str
load: str
icon: str # Icon identifier
class AdminStats(BaseModel):
total_users: str
active_servers: str
api_latency: str
db_size: str
nodes: List[AdminNodeStatus]
class AdminConfig(BaseModel):
maintenance_mode: bool
global_notification: Optional[str] = None
class AdminConfigUpdate(BaseModel):
maintenance_mode: Optional[bool] = None
global_notification: Optional[str] = None

153
bot/api/server.py Normal file
View File

@@ -0,0 +1,153 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
from fastapi import FastAPI, Depends, Request, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from contextlib import asynccontextmanager
import os
import time
import json
import logging
from slowapi import _rate_limit_exceeded_handler
from slowapi.errors import RateLimitExceeded
from slowapi.middleware import SlowAPIMiddleware
from utils.config import *
from api.routes import bot, guilds, admin
from api.dependencies import verify_api_key, limiter
from api.db_manager import db_manager
from api.discord_auth import (
require_dashboard_admin,
require_discord_session,
require_guild_access,
extract_guild_id_from_path,
)
from fastapi.responses import JSONResponse
# Configure logging
logger = logging.getLogger("api_request_logs")
logger.setLevel(logging.INFO)
if not logger.handlers:
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(message)s'))
logger.addHandler(handler)
@asynccontextmanager
async def lifespan(app: FastAPI):
# Setup: Nothing special needed for now
yield
# Shutdown: Close all shared database connections
await db_manager.close_all()
def create_app() -> FastAPI:
"""
Initializes the FastAPI application for the CodeX Bot Dashboard.
The bot instance will be attached to app.state.bot in CodeX.py at runtime.
"""
app = FastAPI(
title=f"{BRAND_NAME} Bot API",
description=f"REST API to manage the {BRAND_NAME} Discord Bot features",
version="1.0",
dependencies=[Depends(verify_api_key)],
lifespan=lifespan
)
# Discord permission checks for dashboard API routes
@app.middleware("http")
async def discord_permission_middleware(request: Request, call_next):
if request.method == "OPTIONS":
return await call_next(request)
path = request.url.path
try:
if path.startswith("/api/v1/admin"):
await require_dashboard_admin(request)
elif path.startswith("/api/v1/bot"):
await require_discord_session(request)
elif path.startswith("/api/v1/guilds"):
guild_id = extract_guild_id_from_path(path)
if guild_id is not None:
await require_guild_access(request, guild_id)
else:
await require_discord_session(request)
except HTTPException as exc:
return JSONResponse(status_code=exc.status_code, content={"detail": exc.detail})
return await call_next(request)
# Structured Logging Middleware
@app.middleware("http")
async def log_requests(request: Request, call_next):
start_time = time.time()
response = await call_next(request)
process_time = time.time() - start_time
log_data = {
"timestamp": time.strftime('%Y-%m-%d %H:%M:%S'),
"method": request.method,
"path": request.url.path,
"status_code": response.status_code,
"duration_ms": round(process_time * 1000, 2),
"client_ip": request.client.host if request.client else "unknown"
}
logger.info(json.dumps(log_data))
return response
# Attach limiter and handler
app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)
app.add_middleware(SlowAPIMiddleware)
# Build allowed origins from env + hardcoded fallbacks
_extra_origins = [
o.strip()
for o in os.getenv("CORS_ORIGINS", "").split(",")
if o.strip()
]
_allowed_origins = list(dict.fromkeys([
"http://localhost:3000",
"https://localhost:3000",
"https://your-vercel-url-here.vercel.app",
*_extra_origins,
]))
# Enable CORS for Next.js dashboard
app.add_middleware(
CORSMiddleware,
allow_origins=_allowed_origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Register Routers
app.include_router(bot.router, prefix="/api/v1/bot", tags=["Bot"])
app.include_router(guilds.router, prefix="/api/v1/guilds", tags=["Guilds"])
app.include_router(admin.router, prefix="/api/v1/admin", tags=["Admin"])
@app.get("/", summary="API Root", description="Returns basic API information and online status.")
async def root():
return {
"status": "online",
"bot_name": {BRAND_NAME},
"api_version": "1.0"
}
@app.get("/health", summary="Health Check", description="Performs a health check for container orchestration and uptime monitoring.")
async def health():
return {"status": "ok"}
return app

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 MiB

376
bot/cogs/__init__.py Normal file
View File

@@ -0,0 +1,376 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
from __future__ import annotations
from core import zyrox
from colorama import Fore, Style, init
from .commands.help import Help
from .commands.general import General
from .commands.music import Music
from .commands.automod import Automod
from .commands.welcome import Welcomer
from .commands.fun import Fun
from .commands.Games import Games
from .commands.extra import Extra
from .commands.owner import Owner
from .commands.voice import Voice
from .commands.afk import afk
from .commands.ignore import Ignore
from .commands.Media import Media
from .commands.Invc import Invcrole
from .commands.giveaway import Giveaway
from .commands.Embed import Embed
from .commands.steal import Steal
from .commands.timer import Timer
from .commands.blacklist import Blacklist
from .commands.block import Block
from .commands.nightmode import Nightmode
from .commands.tracking import Tracking
from .commands.owner import Badges
#from .commands.map import Map
from .commands.autoresponder import AutoResponder
from .commands.customrole import Customrole
from .commands.autorole import AutoRole
from .commands.ticket import TicketCog
from .commands.logging import Logging
from .commands.translate import TranslateCog
from .commands.jail import Jail
from .commands.antinuke import Antinuke
from .commands.extraown import Extraowner
from .commands.anti_wl import Whitelist
from .commands.anti_unwl import Unwhitelist
from .commands.slots import Slots
from .commands.blackjack import Blackjack
from .commands.autoreact import AutoReaction
from .commands.stats import Stats
from .commands.emergency import Emergency
from .commands.notify import NotifCommands
from .commands.status import Status
from .commands.np import NoPrefix
from .commands.filters import FilterCog
from .commands.owner2 import Global
from .commands.qr import QR
from .commands.vanityroles import VanityRoles
from .commands.reactionroles import ReactionRoles
from .commands.messages import Messages
from .commands.fastgreet import FastGreet
from .commands.counting import Counting
from .commands.j2c import JoinToCreate
from .commands.ai import AI
from .commands.dms import StaffDMCog
from .commands.booster import Booster
from .commands.leveling import Leveling
from .commands.stickymessage import StickyMessage
from .commands.verification import Verification
from .commands.minecraft import Minecraft
from .commands.encryption import encryption
from .commands.calc import calculator
from .commands.joindm import joindm
from .commands.Birthday import Birthdays
from .commands.nitro import Nitro
from .commands.image import ImageCommands
from .commands.youtube import Youtube
#____________ Events _____________
#from .events.autoblacklist import AutoBlacklist
from .events.Errors import Errors
from .events.on_guild import Guild
from .events.autorole import Autorole2
from .events.auto import Autorole
from .events.greet2 import greet
from .events.mention import Mention
from .events.react import React
from .events.autoreact import AutoReactListener
#from .events.topgg import TopGG
from .events.ai import AIResponses
from .events.stickymessage import StickyMessageListener
########-------HELP-------########
from .zyrox.antinuke import _antinuke
from .zyrox.extra import _extra
from .zyrox.general import _general
from .zyrox.automod import _automod
from .zyrox.moderation import _moderation
#from .zyrox.inviteTracker import _inviteTracker
from .zyrox.music import _music
from .zyrox.fun import _fun
from .zyrox.games import _games
from .zyrox.ignore import _ignore
from .zyrox.server import _server
from .zyrox.voice import _voice
from .zyrox.welcome import _welcome
from .zyrox.giveaway import _giveaway
from .zyrox.ticket import _ticket
#from .axon.vanityroles import Vanityroles69999
from .zyrox.logging import _logging
from .zyrox.vanity import _vanity
from .zyrox.inviteTracker import inviteTracker
from .zyrox.counting import _Counting
from .zyrox.j2c import _J2C
from .zyrox.ai import _ai
from .zyrox.booster import __boost
from .zyrox.leveling import _leveling
from .zyrox.sticky import _sticky
from .zyrox.verify import _verify
from .zyrox.encryption import _encrypt
from .zyrox.mc import _mc
from .zyrox.joindm import _joindm
from .zyrox.birth import _birth
#########ANTINUKE#########
from .antinuke.anti_member_update import AntiMemberUpdate
from .antinuke.antiban import AntiBan
from .antinuke.antibotadd import AntiBotAdd
from .antinuke.antichcr import AntiChannelCreate
from .antinuke.antichdl import AntiChannelDelete
from .antinuke.antichup import AntiChannelUpdate
from .antinuke.antieveryone import AntiEveryone
from .antinuke.antiguild import AntiGuildUpdate
from .antinuke.antiIntegration import AntiIntegration
from .antinuke.antikick import AntiKick
from .antinuke.antiprune import AntiPrune
from .antinuke.antirlcr import AntiRoleCreate
from .antinuke.antirldl import AntiRoleDelete
from .antinuke.antirlup import AntiRoleUpdate
from .antinuke.antiwebhook import AntiWebhookUpdate
from .antinuke.antiwebhookcr import AntiWebhookCreate
from .antinuke.antiwebhookdl import AntiWebhookDelete
#Extra Optional Events
#from .antinuke.antiemocr import AntiEmojiCreate
#from .antinuke.antiemodl import AntiEmojiDelete
#from .antinuke.antiemoup import AntiEmojiUpdate
#from .antinuke.antisticker import AntiSticker
#from .antinuke.antiunban import AntiUnban
############ AUTOMOD ############
from .automod.antispam import AntiSpam
from .automod.anticaps import AntiCaps
from .automod.antilink import AntiLink
from .automod.anti_invites import AntiInvite
from .automod.anti_mass_mention import AntiMassMention
from .automod.anti_emoji_spam import AntiEmojiSpam
from .moderation.ban import Ban
from .moderation.unban import Unban
from .moderation.timeout import Mute
from .moderation.unmute import Unmute
from .moderation.lock import Lock
from .moderation.unlock import Unlock
from .moderation.hide import Hide
from .moderation.unhide import Unhide
from .moderation.kick import Kick
from .moderation.warn import Warn
from .moderation.role import Role
from .moderation.message import Message
from .moderation.moderation import Moderation
from .moderation.topcheck import TopCheck
from .moderation.snipe import Snipe
from utils.config import BotName
async def setup(bot: zyrox):
cogs_to_load = [
Help, General, Moderation, Automod, Welcomer, Fun, Games, Extra,
Voice, Owner, Customrole, afk, Embed, Media, Ignore, TicketCog, Logging,
Invcrole, Steal, Timer,
Blacklist, Block, Nightmode, Badges, Antinuke, Whitelist,
Unwhitelist, Extraowner, Blackjack, Slots, Guild, Errors, Autorole2, Autorole, greet, AutoResponder,
Mention, AutoRole, React, AntiMemberUpdate, AntiBan, AntiBotAdd,
AntiChannelCreate, AntiChannelDelete, AntiChannelUpdate, AntiEveryone, AntiGuildUpdate,
AntiIntegration, AntiKick, AntiPrune, AntiRoleCreate, AntiRoleDelete,
AntiRoleUpdate, AntiWebhookUpdate, AntiWebhookCreate,
AntiWebhookDelete, AntiSpam, AntiCaps, AntiLink, AntiInvite, AntiMassMention, Stats, Status, NoPrefix, FilterCog, AutoReaction, AutoReactListener, Ban, Unban, Mute, Unmute, Lock, Unlock, Hide, Unhide, Kick, Warn, Role, Message, Moderation, TopCheck, Snipe, Global, QR, VanityRoles, ReactionRoles, Messages, TranslateCog, FastGreet, Jail, inviteTracker,Counting,AI
]
await bot.add_cog(Help(bot))
await bot.add_cog(General(bot))
await bot.add_cog(Music(bot))
await bot.add_cog(Automod(bot))
await bot.add_cog(Welcomer(bot))
await bot.add_cog(Fun(bot))
await bot.add_cog(Tracking(bot))
await bot.add_cog(Games(bot))
await bot.add_cog(Extra(bot))
await bot.add_cog(Voice(bot))
await bot.add_cog(Owner(bot))
await bot.add_cog(Customrole(bot))
await bot.add_cog(afk(bot))
await bot.add_cog(Embed(bot))
await bot.add_cog(Media(bot))
await bot.add_cog(Ignore(bot))
await bot.add_cog(Invcrole(bot))
await bot.add_cog(Giveaway(bot))
await bot.add_cog(Steal(bot))
await bot.add_cog(Booster(bot))
await bot.add_cog(Timer(bot))
await bot.add_cog(Blacklist(bot))
await bot.add_cog(Block(bot))
await bot.add_cog(Nightmode(bot))
await bot.add_cog(Badges(bot))
await bot.add_cog(Antinuke(bot))
await bot.add_cog(Whitelist(bot))
await bot.add_cog(Unwhitelist(bot))
await bot.add_cog(Extraowner(bot))
await bot.add_cog(Slots(bot))
await bot.add_cog(Blackjack(bot))
await bot.add_cog(Stats(bot))
await bot.add_cog(Emergency(bot))
await bot.add_cog(Status(bot))
await bot.add_cog(NoPrefix(bot))
await bot.add_cog(FilterCog(bot))
await bot.add_cog(Global(bot))
# await bot.add_cog(Map(bot))
await bot.add_cog(TicketCog(bot))
await bot.add_cog(Logging(bot))
await bot.add_cog(QR(bot))
await bot.add_cog(VanityRoles(bot))
await bot.add_cog(ReactionRoles(bot))
await bot.add_cog(Messages(bot))
await bot.add_cog(TranslateCog(bot))
await bot.add_cog(FastGreet(bot))
await bot.add_cog(Jail(bot))
await bot.add_cog(JoinToCreate(bot))
await bot.add_cog(AI(bot))
await bot.add_cog(StaffDMCog(bot))
await bot.add_cog(Leveling(bot))
await bot.add_cog(StickyMessage(bot))
await bot.add_cog(Verification(bot))
await bot.add_cog(Minecraft(bot))
await bot.add_cog(encryption(bot))
await bot.add_cog(calculator(bot))
await bot.add_cog(joindm(bot))
await bot.add_cog(Birthdays(bot))
await bot.add_cog(Nitro(bot))
await bot.add_cog(ImageCommands(bot))
await bot.add_cog(Youtube(bot))
await bot.add_cog(_antinuke(bot))
await bot.add_cog(_extra(bot))
await bot.add_cog(_general(bot))
await bot.add_cog(_automod(bot))
await bot.add_cog(_moderation(bot))
await bot.add_cog(_music(bot))
await bot.add_cog(_fun(bot))
await bot.add_cog(_games(bot))
await bot.add_cog(_ignore(bot))
await bot.add_cog(_server(bot))
await bot.add_cog(_voice(bot))
await bot.add_cog(_welcome(bot))
await bot.add_cog(_giveaway(bot))
await bot.add_cog(_ticket(bot))
await bot.add_cog(_logging(bot))
await bot.add_cog(_vanity(bot))
await bot.add_cog(inviteTracker(bot))
await bot.add_cog(Counting(bot))
await bot.add_cog(_Counting(bot))
await bot.add_cog(_J2C(bot))
await bot.add_cog(_ai(bot))
await bot.add_cog(__boost(bot))
await bot.add_cog(_leveling(bot))
await bot.add_cog(_sticky(bot))
await bot.add_cog(_verify(bot))
await bot.add_cog(_encrypt(bot))
await bot.add_cog(_mc(bot))
await bot.add_cog(_joindm(bot))
await bot.add_cog(_birth(bot))
#await bot.add_cog(AutoBlacklist(bot))
await bot.add_cog(Guild(bot))
await bot.add_cog(Errors(bot))
await bot.add_cog(Autorole2(bot))
await bot.add_cog(Autorole(bot))
await bot.add_cog(greet(bot))
await bot.add_cog(AutoResponder(bot))
await bot.add_cog(Mention(bot))
await bot.add_cog(AutoRole(bot))
await bot.add_cog(React(bot))
await bot.add_cog(AutoReaction(bot))
await bot.add_cog(AutoReactListener(bot))
await bot.add_cog(NotifCommands(bot))
await bot.add_cog(StickyMessageListener(bot))
await bot.add_cog(AIResponses(bot))
await bot.add_cog(AntiMemberUpdate(bot))
await bot.add_cog(AntiBan(bot))
await bot.add_cog(AntiBotAdd(bot))
await bot.add_cog(AntiChannelCreate(bot))
await bot.add_cog(AntiChannelDelete(bot))
await bot.add_cog(AntiChannelUpdate(bot))
await bot.add_cog(AntiEveryone(bot))
await bot.add_cog(AntiGuildUpdate(bot))
await bot.add_cog(AntiIntegration(bot))
await bot.add_cog(AntiKick(bot))
await bot.add_cog(AntiPrune(bot))
await bot.add_cog(AntiRoleCreate(bot))
await bot.add_cog(AntiRoleDelete(bot))
await bot.add_cog(AntiRoleUpdate(bot))
await bot.add_cog(AntiWebhookUpdate(bot))
await bot.add_cog(AntiWebhookCreate(bot))
await bot.add_cog(AntiWebhookDelete(bot))
#Extra Optional Events
#await bot.add_cog(AntiEmojiCreate(bot))
#await bot.add_cog(AntiEmojiDelete(bot))
#await bot.add_cog(AntiEmojiUpdate(bot))
#await bot.add_cog(AntiSticker(bot))
#await bot.add_cog(AntiUnban(bot))
await bot.add_cog(AntiSpam(bot))
await bot.add_cog(AntiCaps(bot))
await bot.add_cog(AntiInvite(bot))
await bot.add_cog(AntiLink(bot))
await bot.add_cog(AntiMassMention(bot))
await bot.add_cog(AntiEmojiSpam(bot))
await bot.add_cog(Ban(bot))
await bot.add_cog(Unban(bot))
await bot.add_cog(Mute(bot))
await bot.add_cog(Unmute(bot))
await bot.add_cog(Lock(bot))
await bot.add_cog(Unlock(bot))
await bot.add_cog(Hide(bot))
await bot.add_cog(Unhide(bot))
await bot.add_cog(Kick(bot))
await bot.add_cog(Warn(bot))
await bot.add_cog(Role(bot))
await bot.add_cog(Message(bot))
await bot.add_cog(Moderation(bot))
await bot.add_cog(TopCheck(bot))
await bot.add_cog(Snipe(bot))
for cog in cogs_to_load:
print(Fore.RED + Style.BRIGHT + f"Loaded cog: {cog.__name__}")
print(Fore.RED + Style.BRIGHT + f"All {BotName} Cogs loaded successfully.")

View 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

View 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

View 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

View 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))

View 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)

View 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

View 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

View 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.")

View 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

View 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

View 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.")

View 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

View 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

View 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

View 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

View 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

View 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

View 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.")

View 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.")

View 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.")

View 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.")

View 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.")

View 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 utils.emoji import TICK
from discord.ext import commands
import aiosqlite
import re
from datetime import timedelta
import asyncio
class AntiEmojiSpam(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.emoji_threshold = 5
async def is_automod_enabled(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT enabled FROM automod WHERE guild_id = ?", (guild_id,))
result = await cursor.fetchone()
return result is not None and result[0] == 1
async def is_anti_emoji_spam_enabled(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT punishment FROM automod_punishments WHERE guild_id = ? AND event = 'Anti emoji spam'", (guild_id,))
result = await cursor.fetchone()
return result is not None
async def get_ignored_channels(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT id FROM automod_ignored WHERE guild_id = ? AND type = 'channel'", (guild_id,))
return [row[0] for row in await cursor.fetchall()]
async def get_ignored_roles(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT id FROM automod_ignored WHERE guild_id = ? AND type = 'role'", (guild_id,))
return [row[0] for row in await cursor.fetchall()]
async def get_punishment(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT punishment FROM automod_punishments WHERE guild_id = ? AND event = 'Anti emoji spam'", (guild_id,))
result = await cursor.fetchone()
return result[0] if result else None
async def log_action(self, guild, user, channel, action, reason):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT log_channel FROM automod_logging WHERE guild_id = ?", (guild.id,))
log_channel_id = await cursor.fetchone()
if log_channel_id and log_channel_id[0]:
log_channel = guild.get_channel(log_channel_id[0])
if log_channel:
embed = discord.Embed(title="Automod Log: Anti Emoji Spam", color=0xFF0000)
embed.add_field(name="User", value=user.mention, inline=False)
embed.add_field(name="Action", value=action, inline=False)
embed.add_field(name="Channel", value=channel.mention, inline=False)
embed.add_field(name="Reason", value=reason, inline=False)
embed.set_footer(text=f"User ID: {user.id}")
avatar_url = user.avatar.url if user.avatar else user.default_avatar.url
embed.set_thumbnail(url=avatar_url)
embed.timestamp=discord.utils.utcnow()
await log_channel.send(embed=embed)
@commands.Cog.listener()
async def on_message(self, message):
if message.author.bot:
return
guild = message.guild
user = message.author
channel = message.channel
guild_id = guild.id
if not await self.is_automod_enabled(guild_id) or not await self.is_anti_emoji_spam_enabled(guild_id):
return
if user == guild.owner or user == self.bot.user:
return
ignored_channels = await self.get_ignored_channels(guild_id)
if channel.id in ignored_channels:
return
ignored_roles = await self.get_ignored_roles(guild_id)
if any(role.id in ignored_roles for role in user.roles):
return
emoji_pattern = re.compile(
r"<a?:[a-zA-Z0-9_]+:([0-9]+)>|" #discord emojis
r"([\U0001F600-\U0001F64F]|" # Emoticons
r"[\U0001F300-\U0001F5FF]|" # Miscellaneous Symbols and Pictographs
r"[\U0001F680-\U0001F6FF]|" # Transport and Map Symbols
r"[\U0001F700-\U0001F77F]|" # Alchemical Symbols
r"[\U0001F780-\U0001F7FF]|" # Geometric Shapes Extended
r"[\U0001F800-\U0001F8FF]|" # Supplemental Arrows-C
r"[\U0001F900-\U0001F9FF]|" # Supplemental Symbols and Pictographs
r"[\U0001FA00-\U0001FAFF]|" # Chess Symbols
r"[\U00002700-\U000027BF]|" # Miscellaneous Symbols
r"[\U0001F1E6-\U0001F1FF]|" # Regional Indicator Symbols
r"[\U0001F004-\U0001F0CF]|" # Mahjong Tiles and Playing Cards
r"[\U0001F9B0-\U0001F9FF]" # Additional Emoji
r")"
)
emoji_count = len(emoji_pattern.findall(message.content))
if emoji_count > self.emoji_threshold:
punishment = await self.get_punishment(guild_id)
action_taken = None
reason = f"Emoji Spam ({emoji_count} emojis)"
try:
if punishment == "Mute":
timeout_duration = discord.utils.utcnow() + timedelta(minutes=1)
await user.edit(timed_out_until=timeout_duration, reason=reason)
action_taken = "Muted for 1 minute"
elif punishment == "Kick":
await user.kick(reason=reason)
action_taken = "Kicked"
elif punishment == "Ban":
await user.ban(reason=reason)
action_taken = "Banned"
await message.delete()
simple_embed = discord.Embed(title="Automod Anti Emoji Spam", color=0xFF0000)
simple_embed.description = f"{TICK} | {user.mention} has been successfully **{action_taken}** for **Spamming Emojis.**"
simple_embed.set_footer(text="Use the “automod logging” command to get automod logs if it is not enabled.", icon_url=self.bot.user.avatar.url)
await channel.send(embed=simple_embed, delete_after=30)
await self.log_action(guild, user, channel, action_taken, reason)
except discord.Forbidden:
pass
except discord.HTTPException:
pass
except Exception:
pass
@commands.Cog.listener()
async def on_rate_limit(self, message):
await asyncio.sleep(10)

View File

@@ -0,0 +1,151 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import TICK
from discord.ext import commands
import aiosqlite
import asyncio
from datetime import timedelta
import re
class AntiInvite(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.invite_pattern = re.compile(r'(https?://)?(www\.)?(discord\.gg|discordapp\.com/invite|discord\.com/invite)/\S+')
async def is_automod_enabled(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT enabled FROM automod WHERE guild_id = ?", (guild_id,))
result = await cursor.fetchone()
return result is not None and result[0] == 1
async def is_anti_invites_enabled(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT punishment FROM automod_punishments WHERE guild_id = ? AND event = 'Anti invites'", (guild_id,))
result = await cursor.fetchone()
return result is not None
async def get_ignored_channels(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT id FROM automod_ignored WHERE guild_id = ? AND type = 'channel'", (guild_id,))
return [row[0] for row in await cursor.fetchall()]
async def get_ignored_roles(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT id FROM automod_ignored WHERE guild_id = ? AND type = 'role'", (guild_id,))
return [row[0] for row in await cursor.fetchall()]
async def get_punishment(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT punishment FROM automod_punishments WHERE guild_id = ? AND event = 'Anti invites'", (guild_id,))
result = await cursor.fetchone()
return result[0] if result else None
async def log_action(self, guild, user, channel, action, reason):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT log_channel FROM automod_logging WHERE guild_id = ?", (guild.id,))
log_channel_id = await cursor.fetchone()
if log_channel_id and log_channel_id[0]:
log_channel = guild.get_channel(log_channel_id[0])
if log_channel:
embed = discord.Embed(title="Automod Log: Anti-Invite", color=0xFF0000)
embed.add_field(name="User", value=user.mention, inline=False)
embed.add_field(name="Action", value=action, inline=False)
embed.add_field(name="Channel", value=channel.mention, inline=False)
embed.add_field(name="Reason", value=reason, inline=False)
embed.set_footer(text=f"User ID: {user.id}")
avatar_url = user.avatar.url if user.avatar else user.default_avatar.url
embed.set_thumbnail(url=avatar_url)
embed.timestamp=discord.utils.utcnow()
await log_channel.send(embed=embed)
@commands.Cog.listener()
async def on_message(self, message):
if message.author.bot:
return
guild = message.guild
user = message.author
channel = message.channel
guild_id = guild.id
if not await self.is_automod_enabled(guild_id) or not await self.is_anti_invites_enabled(guild_id):
return
if user == guild.owner or user == self.bot.user:
return
ignored_channels = await self.get_ignored_channels(guild_id)
if channel.id in ignored_channels:
return
ignored_roles = await self.get_ignored_roles(guild_id)
if any(role.id in ignored_roles for role in user.roles):
return
if self.invite_pattern.search(message.content):
invite_link = self.invite_pattern.search(message.content).group(0)
invite_code = invite_link.split('/')[-1]
try:
invite = await guild.invites()
if any(invite.code == invite_code for invite in invite):
return
punishment = await self.get_punishment(guild_id)
action_taken = None
reason = "Posted an invite link"
try:
if punishment == "Mute":
timeout_duration = discord.utils.utcnow() + timedelta(minutes=12)
await user.edit(timed_out_until=timeout_duration, reason="Posted an invite link")
action_taken = "Muted for 12 minutes"
elif punishment == "Kick":
await user.kick(reason="Posted an invite link")
action_taken = "Kicked"
elif punishment == "Ban":
await user.ban(reason="Posted an invite link")
action_taken = "Banned"
await message.delete()
simple_embed = discord.Embed(title="Automod Anti-Invite", color=0xFF0000)
simple_embed.description = f"{TICK} | {user.mention} has been successfully **{action_taken}** for **posting an invite link.**"
simple_embed.set_footer(text="Use the “automod logging” command to get automod logs if it is not enabled.", icon_url=self.bot.user.avatar.url)
await channel.send(embed=simple_embed, delete_after=30)
await self.log_action(guild, user, channel, action_taken, reason)
except discord.Forbidden:
pass
except discord.HTTPException:
pass
except Exception:
pass
except discord.Forbidden:
pass
except discord.HTTPException:
pass
except Exception:
pass
@commands.Cog.listener()
async def on_rate_limit(self, message):
await asyncio.sleep(10)

View 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 utils.emoji import TICK
from discord.ext import commands
import aiosqlite
from datetime import timedelta
import asyncio
class AntiMassMention(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.mass_mention_threshold = 5
async def is_automod_enabled(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT enabled FROM automod WHERE guild_id = ?", (guild_id,))
result = await cursor.fetchone()
return result is not None and result[0] == 1
async def is_anti_mass_mention_enabled(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT punishment FROM automod_punishments WHERE guild_id = ? AND event = 'Anti mass mention'", (guild_id,))
result = await cursor.fetchone()
return result is not None
async def get_ignored_channels(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT id FROM automod_ignored WHERE guild_id = ? AND type = 'channel'", (guild_id,))
return [row[0] for row in await cursor.fetchall()]
async def get_ignored_roles(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT id FROM automod_ignored WHERE guild_id = ? AND type = 'role'", (guild_id,))
return [row[0] for row in await cursor.fetchall()]
async def get_punishment(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT punishment FROM automod_punishments WHERE guild_id = ? AND event = 'Anti mass mention'", (guild_id,))
result = await cursor.fetchone()
return result[0] if result else None
async def log_action(self, guild, user, channel, action, reason):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT log_channel FROM automod_logging WHERE guild_id = ?", (guild.id,))
log_channel_id = await cursor.fetchone()
if log_channel_id and log_channel_id[0]:
log_channel = guild.get_channel(log_channel_id[0])
if log_channel:
embed = discord.Embed(title="Automod Log: Anti Mass Mention", color=0xFF0000)
embed.add_field(name="User", value=user.mention, inline=False)
embed.add_field(name="Action", value=action, inline=False)
embed.add_field(name="Channel", value=channel.mention, inline=False)
embed.add_field(name="Reason", value=reason, inline=False)
embed.set_footer(text=f"User ID: {user.id}")
avatar_url = user.avatar.url if user.avatar else user.default_avatar.url
embed.set_thumbnail(url=avatar_url)
embed.timestamp=discord.utils.utcnow()
await log_channel.send(embed=embed)
@commands.Cog.listener()
async def on_message(self, message):
if message.author.bot:
return
guild = message.guild
user = message.author
channel = message.channel
guild_id = guild.id
if not await self.is_automod_enabled(guild_id) or not await self.is_anti_mass_mention_enabled(guild_id):
return
if user == guild.owner or user == self.bot.user:
return
ignored_channels = await self.get_ignored_channels(guild_id)
if channel.id in ignored_channels:
return
ignored_roles = await self.get_ignored_roles(guild_id)
if any(role.id in ignored_roles for role in user.roles):
return
mention_count = message.content.count("<@")
if mention_count >= self.mass_mention_threshold:
punishment = await self.get_punishment(guild_id)
action_taken = None
reason = f"Mass Mention ({mention_count} mentions)"
try:
if punishment == "Mute":
timeout_duration = discord.utils.utcnow() + timedelta(minutes=3)
await user.edit(timed_out_until=timeout_duration, reason=reason)
action_taken = "Muted for 3 minutes"
elif punishment == "Kick":
await user.kick(reason=reason)
action_taken = "Kicked"
elif punishment == "Ban":
await user.ban(reason=reason)
action_taken = "Banned"
await message.delete()
simple_embed = discord.Embed(title="Automod Anti Mass-Mention", color=0xFF0000)
simple_embed.description = f"{TICK} | {user.mention} has been successfully **{action_taken}** for **mass mentioning.**"
simple_embed.set_footer(text="Use the “automod logging” command to get automod logs if it is not enabled.", icon_url=self.bot.user.avatar.url)
await channel.send(embed=simple_embed, delete_after=30)
await self.log_action(guild, user, channel, action_taken, reason)
except discord.Forbidden:
pass
except discord.HTTPException:
pass
except Exception:
pass
@commands.Cog.listener()
async def on_rate_limit(self, message):
await asyncio.sleep(10)

View File

@@ -0,0 +1,142 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import TICK
from discord.ext import commands
import aiosqlite
import asyncio
from datetime import timedelta
class AntiCaps(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.caps_threshold = 70
self.mute_duration = 2 * 60
async def is_automod_enabled(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT enabled FROM automod WHERE guild_id = ?", (guild_id,))
result = await cursor.fetchone()
return result is not None and result[0] == 1
async def is_anti_caps_enabled(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT punishment FROM automod_punishments WHERE guild_id = ? AND event = 'Anti caps'", (guild_id,))
result = await cursor.fetchone()
return result is not None
async def get_ignored_channels(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT id FROM automod_ignored WHERE guild_id = ? AND type = 'channel'", (guild_id,))
return [row[0] for row in await cursor.fetchall()]
async def get_ignored_roles(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT id FROM automod_ignored WHERE guild_id = ? AND type = 'role'", (guild_id,))
return [row[0] for row in await cursor.fetchall()]
async def get_punishment(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT punishment FROM automod_punishments WHERE guild_id = ? AND event = 'Anti caps'", (guild_id,))
result = await cursor.fetchone()
return result[0] if result else None
async def log_action(self, guild, user, channel, action, reason):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT log_channel FROM automod_logging WHERE guild_id = ?", (guild.id,))
log_channel_id = await cursor.fetchone()
if log_channel_id and log_channel_id[0]:
log_channel = guild.get_channel(log_channel_id[0])
if log_channel:
embed = discord.Embed(title="Automod Log: Anti-Caps", color=0xFF0000)
embed.add_field(name="User", value=user.mention, inline=False)
embed.add_field(name="Action", value=action, inline=False)
embed.add_field(name="Channel", value=channel.mention, inline=False)
embed.add_field(name="Reason", value=reason, inline=False)
embed.set_footer(text=f"User ID: {user.id}")
avatar_url = user.avatar.url if user.avatar else user.default_avatar.url
embed.set_thumbnail(url=avatar_url)
embed.timestamp=discord.utils.utcnow()
await log_channel.send(embed=embed)
@commands.Cog.listener()
async def on_message(self, message):
if len(message.content) < 45:
return
if message.author.bot:
return
guild = message.guild
user = message.author
channel = message.channel
guild_id = guild.id
if not await self.is_automod_enabled(guild_id) or not await self.is_anti_caps_enabled(guild_id):
return
if user == guild.owner or user == self.bot.user:
return
ignored_channels = await self.get_ignored_channels(guild_id)
if channel.id in ignored_channels:
return
ignored_roles = await self.get_ignored_roles(guild_id)
if any(role.id in ignored_roles for role in user.roles):
return
if len(message.content) > 0:
caps_count = sum(1 for c in message.content if c.isupper())
caps_percentage = (caps_count / len(message.content)) * 100
if caps_percentage > self.caps_threshold:
punishment = await self.get_punishment(guild_id)
action_taken = None
reason = "Excessive Caps"
try:
if punishment == "Mute":
timeout_duration = discord.utils.utcnow() + timedelta(minutes=1)
await user.edit(timed_out_until=timeout_duration, reason="Excessive Caps")
action_taken = "Muted for 1 minutes"
elif punishment == "Kick":
await user.kick(reason="Excessive Caps")
action_taken = "Kicked"
elif punishment == "Ban":
await user.ban(reason="Excessive Caps")
action_taken = "Banned"
await message.delete()
simple_embed = discord.Embed(title="Automod Anti-Caps", color=0xFF0000)
simple_embed.description = f"{TICK} | {user.mention} has been successfully **{action_taken}** for **Excessive caps.**"
simple_embed.set_footer(text="Use the “automod logging” command to get automod logs if it is not enabled.", icon_url=self.bot.user.avatar.url)
await channel.send(embed=simple_embed, delete_after=30)
await self.log_action(guild, user, channel, action_taken, reason)
except discord.Forbidden:
pass
except discord.HTTPException:
pass
except Exception:
pass
@commands.Cog.listener()
async def on_rate_limit(self, message):
await asyncio.sleep(10)

View 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 utils.emoji import TICK
from discord.ext import commands
import aiosqlite
import asyncio
from datetime import timedelta
import re
class AntiLink(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.link_pattern = re.compile(r'http[s]?://\S+')
self.invite_pattern = re.compile(r'(https?://)?(www\.)?(discord\.(gg|io|me|li)|discordapp\.com/invite)/\S+')
self.gif_pattern = re.compile(r'(\.gif$|^https://(tenor\.com|giphy\.com/gifs|cdn\.discordapp\.com|media\.discordapp\.net))')
self.spotify_pattern = re.compile(r'^https://open\.spotify\.com/track/\S+')
async def is_automod_enabled(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT enabled FROM automod WHERE guild_id = ?", (guild_id,))
result = await cursor.fetchone()
return result is not None and result[0] == 1
async def is_anti_link_enabled(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT punishment FROM automod_punishments WHERE guild_id = ? AND event = 'Anti link'", (guild_id,))
result = await cursor.fetchone()
return result is not None
async def get_ignored_channels(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT id FROM automod_ignored WHERE guild_id = ? AND type = 'channel'", (guild_id,))
return [row[0] for row in await cursor.fetchall()]
async def get_ignored_roles(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT id FROM automod_ignored WHERE guild_id = ? AND type = 'role'", (guild_id,))
return [row[0] for row in await cursor.fetchall()]
async def get_punishment(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT punishment FROM automod_punishments WHERE guild_id = ? AND event = 'Anti link'", (guild_id,))
result = await cursor.fetchone()
return result[0] if result else None
async def log_action(self, guild, user, channel, action, reason):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT log_channel FROM automod_logging WHERE guild_id = ?", (guild.id,))
log_channel_id = await cursor.fetchone()
if log_channel_id and log_channel_id[0]:
log_channel = guild.get_channel(log_channel_id[0])
if log_channel:
embed = discord.Embed(title="Automod Log: Anti-Link", color=0xFF0000)
embed.add_field(name="User", value=user.mention, inline=False)
embed.add_field(name="Action", value=action, inline=False)
embed.add_field(name="Channel", value=channel.mention, inline=False)
embed.add_field(name="Reason", value=reason, inline=False)
embed.set_footer(text=f"User ID: {user.id}")
avatar_url = user.avatar.url if user.avatar else user.default_avatar.url
embed.set_thumbnail(url=avatar_url)
embed.timestamp=discord.utils.utcnow()
await log_channel.send(embed=embed)
@commands.Cog.listener()
async def on_message(self, message):
if message.author.bot:
return
guild = message.guild
user = message.author
channel = message.channel
guild_id = guild.id
if not await self.is_automod_enabled(guild_id) or not await self.is_anti_link_enabled(guild_id):
return
if user == guild.owner or user == self.bot.user:
return
ignored_channels = await self.get_ignored_channels(guild_id)
if channel.id in ignored_channels:
return
ignored_roles = await self.get_ignored_roles(guild_id)
if any(role.id in ignored_roles for role in user.roles):
return
if self.link_pattern.search(message.content):
if self.invite_pattern.search(message.content):
return
if self.gif_pattern.search(message.content):
return
if self.spotify_pattern.search(message.content):
return
punishment = await self.get_punishment(guild_id)
action_taken = None
reason = "Posted a link"
try:
if punishment == "Mute":
timeout_duration = discord.utils.utcnow() + timedelta(minutes=7)
await user.edit(timed_out_until=timeout_duration, reason=reason)
action_taken = "Muted for 7 minutes"
elif punishment == "Kick":
await user.kick(reason=reason)
action_taken = "Kicked"
elif punishment == "Ban":
await user.ban(reason=reason)
action_taken = "Banned"
await message.delete()
simple_embed = discord.Embed(title="Automod Anti-Link", color=0xFF0000)
simple_embed.description = f"{TICK} | {user.mention} has been successfully **{action_taken}** for **Posting a link.**"
simple_embed.set_footer(text="Use the “automod logging” command to get automod logs if it is not enabled.", icon_url=self.bot.user.avatar.url)
await channel.send(embed=simple_embed, delete_after=30)
await self.log_action(guild, user, channel, action_taken, reason)
except discord.Forbidden:
pass
except discord.HTTPException:
pass
except Exception:
pass
@commands.Cog.listener()
async def on_rate_limit(self, message):
await asyncio.sleep(10)

View File

@@ -0,0 +1,142 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import TICK
from discord.ext import commands
import aiosqlite
import asyncio
from datetime import timedelta
class AntiSpam(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.spam_threshold = 5
self.mute_duration = 12 * 60
self.recent_messages = {}
async def is_automod_enabled(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT enabled FROM automod WHERE guild_id = ?", (guild_id,))
result = await cursor.fetchone()
return result is not None and result[0] == 1
async def is_anti_spam_enabled(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT punishment FROM automod_punishments WHERE guild_id = ? AND event = 'Anti spam'", (guild_id,))
result = await cursor.fetchone()
return result is not None
async def get_ignored_channels(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT id FROM automod_ignored WHERE guild_id = ? AND type = 'channel'", (guild_id,))
return [row[0] for row in await cursor.fetchall()]
async def get_ignored_roles(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT id FROM automod_ignored WHERE guild_id = ? AND type = 'role'", (guild_id,))
return [row[0] for row in await cursor.fetchall()]
async def get_punishment(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT punishment FROM automod_punishments WHERE guild_id = ? AND event = 'Anti spam'", (guild_id,))
result = await cursor.fetchone()
return result[0] if result else None
async def log_action(self, guild, user, channel, action, reason):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT log_channel FROM automod_logging WHERE guild_id = ?", (guild.id,))
log_channel_id = await cursor.fetchone()
if log_channel_id and log_channel_id[0]:
log_channel = guild.get_channel(log_channel_id[0])
if log_channel:
embed = discord.Embed(title="Automod Log: Anti-Spam", color=0xFF0000)
embed.add_field(name="User", value=user.mention, inline=False)
embed.add_field(name="Action", value=action, inline=False)
embed.add_field(name="Channel", value=channel.mention, inline=False)
embed.add_field(name="Reason", value=reason, inline=False)
embed.set_footer(text=f"User ID: {user.id}")
avatar_url = user.avatar.url if user.avatar else user.default_avatar.url
embed.set_thumbnail(url=avatar_url)
embed.timestamp=discord.utils.utcnow()
await log_channel.send(embed=embed)
@commands.Cog.listener()
async def on_message(self, message):
if message.author.bot:
return
guild = message.guild
user = message.author
channel = message.channel
guild_id = guild.id
if not await self.is_automod_enabled(guild_id) or not await self.is_anti_spam_enabled(guild_id):
return
if user == guild.owner or user == self.bot.user:
return
ignored_channels = await self.get_ignored_channels(guild_id)
if channel.id in ignored_channels:
return
ignored_roles = await self.get_ignored_roles(guild_id)
if any(role.id in ignored_roles for role in user.roles):
return
current_time = message.created_at.timestamp()
user_messages = self.recent_messages.get(user.id, [])
user_messages = [msg for msg in user_messages if current_time - msg < 10]
user_messages.append(current_time)
self.recent_messages[user.id] = user_messages
if len(user_messages) > self.spam_threshold:
punishment = await self.get_punishment(guild_id)
action_taken = None
reason = "Spamming"
try:
if punishment == "Mute":
timeout_duration = discord.utils.utcnow() + timedelta(minutes=12)
await user.edit(timed_out_until=timeout_duration, reason="Spamming")
action_taken = "Muted for 12 minutes"
elif punishment == "Kick":
await user.kick(reason="Spamming")
action_taken = "Kicked"
elif punishment == "Ban":
await user.ban(reason="Spamming")
action_taken = "Banned"
simple_embed = discord.Embed(title="Automod Anti-Spam", color=0xFF0000)
simple_embed.description = f"{TICK} | {user.mention} has been successfully **{action_taken}** for **Spamming.**"
simple_embed.set_footer(text="Use the “automod logging” command to get automod logs if it is not enabled.", icon_url=self.bot.user.avatar.url)
await channel.send(embed=simple_embed, delete_after=30)
await self.log_action(guild, user, channel, action_taken, reason)
except discord.Forbidden:
pass
except discord.HTTPException:
pass
except Exception:
pass
@commands.Cog.listener()
async def on_rate_limit(self, message):
await asyncio.sleep(10)

View File

@@ -0,0 +1,192 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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, tasks
import json
import datetime
import asyncio
import os
from discord.ui import LayoutView, TextDisplay, Separator, Container
from utils.cv2 import CV2, build_container
class CV2(LayoutView):
def __init__(self, title, *sections):
super().__init__(timeout=None)
items = [TextDisplay(f"**{title}**")]
for s in sections:
if s:
items.append(Separator(visible=True))
items.append(TextDisplay(str(s)))
self.add_item(build_container(*items))
def read_db(filename):
"""Read the JSON database file."""
if os.path.exists(filename):
with open(filename, 'r') as f:
return json.load(f)
return {}
def write_db(filename, data):
"""Write data to the JSON database file."""
with open(filename, 'w') as f:
json.dump(data, f, indent=4)
class Birthdays(commands.Cog):
"""Handle birthday notifications and setup."""
def __init__(self, client: commands.Bot):
self.client = client
self.check_birthdays.start()
@commands.command(
name="birthdaysetup",
help="Set up the birthday log channel and role.")
@commands.has_permissions(administrator=True)
@commands.guild_only()
async def birthday_setup(self, ctx: commands.Context, channel: discord.TextChannel, role: discord.Role):
db = read_db('jsondb/birthday_logs.json')
guild_id = str(ctx.guild.id)
if guild_id not in db:
db[guild_id] = {"birthday_channel_id": channel.id, "birthday_role_id": role.id}
else:
db[guild_id]["birthday_channel_id"] = channel.id
db[guild_id]["birthday_role_id"] = role.id
write_db('jsondb/birthday_logs.json', db)
await ctx.send(view=CV2("Birthday Setup", f"Birthday log channel set to {channel.mention} and birthday role set to {role.mention}."))
@commands.command(
name="setbirthday",
help="Set your birthday.")
@commands.guild_only()
async def set_birthday(self, ctx: commands.Context):
def check(msg):
return msg.author.id == ctx.author.id and msg.channel.id == ctx.channel.id
await ctx.send(view=CV2("Birthday Setup", "Please enter your birth day (DD):"))
try:
msg = await self.client.wait_for('message', timeout=60.0, check=check)
day = msg.content.strip().zfill(2)
if not day.isdigit() or int(day) not in range(1, 32):
await ctx.send(view=CV2("Error", "Invalid day entered. Please enter a number between 01 and 31."))
return
await ctx.send(view=CV2("Birthday Setup", "Please enter your birth month (MM):"))
msg = await self.client.wait_for('message', timeout=60.0, check=check)
month = msg.content.strip().zfill(2)
if not month.isdigit() or int(month) not in range(1, 13):
await ctx.send(view=CV2("Error", "Invalid month entered. Please enter a number between 01 and 12."))
return
await ctx.send(view=CV2("Birthday Setup", "Please enter your birth year (YYYY):"))
msg = await self.client.wait_for('message', timeout=60.0, check=check)
year = msg.content.strip()
if not year.isdigit() or len(year) != 4:
await ctx.send(view=CV2("Error", "Invalid year entered. Please enter a valid year in YYYY format."))
return
date = f"{month}-{day}-{year}"
db = read_db('jsondb/birthdays.json')
db[str(ctx.author.id)] = date
write_db('jsondb/birthdays.json', db)
await ctx.send(view=CV2("Success", f"Your birthday has been set to {date}."))
except asyncio.TimeoutError:
await ctx.send(view=CV2("Error", "You took too long to respond. Please try again."))
@commands.command(
name="removebirthday",
help="Remove your birthday.")
@commands.guild_only()
async def remove_birthday(self, ctx: commands.Context):
db = read_db('jsondb/birthdays.json')
if str(ctx.author.id) in db:
del db[str(ctx.author.id)]
write_db('jsondb/birthdays.json', db)
await ctx.send(view=CV2("Success", "Your birthday has been removed."))
else:
await ctx.send(view=CV2("Error", "You have no birthday set."))
@commands.command(
name="listbirthdays",
help="List all members who have their birthday today.")
@commands.guild_only()
async def list_birthdays(self, ctx: commands.Context):
now = datetime.datetime.now()
today_date = now.strftime("%m-%d")
db = read_db('jsondb/birthdays.json')
members_with_birthday = [ctx.guild.get_member(int(user_id)) for user_id, date in db.items() if date.startswith(today_date)]
if members_with_birthday:
mentions = ', '.join(member.mention for member in members_with_birthday if member)
await ctx.send(view=CV2("Birthdays Today", f"Members with birthdays today: {mentions}"))
else:
await ctx.send(view=CV2("Birthdays", "No birthdays today."))
@commands.command(
name="birthday",
help="Check your birthday.")
@commands.guild_only()
async def check_birthday(self, ctx: commands.Context):
db = read_db('jsondb/birthdays.json')
if str(ctx.author.id) in db:
date = db[str(ctx.author.id)]
await ctx.send(view=CV2("Your Birthday", f"Your birthday is set to {date}."))
else:
await ctx.send(view=CV2("Your Birthday", "You haven't set your birthday."))
@tasks.loop(hours=24)
async def check_birthdays(self):
now = datetime.datetime.now()
today_date = now.strftime("%m-%d")
db = read_db('jsondb/birthdays.json')
guild_settings = read_db('jsondb/birthday_logs.json')
for user_id, birthday in db.items():
if birthday.startswith(today_date):
user = self.client.get_user(int(user_id))
if user:
for guild_id, settings in guild_settings.items():
channel_id = settings.get("birthday_channel_id")
role_id = settings.get("birthday_role_id")
if channel_id:
channel = self.client.get_channel(channel_id)
if channel:
await channel.send(view=CV2("Happy Birthday! 🎉", f"Wishing {user.mention} a fantastic birthday!"))
role = discord.utils.get(channel.guild.roles, id=role_id)
if role:
await user.add_roles(role)
break
@check_birthdays.before_loop
async def before_check_birthdays(self):
await self.client.wait_until_ready()
now = datetime.datetime.now()
first_run = datetime.datetime.combine(now.date(), datetime.time(hour=0, minute=0))
if now > first_run:
first_run += datetime.timedelta(days=1)
await asyncio.sleep((first_run - now).total_seconds())
async def setup(client: commands.Bot):
await client.add_cog(Birthdays(client))

266
bot/cogs/commands/Embed.py Normal file
View File

@@ -0,0 +1,266 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import os
import discord
from utils.emoji import CROSS, TICK
from discord.ext import commands
from discord import ui
import asyncio
from utils.Tools import *
import re
class EmbedBuilder(ui.LayoutView):
def __init__(self, ctx):
super().__init__(timeout=180)
self.ctx = ctx
self.message = None
self.embed_data = {
"title": "Edit your Embed!",
"description": "Select Options from the menu below to customize.",
"color": 0xFF0000,
"thumbnail": None,
"image": None,
"footer_text": None,
"footer_icon": None,
"author_text": None,
"author_icon": None,
"fields": []
}
self.container = ui.Container(accent_color=None)
self._build_view()
self.add_item(self.container)
def _get_preview(self):
d = self.embed_data
lines = []
if d["title"]:
lines.append(f"**Title:** {d['title']}")
if d["description"]:
lines.append(f"**Description:** {d['description']}")
if d["color"]:
lines.append(f"**Color:** `#{d['color']:06X}`")
if d["thumbnail"]:
lines.append(f"**Thumbnail:** [Set]({d['thumbnail']})")
if d["image"]:
lines.append(f"**Image:** [Set]({d['image']})")
if d["footer_text"]:
lines.append(f"**Footer:** {d['footer_text']}")
if d["footer_icon"]:
lines.append(f"**Footer Icon:** [Set]({d['footer_icon']})")
if d["author_text"]:
lines.append(f"**Author:** {d['author_text']}")
if d["author_icon"]:
lines.append(f"**Author Icon:** [Set]({d['author_icon']})")
if d["fields"]:
for i, f in enumerate(d["fields"]):
lines.append(f"**Field {i+1}:** {f['name']}{f['value']}")
return "\n".join(lines) if lines else "No properties set yet."
def _build_view(self):
self.container.clear_items()
self.container.add_item(ui.TextDisplay("# Embed Builder"))
self.container.add_item(ui.Separator())
self.container.add_item(ui.TextDisplay(self._get_preview()))
self.container.add_item(ui.Separator())
self.container.add_item(ui.TextDisplay("*Select an option to edit. Respond within 30 seconds.*"))
# Select menu
select = ui.Select(
placeholder="Choose an option to edit the Embed",
min_values=1, max_values=1,
options=[
discord.SelectOption(label="Title", description="Edit the title"),
discord.SelectOption(label="Description", description="Edit the description"),
discord.SelectOption(label="Add Field", description="Add a field"),
discord.SelectOption(label="Color", description="Edit the color (hex)"),
discord.SelectOption(label="Thumbnail", description="Set thumbnail URL"),
discord.SelectOption(label="Image", description="Set image URL"),
discord.SelectOption(label="Footer Text", description="Edit footer text"),
discord.SelectOption(label="Footer Icon", description="Set footer icon URL"),
discord.SelectOption(label="Author Text", description="Edit author text"),
discord.SelectOption(label="Author Icon", description="Set author icon URL"),
]
)
select.callback = self._select_callback
self.container.add_item(ui.ActionRow(select))
# Buttons
send_btn = ui.Button(label="Send Embed", emoji=TICK, style=discord.ButtonStyle.success)
send_btn.callback = self._send_callback
cancel_btn = ui.Button(label="Cancel Setup", emoji=CROSS, style=discord.ButtonStyle.danger)
cancel_btn.callback = self._cancel_callback
self.container.add_item(ui.ActionRow(send_btn, cancel_btn))
def _build_embed(self):
"""Build a real discord.Embed from stored data"""
d = self.embed_data
embed = discord.Embed(
title=d["title"],
description=d["description"],
color=d["color"]
)
if d["thumbnail"]:
embed.set_thumbnail(url=d["thumbnail"])
if d["image"]:
embed.set_image(url=d["image"])
if d["footer_text"] or d["footer_icon"]:
embed.set_footer(text=d["footer_text"] or "", icon_url=d["footer_icon"] or discord.Embed.Empty)
if d["author_text"] or d["author_icon"]:
embed.set_author(name=d["author_text"] or "", icon_url=d["author_icon"] or discord.Embed.Empty)
for field in d["fields"]:
embed.add_field(name=field["name"], value=field["value"], inline=False)
return embed
async def _select_callback(self, interaction: discord.Interaction):
if interaction.user.id != self.ctx.author.id:
await interaction.response.send_message("This builder doesn't belong to you.", ephemeral=True)
return
await interaction.response.defer()
value = interaction.data["values"][0]
def chk(m):
return m.channel.id == self.ctx.channel.id and m.author.id == self.ctx.author.id
prompts = {
"Title": "Enter the **Title** of the embed:",
"Description": "Enter the **Description** of the embed:",
"Color": "Enter the color as a hex value (e.g., `#FF0000`):",
"Thumbnail": "Enter the **Thumbnail URL**:",
"Image": "Enter the **Image URL**:",
"Footer Text": "Enter the **Footer text**:",
"Footer Icon": "Enter the **Footer icon URL**:",
"Author Text": "Enter the **Author text**:",
"Author Icon": "Enter the **Author icon URL**:",
"Add Field": "Enter the **Field title**:",
}
await self.ctx.send(prompts.get(value, "Enter a value:"))
try:
msg = await self.ctx.bot.wait_for("message", timeout=30, check=chk)
if value == "Title":
self.embed_data["title"] = msg.content
elif value == "Description":
self.embed_data["description"] = msg.content
elif value == "Color":
try:
self.embed_data["color"] = int(msg.content.strip("#"), 16)
except ValueError:
await self.ctx.send("Invalid hex color. Please try again.")
return
elif value == "Thumbnail":
if not msg.content.startswith("http"):
await self.ctx.send("Invalid URL format.")
return
self.embed_data["thumbnail"] = msg.content
elif value == "Image":
if not msg.content.startswith("http"):
await self.ctx.send("Invalid URL format.")
return
self.embed_data["image"] = msg.content
elif value == "Footer Text":
self.embed_data["footer_text"] = msg.content
elif value == "Footer Icon":
if not msg.content.startswith("http"):
await self.ctx.send("Invalid URL format.")
return
self.embed_data["footer_icon"] = msg.content
elif value == "Author Text":
self.embed_data["author_text"] = msg.content
elif value == "Author Icon":
if not msg.content.startswith("http"):
await self.ctx.send("Invalid URL format.")
return
self.embed_data["author_icon"] = msg.content
elif value == "Add Field":
field_name = msg.content
await self.ctx.send("Enter the **Field value**:")
val_msg = await self.ctx.bot.wait_for("message", timeout=30, check=chk)
self.embed_data["fields"].append({"name": field_name, "value": val_msg.content})
# Rebuild and update
self._build_view()
await self.message.edit(view=self)
except asyncio.TimeoutError:
await self.ctx.send("Timed Out.")
async def _send_callback(self, interaction: discord.Interaction):
if interaction.user.id != self.ctx.author.id:
await interaction.response.send_message("This builder doesn't belong to you.", ephemeral=True)
return
await interaction.response.defer()
await self.ctx.send("Mention the **channel** where you want to send this embed:")
def chk(m):
return m.channel.id == self.ctx.channel.id and m.author.id == self.ctx.author.id
try:
msg = await self.ctx.bot.wait_for("message", timeout=30, check=chk)
chnl = msg.channel_mentions[0]
embed = self._build_embed()
await chnl.send(embed=embed)
# Show success
self.container.clear_items()
self.container.add_item(ui.TextDisplay(f"# {TICK} Embed Sent"))
self.container.add_item(ui.Separator())
self.container.add_item(ui.TextDisplay(f"Successfully sent the embed to {chnl.mention}"))
await self.message.edit(view=self)
except asyncio.TimeoutError:
await self.ctx.send("Timed Out.")
except (IndexError, AttributeError):
await self.ctx.send("Please mention a valid channel.")
async def _cancel_callback(self, interaction: discord.Interaction):
if interaction.user.id != self.ctx.author.id:
await interaction.response.send_message("This builder doesn't belong to you.", ephemeral=True)
return
self.container.clear_items()
self.container.add_item(ui.TextDisplay("# Embed Builder"))
self.container.add_item(ui.Separator())
self.container.add_item(ui.TextDisplay(f"{CROSS} Embed setup cancelled."))
await interaction.response.edit_message(view=self)
self.stop()
async def on_timeout(self):
try:
self.container.clear_items()
self.container.add_item(ui.TextDisplay("# Embed Builder"))
self.container.add_item(ui.Separator())
self.container.add_item(ui.TextDisplay("⏰ Builder timed out. Use the command again."))
await self.message.edit(view=self)
except:
pass
class Embed(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.hybrid_command(name="embed")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 7, commands.BucketType.user)
@commands.has_permissions(manage_messages=True)
async def _embed(self, ctx):
view = EmbedBuilder(ctx)
view.message = await ctx.send(view=view)

199
bot/cogs/commands/Games.py Normal file
View File

@@ -0,0 +1,199 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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 os
from core import Cog, zyrox, Context
import games as games
from utils.Tools import *
from utils.cv2 import CV2
from games import button_games as btn
import random
import asyncio
class Games(Cog):
"""Zyrox Games"""
def __init__(self, client: zyrox):
self.client = client
@commands.hybrid_command(name="chess",
help="Play Chess with a user.",
usage="Chess <user>")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(5, per=commands.BucketType.default, wait=False)
@commands.guild_only()
async def _chess(self, ctx: Context, player: discord.Member):
if player == ctx.author:
await ctx.send(view=CV2("❌ Error", "You Cannot play game with yourself!"))
elif player.bot:
await ctx.send(view=CV2("❌ Error", "You cannot play with bots!"))
else:
game = btn.BetaChess(white=ctx.author, black=player)
await game.start(ctx)
@commands.hybrid_command(name="rps",
help="Play Rock Paper Scissor with bot/user.",
aliases=["rockpaperscissors"],
usage="Rockpaperscissors")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(5, per=commands.BucketType.default, wait=False)
@commands.guild_only()
async def _rps(self, ctx: Context, player: discord.Member = None):
game = btn.BetaRockPaperScissors(player)
await game.start(ctx, timeout=120)
@commands.hybrid_command(name="tic-tac-toe",
help="play tic-tac-toe game with a user.",
aliases=["ttt", "tictactoe"],
usage="Ticktactoe <member>")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(5, per=commands.BucketType.user, wait=False)
@commands.guild_only()
async def _ttt(self, ctx: Context, player: discord.Member):
if player == ctx.author:
await ctx.send(view=CV2("❌ Error", "You cannot play game with yourself!"))
elif player.bot:
await ctx.send(view=CV2("❌ Error", "You cannot play with bots!"))
else:
game = btn.BetaTictactoe(cross=ctx.author, circle=player)
await game.start(ctx, timeout=30)
@commands.hybrid_command(name="wordle",
help="Wordle Game | Play with bot.",
usage="Wordle")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(3, per=commands.BucketType.default, wait=False)
@commands.guild_only()
async def _wordle(self, ctx: Context):
game = games.Wordle()
await game.start(ctx, timeout=120)
@commands.hybrid_command(name="2048",
help="Play 2048 game with bot.",
aliases=["twenty48"],
usage="2048")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(3, per=commands.BucketType.default, wait=False)
@commands.guild_only()
async def _2048(self, ctx: Context):
game = btn.BetaTwenty48()
await game.start(ctx, win_at=2048)
@commands.hybrid_command(name="memory-game",
help="How strong is your memory?",
aliases=["memory"],
usage="memory-game")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(3, per=commands.BucketType.default, wait=False)
@commands.guild_only()
async def _memory(self, ctx: Context):
game = btn.MemoryGame()
await game.start(ctx)
@commands.hybrid_command(name="number-slider",
help="slide numbers with bot",
aliases=["slider"],
usage="slider")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(3, per=commands.BucketType.default, wait=False)
@commands.guild_only()
async def _number_slider(self, ctx: Context):
game = btn.NumberSlider()
await game.start(ctx)
@commands.hybrid_command(name="battleship",
help="Play battleship game with your friend.",
aliases=["battle-ship"],
usage="battleship <user>")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(3, per=commands.BucketType.default, wait=False)
@commands.guild_only()
async def _battle(self, ctx: Context, player: discord.Member):
game = btn.BetaBattleShip(player1=ctx.author, player2=player)
await game.start(ctx)
@commands.group(name="country-guesser",
help="Guess name of the country by flag.",
aliases=["guess", "guesser", "countryguesser"],
usage="country-guesser")
@commands.guild_only()
async def _country_guesser(self, ctx: Context):
if ctx.invoked_subcommand is None:
await ctx.send_help("country-guesser")
@_country_guesser.command(name="start",
help="Starts the country guesser game. It's a 100 Seconds Game so suggested to play in a SPECIFIC CHANNEL.")
async def _start_country_guesser(self, ctx: Context):
game = games.CountryGuesser(is_flags=True, hints=2)
await game.start(ctx)
"""@_country_guesser.command(name="end",
help="Ends the country guesser game.")
async def _end_country_guesser(self, ctx: Context):
await self.country_guesser_game.end_game_manually(ctx)"""
@commands.hybrid_command(name="connectfour",
help="Play Connect Four game with user.",
aliases=["c4", "connect-four", "connect4"],
usage="connectfour <user>")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.user, wait=False)
@commands.guild_only()
async def _connectfour(self, ctx: Context, player: discord.Member):
if player == ctx.author:
await ctx.send(view=CV2("❌ Error", "You cannot play against yourself!"))
elif player.bot:
await ctx.send(view=CV2("❌ Error", "You cannot play with bots!"))
else:
game = games.ConnectFour(red=ctx.author, blue=player)
await game.start(ctx, timeout=300)
@commands.hybrid_command(name="lights-out",
help="Play Lights Show game with bot.",
aliases=["lightsout"],
usage="Lights-out")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(3, per=commands.BucketType.default, wait=False)
@commands.guild_only()
async def _lights_show(self, ctx: Context):
game = btn.LightsOut()
await game.start(ctx)

140
bot/cogs/commands/Invc.py Normal file
View File

@@ -0,0 +1,140 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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
from utils.Tools import *
from utils.cv2 import CV2
from utils.config import *
class Invcrole(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.db_path = 'db/invc.db'
self.bot.loop.create_task(self.create_table())
async def create_table(self):
async with aiosqlite.connect(self.db_path) as db:
await db.execute('''
CREATE TABLE IF NOT EXISTS vcroles (
guild_id INTEGER PRIMARY KEY,
role_id INTEGER NOT NULL
)
''')
await db.commit()
@commands.group(name='vcrole', help="Vcrole Setup commands", invoke_without_command=True)
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def vcrole(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@vcrole.command(name='add', help="Adds a role to the vcrole list")
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def add(self, ctx, role: discord.Role):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute('SELECT role_id FROM vcroles WHERE guild_id = ?', (ctx.guild.id,)) as cursor:
row = await cursor.fetchone()
if row:
await ctx.reply(view=CV2("⚠️ Access Denied", f"VC role is already set in this guild with the role {ctx.guild.get_role(row[0]).mention}.\nPlease **remove** it to add another one."))
return
await db.execute('INSERT INTO vcroles (guild_id, role_id) VALUES (?, ?)', (ctx.guild.id, role.id))
await db.commit()
await ctx.reply(view=CV2("✅ Success", f"VC role {role.mention} added for this guild."))
@vcrole.command(name='remove', aliases=["reset"], help="Removes the role from vcrole list")
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def remove(self, ctx, role: discord.Role):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute('SELECT role_id FROM vcroles WHERE guild_id = ? AND role_id = ?', (ctx.guild.id, role.id)) as cursor:
row = await cursor.fetchone()
if not row:
await ctx.send(view=CV2("❌ Error", "Given role is not set in VC role."))
return
await db.execute('DELETE FROM vcroles WHERE guild_id = ? AND role_id = ?', (ctx.guild.id, role.id))
await db.commit()
await ctx.send(view=CV2("✅ Success", f"VC role {role.mention} removed for this guild."))
@vcrole.command(name='config', aliases=['view', 'show'], help="Shows the Current vcrole in this Guild")
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def config(self, ctx):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute('SELECT role_id FROM vcroles WHERE guild_id = ?', (ctx.guild.id,)) as cursor:
row = await cursor.fetchone()
if not row:
await ctx.send(view=CV2("❌ Error", "VC role is not set in this guild."))
return
role = ctx.guild.get_role(row[0])
await ctx.send(view=CV2("VC Role Configuration", f"Current VC role in this guild is {role.mention}.\n\n*Make sure to place My role above Vc role*"))
@commands.Cog.listener()
async def on_voice_state_update(self, member, before, after):
try:
async with aiosqlite.connect(self.db_path) as db:
async with db.execute('SELECT role_id FROM vcroles WHERE guild_id = ?', (member.guild.id,)) as cursor:
row = await cursor.fetchone()
if not row:
return
role = member.guild.get_role(row[0])
if after.channel and role not in member.roles:
await self.add_role_with_retry(member, role, reason=f"Member Joined VC | {BRAND_NAME} Invcrole")
elif not after.channel and role in member.roles:
await self.remove_role_with_retry(member, role, reason=f"Member Left VC | {BRAND_NAME} Invcrole")
except discord.Forbidden:
print(f"Bot lacks permissions to maange role in a guild during Invc Event .")
except Exception as e:
print(f"Error in on_voice_state_update: {e}")
async def add_role_with_retry(self, member, role, reason, retries=5):
attempt = 0
while attempt < retries:
try:
await member.add_roles(role, reason=reason)
break
except discord.errors.RateLimited as e:
retry_after = e.retry_after if hasattr(e, 'retry_after') else 1
await asyncio.sleep(retry_after)
except discord.HTTPException as e:
print(f"Error adding role: {e}")
break
attempt += 1
async def remove_role_with_retry(self, member, role, reason, retries=5):
attempt = 0
while attempt < retries:
try:
await member.remove_roles(role, reason=reason)
break
except discord.errors.RateLimited as e:
retry_after = e.retry_after if hasattr(e, 'retry_after') else 1
await asyncio.sleep(retry_after)
except discord.HTTPException as e:
print(f"Error removing role: {e}")
break
attempt += 1
async def setup(bot):
await bot.add_cog(Invcrole(bot))

237
bot/cogs/commands/Media.py Normal file
View File

@@ -0,0 +1,237 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
import aiosqlite
from discord.ext import commands
from utils.Tools import blacklist_check, ignore_check
from collections import defaultdict
import time
from utils.cv2 import CV2
class Media(commands.Cog):
def __init__(self, client):
self.client = client
self.infractions = defaultdict(list)
async def set_db(self):
async with aiosqlite.connect('db/media.db') as db:
await db.execute('''
CREATE TABLE IF NOT EXISTS media_channels (
guild_id INTEGER PRIMARY KEY,
channel_id INTEGER NOT NULL
)
''')
await db.execute('''
CREATE TABLE IF NOT EXISTS media_bypass (
guild_id INTEGER,
user_id INTEGER,
PRIMARY KEY (guild_id, user_id)
)
''')
await db.commit()
@commands.Cog.listener()
async def on_ready(self):
await self.set_db()
@commands.hybrid_group(name="media", help="Setup Media channel, Media channel will not allow users to send messages other than media files.", invoke_without_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def media(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@media.command(name="setup", aliases=["set", "add"], help="Sets up a media-only channel for the server")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def setup(self, ctx, *, channel: discord.TextChannel):
async with aiosqlite.connect('db/media.db') as db:
async with db.execute('SELECT channel_id FROM media_channels WHERE guild_id = ?', (ctx.guild.id,)) as cursor:
result = await cursor.fetchone()
if result:
await ctx.reply(view=CV2("❌ Error", "A media channel is already set. Please remove it before setting a new one."))
return
await db.execute('INSERT INTO media_channels (guild_id, channel_id) VALUES (?, ?)', (ctx.guild.id, channel.id))
await db.commit()
await ctx.reply(view=CV2("✅ Success", f"Successfully set {channel.mention} as the media-only channel.\n\n*Make sure to grant me \"Manage Messages\" permission for functioning of media channel.*"))
@media.command(name="remove", aliases=["reset", "delete"], help="Removes the current media-only channel")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def remove(self, ctx):
async with aiosqlite.connect('db/media.db') as db:
async with db.execute('SELECT channel_id FROM media_channels WHERE guild_id = ?', (ctx.guild.id,)) as cursor:
result = await cursor.fetchone()
if not result:
await ctx.reply(view=CV2("❌ Error", "There is no media-only channel set for this server."))
return
await db.execute('DELETE FROM media_channels WHERE guild_id = ?', (ctx.guild.id,))
await db.commit()
await ctx.reply(view=CV2("✅ Success", "Successfully removed the media-only channel."))
@media.command(name="config", aliases=["settings", "show"], help="Shows the configured media-only channel")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def config(self, ctx):
async with aiosqlite.connect('db/media.db') as db:
async with db.execute('SELECT channel_id FROM media_channels WHERE guild_id = ?', (ctx.guild.id,)) as cursor:
result = await cursor.fetchone()
if not result:
await ctx.reply(view=CV2("❌ Error", "There is no media-only channel set for this server."))
return
channel = self.client.get_channel(result[0])
await ctx.reply(view=CV2("Media Only Channel", f"The configured media-only channel is {channel.mention}."))
@media.group(name="bypass", help="Add/Remove user to bypass in Media only channel, Bypassed users can send messages in Media channel.", invoke_without_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def bypass(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@bypass.command(name="add", help="Adds a user to the bypass list")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def bypass_add(self, ctx, user: discord.Member):
async with aiosqlite.connect('db/media.db') as db:
async with db.execute('SELECT COUNT(*) FROM media_bypass WHERE guild_id = ?', (ctx.guild.id,)) as cursor:
count = await cursor.fetchone()
if count[0] >= 25:
await ctx.reply(view=CV2("❌ Error", "The bypass list can only hold up to 25 users."))
return
async with db.execute('SELECT 1 FROM media_bypass WHERE guild_id = ? AND user_id = ?', (ctx.guild.id, user.id)) as cursor:
result = await cursor.fetchone()
if result:
await ctx.reply(view=CV2("❌ Error", f"{user.mention} is already in the bypass list."))
return
await db.execute('INSERT INTO media_bypass (guild_id, user_id) VALUES (?, ?)', (ctx.guild.id, user.id))
await db.commit()
await ctx.reply(view=CV2("✅ Success", f"{user.mention} has been added to the bypass list."))
@bypass.command(name="remove", help="Removes a user from the bypass list")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def bypass_remove(self, ctx, user: discord.Member):
async with aiosqlite.connect('db/media.db') as db:
async with db.execute('SELECT 1 FROM media_bypass WHERE guild_id = ? AND user_id = ?', (ctx.guild.id, user.id)) as cursor:
result = await cursor.fetchone()
if not result:
await ctx.reply(view=CV2("❌ Error", f"{user.mention} is not in the bypass list."))
return
await db.execute('DELETE FROM media_bypass WHERE guild_id = ? AND user_id = ?', (ctx.guild.id, user.id))
await db.commit()
await ctx.reply(view=CV2("✅ Success", f"{user.mention} has been removed from the bypass list."))
@bypass.command(name="show", aliases=["list", "view"], help="Shows the bypass list")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def bypass_show(self, ctx):
async with aiosqlite.connect('db/media.db') as db:
async with db.execute('SELECT user_id FROM media_bypass WHERE guild_id = ?', (ctx.guild.id,)) as cursor:
result = await cursor.fetchall()
if not result:
await ctx.reply(view=CV2("Bypass List", "There are no users in the bypass list."))
return
users = [self.client.get_user(user_id).mention for user_id, in result]
user_mentions = "\n".join(users)
await ctx.reply(view=CV2("Bypass List", user_mentions))
@commands.Cog.listener()
async def on_message(self, message):
if message.author.bot:
return
async with aiosqlite.connect('db/media.db') as db:
async with db.execute('SELECT channel_id FROM media_channels WHERE guild_id = ?', (message.guild.id,)) as cursor:
media_channel = await cursor.fetchone()
if media_channel and message.channel.id == media_channel[0]:
async with aiosqlite.connect('db/block.db') as block_db:
async with block_db.execute('SELECT 1 FROM user_blacklist WHERE user_id = ?', (message.author.id,)) as cursor:
blacklisted = await cursor.fetchone()
async with aiosqlite.connect('db/media.db') as db:
async with db.execute('SELECT 1 FROM media_bypass WHERE guild_id = ? AND user_id = ?', (message.guild.id, message.author.id)) as cursor:
bypassed = await cursor.fetchone()
if blacklisted or bypassed:
return
if not message.attachments:
try:
await message.delete()
msg = await message.channel.send(view=CV2("⚠️ Warning", f"{message.author.mention} This channel is configured for Media only. Please send only media files."))
await msg.delete(delay=5)
except discord.Forbidden:
pass
except discord.HTTPException:
pass
except Exception:
pass
current_time = time.time()
self.infractions[message.author.id].append(current_time)
self.infractions[message.author.id] = [
infraction for infraction in self.infractions[message.author.id]
if current_time - infraction <= 5
]
if len(self.infractions[message.author.id]) >= 5:
async with aiosqlite.connect('db/block.db') as block_db:
await block_db.execute('INSERT OR IGNORE INTO user_blacklist (user_id) VALUES (?)', (message.author.id,))
await block_db.commit()
desc = (
"⚠️ You are blacklisted from using my commands due to spamming in the media channel. "
"If you believe this is a mistake, please reach out to the support server with proof."
)
await message.channel.send(f"{message.author.mention}", view=CV2("You Have Been Blacklisted", desc))
del self.infractions[message.author.id]
async def setup(bot):
await bot.add_cog(Media(bot))

250
bot/cogs/commands/afk.py Normal file
View File

@@ -0,0 +1,250 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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
from discord.ui import LayoutView, TextDisplay, Separator, Container, Button, ActionRow
import aiosqlite
import os
import time
from utils.Tools import blacklist_check, ignore_check
from utils.cv2 import CV2, build_container
from utils.emoji import TICK, MENTION, SEED, TIME
from utils.config import *
DB_PATH = "db/afk.db"
THEME_COLOR = 0xFF0000
FOOTER_TEXT = f"Developed by {BRAND_NAME}"
class AfkTypeView(LayoutView):
def __init__(self, author, reason, timeout=60):
super().__init__(timeout=timeout)
self.author = author
self.reason = reason
self.value = None
self.global_btn = Button(label="Global AFK", style=discord.ButtonStyle.primary)
self.local_btn = Button(label="Local AFK", style=discord.ButtonStyle.success)
self.global_btn.callback = self.global_afk
self.local_btn.callback = self.local_afk
self.add_item(
build_container(
TextDisplay(f"You are going AFK for reason: **{reason}**"),
Separator(visible=True),
TextDisplay("Select your preferred AFK type from the buttons below."),
ActionRow(self.global_btn, self.local_btn)
)
)
async def interaction_check(self, interaction: discord.Interaction):
if interaction.user.id != self.author.id:
await interaction.response.send_message(
f"Only **{self.author.display_name}** can use this button.", ephemeral=True)
return False
return True
async def global_afk(self, interaction: discord.Interaction):
self.value = "global"
await interaction.response.defer()
self.stop()
async def local_afk(self, interaction: discord.Interaction):
self.value = "local"
await interaction.response.defer()
self.stop()
class AfkSuccess(LayoutView):
def __init__(self, type_val, reason):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay(f"{TICK} **AFK Activated**"),
Separator(visible=True),
TextDisplay(f"**{MENTION} You are now marked as {type_val.capitalize()} AFK.**\n{SEED} **Reason:** {reason}")
)
)
class AfkMention(LayoutView):
def __init__(self, user_mention, afk_time, reason):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay(f"**{user_mention.display_name}** is AFK right now!"),
Separator(visible=True),
TextDisplay(f"Went AFK <t:{int(afk_time)}:R> for the following reason:\n**{reason}**")
)
)
class AfkWelcomeBack(LayoutView):
def __init__(self, author, mentions, elapsed_time):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay(f"**{author.display_name}** Is Back!"),
Separator(visible=True),
TextDisplay(f"{TICK} **AFK Removed**\n{MENTION} **Mentions:** {mentions}\n{TIME} **AFK Time:** {elapsed_time}")
)
)
class afk(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.theme_color = THEME_COLOR
self.bot.loop.create_task(self.initialize_db())
async def initialize_db(self):
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
async with aiosqlite.connect(DB_PATH) as db:
await db.execute("""
CREATE TABLE IF NOT EXISTS afk (
user_id INTEGER PRIMARY KEY,
type TEXT NOT NULL,
reason TEXT NOT NULL,
time INTEGER NOT NULL,
mentions INTEGER NOT NULL DEFAULT 0
)
""")
await db.execute("""
CREATE TABLE IF NOT EXISTS afk_guild (
user_id INTEGER NOT NULL,
guild_id INTEGER NOT NULL,
PRIMARY KEY (user_id, guild_id)
)
""")
await db.commit()
async def time_formatter(self, seconds: float):
m, s = divmod(int(seconds), 60)
h, m = divmod(m, 60)
d, h = divmod(h, 24)
parts = []
if d > 0: parts.append(f"{d}d")
if h > 0: parts.append(f"{h}h")
if m > 0: parts.append(f"{m}m")
if s > 0: parts.append(f"{s}s")
return " ".join(parts) or "0s"
async def set_afk(self, user, afk_type, reason, current_guild=None):
async with aiosqlite.connect(DB_PATH) as db:
await db.execute("DELETE FROM afk_guild WHERE user_id = ?", (user.id,))
await db.execute(
"INSERT OR REPLACE INTO afk (user_id, type, reason, time, mentions) VALUES (?, ?, ?, ?, 0)",
(user.id, afk_type, reason, int(time.time()))
)
if afk_type == "global":
for g in self.bot.guilds:
if g.get_member(user.id):
await db.execute("INSERT OR IGNORE INTO afk_guild (user_id, guild_id) VALUES (?, ?)", (user.id, g.id))
elif current_guild:
await db.execute("INSERT OR IGNORE INTO afk_guild (user_id, guild_id) VALUES (?, ?)", (user.id, current_guild.id))
await db.commit()
async def clear_afk(self, message):
async with aiosqlite.connect(DB_PATH) as db:
cursor = await db.execute("SELECT 1 FROM afk_guild WHERE user_id = ? AND guild_id = ?", (message.author.id, message.guild.id))
if not await cursor.fetchone():
return
cursor = await db.execute("SELECT type, time, mentions FROM afk WHERE user_id = ?", (message.author.id,))
afk_data = await cursor.fetchone()
if not afk_data: return
afk_type, afk_time, mentions = afk_data
elapsed_time = await self.time_formatter(time.time() - afk_time)
if afk_type == 'global':
await db.execute("DELETE FROM afk WHERE user_id = ?", (message.author.id,))
await db.execute("DELETE FROM afk_guild WHERE user_id = ?", (message.author.id,))
else:
await db.execute("DELETE FROM afk_guild WHERE user_id = ? AND guild_id = ?", (message.author.id, message.guild.id))
cursor_check = await db.execute("SELECT 1 FROM afk_guild WHERE user_id = ?", (message.author.id,))
if not await cursor_check.fetchone():
await db.execute("DELETE FROM afk WHERE user_id = ?", (message.author.id,))
await db.commit()
view = AfkWelcomeBack(message.author, mentions, elapsed_time)
try:
await message.reply(view=view, delete_after=10, mention_author=False)
except discord.HTTPException:
pass
@commands.Cog.listener()
async def on_message(self, message):
if message.author.bot or not message.guild:
return
await self.clear_afk(message)
if not message.mentions:
return
async with aiosqlite.connect(DB_PATH) as db:
for mentioned in message.mentions:
if mentioned.bot or mentioned.id == message.author.id:
continue
cursor = await db.execute("SELECT 1 FROM afk_guild WHERE user_id = ? AND guild_id = ?", (mentioned.id, message.guild.id))
if await cursor.fetchone():
cursor_main = await db.execute("SELECT reason, mentions, time FROM afk WHERE user_id = ?", (mentioned.id,))
afk_data = await cursor_main.fetchone()
if not afk_data: continue
reason, mentions, afk_time = afk_data
view = AfkMention(mentioned, afk_time, reason)
await message.reply(view=view, delete_after=10, mention_author=False)
new_mentions = mentions + 1
await db.execute("UPDATE afk SET mentions = ? WHERE user_id = ?", (new_mentions, mentioned.id))
await db.commit()
dm_embed = discord.Embed(description=f"You were mentioned in **{message.guild.name}** by **{message.author}**", color=self.theme_color)
dm_embed.add_field(name="Total Mentions", value=str(new_mentions))
dm_embed.add_field(name="Jump to Message", value=f"[Click Here]({message.jump_url})")
dm_embed.set_footer(text=FOOTER_TEXT, icon_url=self.bot.user.avatar.url)
try:
await mentioned.send(embed=dm_embed)
except discord.Forbidden:
pass
@commands.hybrid_command(name="afk", description="Set your AFK status with a reason (Global or Local).")
@blacklist_check()
@ignore_check()
@commands.guild_only()
@commands.cooldown(1, 5, commands.BucketType.user)
async def afk(self, ctx: commands.Context, *, reason: str = "I am AFK"):
if any(w in reason.lower() for w in ("discord.gg", "gg/")):
return await ctx.send(embed=discord.Embed(description="⚠️ Advertising is not allowed in AFK reasons.", color=self.theme_color), ephemeral=True)
type_view = AfkTypeView(ctx.author, reason)
msg = await ctx.reply(view=type_view, mention_author=False)
await type_view.wait()
if not type_view.value:
await msg.edit(content="Timed out.", view=None)
return
await self.set_afk(ctx.author, type_view.value, reason, ctx.guild)
success_view = AfkSuccess(type_view.value, reason)
await msg.edit(view=success_view)
async def setup(bot):
await bot.add_cog(afk(bot))

1631
bot/cogs/commands/ai.py Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,100 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import CROSS, MANAGER, REDDOT, TICK
from discord.ext import commands
from discord.ui import LayoutView, TextDisplay, Separator, Container
import aiosqlite
from utils.Tools import *
from utils.cv2 import CV2, build_container
class Unwhitelist(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.bot.loop.create_task(self.initialize_db())
#@commands.Cog.listener()
async def initialize_db(self):
self.db = await aiosqlite.connect('db/anti.db')
@commands.hybrid_command(name='unwhitelist', aliases=['unwl'], help="Unwhitelist a user from antinuke")
@commands.has_permissions(administrator=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 10, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
async def unwhitelist(self, ctx, member: discord.Member = None):
if ctx.guild.member_count < 2:
view = CV2(f"{CROSS} Error", "Your Server Doesn't Meet My 30 Member Criteria")
return await ctx.send(view=view)
async with self.db.execute(
"SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
(ctx.guild.id, ctx.author.id)
) as cursor:
check = await cursor.fetchone()
async with self.db.execute(
"SELECT status FROM antinuke WHERE guild_id = ?",
(ctx.guild.id,)
) as cursor:
antinuke = await cursor.fetchone()
is_owner = ctx.author.id == ctx.guild.owner_id
if not is_owner and not check:
view = CV2(f"{CROSS} Access Denied", "Only Server Owner or Extra Owner can Run this Command!")
return await ctx.send(view=view)
if not antinuke or not antinuke[0]:
view = CV2(
f"{ctx.guild.name} Security Settings {MANAGER}",
f"Ohh NO! looks like your server doesn't enabled security\n\nCurrent Status : {CROSS}\n\nTo enable use `antinuke enable`"
)
return await ctx.send(view=view)
if not member:
view = CV2(
"__Unwhitelist Commands__",
"**Removes user from whitelisted users which means that the antinuke module will now take actions on them if they trigger it.**",
f"**Usage**\n{REDDOT} `unwhitelist @user/id`\n{REDDOT} `unwl @user`"
)
return await ctx.send(view=view)
async with self.db.execute(
"SELECT * FROM whitelisted_users WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, member.id)
) as cursor:
data = await cursor.fetchone()
if not data:
view = CV2(f"{CROSS} Error", f"<@{member.id}> is not a whitelisted member.")
return await ctx.send(view=view)
await self.db.execute(
"DELETE FROM whitelisted_users WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, member.id)
)
await self.db.commit()
view = CV2(f"{TICK} Success", f"User <@!{member.id}> has been removed from the whitelist.")
await ctx.send(view=view)

View File

@@ -0,0 +1,365 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import ARROWRED, CROSS, DISABLE, ENABLE, MANAGER, TICK
from discord.ext import commands
from discord.ui import LayoutView, TextDisplay, Separator, Container
import aiosqlite
from utils.Tools import *
from utils.cv2 import CV2, build_container
class Whitelist(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.bot.loop.create_task(self.initialize_db())
#@commands.Cog.listener()
async def initialize_db(self):
self.db = await aiosqlite.connect('db/anti.db')
await self.db.execute('''
CREATE TABLE IF NOT EXISTS whitelisted_users (
guild_id INTEGER,
user_id INTEGER,
ban BOOLEAN DEFAULT FALSE,
kick BOOLEAN DEFAULT FALSE,
prune BOOLEAN DEFAULT FALSE,
botadd BOOLEAN DEFAULT FALSE,
serverup BOOLEAN DEFAULT FALSE,
memup BOOLEAN DEFAULT FALSE,
chcr BOOLEAN DEFAULT FALSE,
chdl BOOLEAN DEFAULT FALSE,
chup BOOLEAN DEFAULT FALSE,
rlcr BOOLEAN DEFAULT FALSE,
rlup BOOLEAN DEFAULT FALSE,
rldl BOOLEAN DEFAULT FALSE,
meneve BOOLEAN DEFAULT FALSE,
mngweb BOOLEAN DEFAULT FALSE,
mngstemo BOOLEAN DEFAULT FALSE,
PRIMARY KEY (guild_id, user_id)
)
''')
await self.db.commit()
@commands.hybrid_command(name='whitelist', aliases=['wl'], help="Whitelists a user from antinuke for a specific action.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def whitelist(self, ctx, member: discord.Member = None):
if ctx.guild.member_count < 2:
view = CV2(f"{CROSS} Error", "Your Server Doesn't Meet My 30 Member Criteria")
return await ctx.send(view=view)
prefix=ctx.prefix
async with self.db.execute(
"SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
(ctx.guild.id, ctx.author.id)
) as cursor:
check = await cursor.fetchone()
async with self.db.execute(
"SELECT status FROM antinuke WHERE guild_id = ?",
(ctx.guild.id,)
) as cursor:
antinuke = await cursor.fetchone()
is_owner = ctx.author.id == ctx.guild.owner_id
if not is_owner and not check:
view = CV2(f"{CROSS} Access Denied", "Only Server Owner or Extra Owner can Run this Command!")
return await ctx.send(view=view)
if not antinuke or not antinuke[0]:
view = CV2(
f"{ctx.guild.name} Security Settings {MANAGER}",
f"Ohh No! looks like your server doesn't enabled Antinuke\n\nCurrent Status : {CROSS}\n\nTo enable use `{prefix}antinuke enable`"
)
return await ctx.send(view=view)
if not member:
view = CV2(
"__Whitelist Commands__",
"**Adding a user to the whitelist means that no actions will be taken against them if they trigger the Anti-Nuke Module.**",
f"**Usage**\n{ARROWRED} `{prefix}whitelist @user/id`\n{ARROWRED} `{prefix}wl @user`"
)
return await ctx.send(view=view)
async with self.db.execute(
"SELECT * FROM whitelisted_users WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, member.id)
) as cursor:
data = await cursor.fetchone()
if data:
view = CV2(f"{CROSS} Error", f"<@{member.id}> is already a whitelisted member, **Unwhitelist** the user and try again.")
return await ctx.send(view=view)
await self.db.execute(
"INSERT INTO whitelisted_users (guild_id, user_id) VALUES (?, ?)",
(ctx.guild.id, member.id)
)
await self.db.commit()
options = [
discord.SelectOption(label="Ban", description="Whitelist a member with ban permission", value="ban"),
discord.SelectOption(label="Kick", description="Whitelist a member with kick permission", value="kick"),
discord.SelectOption(label="Prune", description="Whitelist a member with prune permission", value="prune"),
discord.SelectOption(label="Bot Add", description="Whitelist a member with bot add permission", value="botadd"),
discord.SelectOption(label="Server Update", description="Whitelist a member with server update permission", value="serverup"),
discord.SelectOption(label="Member Update", description="Whitelist a member with member update permission", value="memup"),
discord.SelectOption(label="Channel Create", description="Whitelist a member with channel create permission", value="chcr"),
discord.SelectOption(label="Channel Delete", description="Whitelist a member with channel delete permission", value="chdl"),
discord.SelectOption(label="Channel Update", description="Whitelist a member with channel update permission", value="chup"),
discord.SelectOption(label="Role Create", description="Whitelist a member with role create permission", value="rlcr"),
discord.SelectOption(label="Role Update", description="Whitelist a member with role update permission", value="rlup"),
discord.SelectOption(label="Role Delete", description="Whitelist a member with role delete permission", value="rldl"),
discord.SelectOption(label="Mention Everyone", description="Whitelist a member with mention everyone permission", value="meneve"),
discord.SelectOption(label="Manage Webhook", description="Whitelist a member with manage webhook permission", value="mngweb")
]
select = discord.ui.Select(placeholder="Choose Your Options", min_values=1, max_values=len(options), options=options, custom_id="wl")
button = discord.ui.Button(label="Add This User To All Categories", style=discord.ButtonStyle.primary, custom_id="catWl")
action_view = discord.ui.View()
action_view.add_item(select)
action_view.add_item(button)
disabled_list = (
f"{DISABLE} : **Ban**\n"
f"{DISABLE} : **Kick**\n"
f"{DISABLE} : **Prune**\n"
f"{DISABLE} : **Bot Add**\n"
f"{DISABLE} : **Server Update**\n"
f"{DISABLE} : **Member Update**\n"
f"{DISABLE} : **Channel Create**\n"
f"{DISABLE} : **Channel Delete**\n"
f"{DISABLE} : **Channel Update**\n"
f"{DISABLE} : **Role Create**\n"
f"{DISABLE} : **Role Delete**\n"
f"{DISABLE} : **Role Update**\n"
f"{DISABLE} : **Mention** @everyone\n"
f"{DISABLE} : **Webhook Management**"
)
wl_view = CV2(
ctx.guild.name,
disabled_list,
f"**Executor:** <@!{ctx.author.id}> │ **Target:** <@!{member.id}>"
)
msg = await ctx.send(view=action_view)
def check(interaction):
return interaction.user.id == ctx.author.id and interaction.message.id == msg.id
try:
interaction = await self.bot.wait_for("interaction", check=check, timeout=60.0)
if interaction.data["custom_id"] == "catWl":
await self.db.execute(
"UPDATE whitelisted_users SET ban = ?, kick = ?, prune = ?, botadd = ?, serverup = ?, memup = ?, chcr = ?, chdl = ?, chup = ?, rlcr = ?, rldl = ?, rlup = ?, meneve = ?, mngweb = ?, mngstemo = ? WHERE guild_id = ? AND user_id = ?",
(True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, ctx.guild.id, member.id)
)
await self.db.commit()
enabled_list = (
f"{ENABLE} : **Ban**\n"
f"{ENABLE} : **Kick**\n"
f"{ENABLE} : **Prune**\n"
f"{ENABLE} : **Bot Add**\n"
f"{ENABLE} : **Server Update**\n"
f"{ENABLE} : **Member Update**\n"
f"{ENABLE} : **Channel Create**\n"
f"{ENABLE} : **Channel Delete**\n"
f"{ENABLE} : **Channel Update**\n"
f"{ENABLE} : **Role Create**\n"
f"{ENABLE} : **Role Delete**\n"
f"{ENABLE} : **Role Update**\n"
f"{ENABLE} : **Mention** @everyone\n"
f"{ENABLE} : **Webhook Management**"
)
result = CV2(
ctx.guild.name,
enabled_list,
f"**Executor:** <@!{ctx.author.id}> │ **Target:** <@!{member.id}>"
)
await interaction.response.edit_message(view=result)
else:
fields = {
'ban': 'Ban',
'kick': 'Kick',
'prune': 'Prune',
'botadd': 'Bot Add',
'serverup': 'Server Update',
'memup': 'Member Update',
'chcr': 'Channel Create',
'chdl': 'Channel Delete',
'chup': 'Channel Update',
'rlcr': 'Role Create',
'rldl': 'Role Delete',
'rlup': 'Role Update',
'meneve': 'Mention Everyone',
'mngweb': 'Manage Webhooks'
}
status_lines = []
selected_values = interaction.data["values"]
for key, name in fields.items():
if key in selected_values:
status_lines.append(f"{ENABLE} : **{name}**")
else:
status_lines.append(f"{DISABLE} : **{name}**")
for value in selected_values:
await self.db.execute(
f"UPDATE whitelisted_users SET {value} = ? WHERE guild_id = ? AND user_id = ?",
(True, ctx.guild.id, member.id)
)
await self.db.commit()
result = CV2(
ctx.guild.name,
"\n".join(status_lines),
f"**Executor:** <@!{ctx.author.id}> │ **Target:** <@!{member.id}>"
)
await interaction.response.edit_message(view=result)
except TimeoutError:
await msg.edit(view=None)
@commands.hybrid_command(name='whitelisted', aliases=['wlist'], help="Shows the list of whitelisted users.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def whitelisted(self, ctx):
if ctx.guild.member_count < 2:
view = CV2(f"{CROSS} Error", "Your Server Doesn't Meet My 30 Member Criteria")
return await ctx.send(view=view)
pre=ctx.prefix
async with self.db.execute(
"SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
(ctx.guild.id, ctx.author.id)
) as cursor:
check = await cursor.fetchone()
async with self.db.execute(
"SELECT status FROM antinuke WHERE guild_id = ?",
(ctx.guild.id,)
) as cursor:
antinuke = await cursor.fetchone()
is_owner = ctx.author.id == ctx.guild.owner_id
if not is_owner and not check:
view = CV2(f"{CROSS} Access Denied", "Only Server Owner or Extra Owner can Run this Command!")
return await ctx.send(view=view)
if not antinuke or not antinuke[0]:
view = CV2(
f"{ctx.guild.name} Security Settings {MANAGER}",
f"Ohh NO! looks like your server doesn't enabled security\n\nCurrent Status : {CROSS}\n\nTo enable use `{pre}antinuke enable`"
)
return await ctx.send(view=view)
async with self.db.execute(
"SELECT user_id FROM whitelisted_users WHERE guild_id = ?",
(ctx.guild.id,)
) as cursor:
data = await cursor.fetchall()
if not data:
view = CV2(f"{CROSS} Error", "No whitelisted users found.")
return await ctx.send(view=view)
whitelisted_users = [self.bot.get_user(user_id[0]) for user_id in data]
whitelisted_users_str = ", ".join(f"<@!{user.id}>" for user in whitelisted_users if user)
view = CV2(f"__Whitelisted Users for {ctx.guild.name}__", whitelisted_users_str)
await ctx.send(view=view)
@commands.hybrid_command(name="whitelistreset", aliases=['wlreset'], help="Resets the whitelisted users.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 10, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def whitelistreset(self, ctx):
if ctx.guild.member_count < 2:
view = CV2(f"{CROSS} Error", "Your Server Doesn't Meet My 30 Member Criteria")
return await ctx.send(view=view)
pre=ctx.prefix
async with self.db.execute(
"SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
(ctx.guild.id, ctx.author.id)
) as cursor:
check = await cursor.fetchone()
async with self.db.execute(
"SELECT status FROM antinuke WHERE guild_id = ?",
(ctx.guild.id,)
) as cursor:
antinuke = await cursor.fetchone()
is_owner = ctx.author.id == ctx.guild.owner_id
if not is_owner and not check:
view = CV2(f"{CROSS} Access Denied", "Only Server Owner or Extra Owner can Run this Command!")
return await ctx.send(view=view)
if not antinuke or not antinuke[0]:
view = CV2(
f"{ctx.guild.name} Security Settings {MANAGER}",
f"Ohh NO! looks like your server doesn't enabled security\n\nCurrent Status : {CROSS}\n\nTo enable use `{pre}antinuke enable`"
)
return await ctx.send(view=view)
async with self.db.execute(
"SELECT user_id FROM whitelisted_users WHERE guild_id = ?",
(ctx.guild.id,)
) as cursor:
data = await cursor.fetchall()
if not data:
view = CV2(f"{CROSS} Error", "No whitelisted users found.")
return await ctx.send(view=view)
await self.db.execute("DELETE FROM whitelisted_users WHERE guild_id = ?", (ctx.guild.id,))
await self.db.commit()
view = CV2(f"{TICK} Success", f"Removed all whitelisted members from {ctx.guild.name}")
await ctx.send(view=view)

View File

@@ -0,0 +1,253 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import CROSS, EMOTE, TICK, ZSAFE, ZSETTINGS
from discord.ext import commands
from discord.ui import LayoutView, TextDisplay, Separator, Container, Button, ActionRow
import aiosqlite
import asyncio
from utils.Tools import *
from utils.cv2 import CV2, build_container
from utils.config import *
class Antinuke(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.bot.loop.create_task(self.initialize_db())
async def initialize_db(self):
self.db = await aiosqlite.connect('db/anti.db')
await self.db.execute('''
CREATE TABLE IF NOT EXISTS antinuke (
guild_id INTEGER PRIMARY KEY,
status BOOLEAN
)
''')
await self.db.commit()
async def enable_limit_settings(self, guild_id):
default_limits = DEFAULT_LIMITS
for action, limit in default_limits.items():
await self.db.execute('INSERT OR REPLACE INTO limit_settings (guild_id, action_type, action_limit, time_window) VALUES (?, ?, ?, ?)', (guild_id, action, limit, TIME_WINDOW))
await self.db.commit()
async def disable_limit_settings(self, guild_id):
await self.db.execute('DELETE FROM limit_settings WHERE guild_id = ?', (guild_id,))
await self.db.commit()
@commands.hybrid_command(name='antinuke', aliases=['antiwizz', 'anti'], help="Enables/Disables Anti-Nuke Module in the server")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 4, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def antinuke(self, ctx, option: str = None):
guild_id = ctx.guild.id
pre=ctx.prefix
async with self.db.execute('SELECT status FROM antinuke WHERE guild_id = ?', (guild_id,)) as cursor:
row = await cursor.fetchone()
async with self.db.execute(
"SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?",
(ctx.guild.id, ctx.author.id)
) as cursor:
check = await cursor.fetchone()
is_owner = ctx.author.id == ctx.guild.owner_id
if not is_owner and not check:
view = CV2(f"{CROSS} Access Denied", "Only Server Owner or Extra Owner can Run this Command!")
return await ctx.send(view=view)
is_activated = row[0] if row else False
if option is None:
view = CV2(
f"{ZSAFE} {BRAND_NAME} Security",
"**Antinuke Defense Mode** — Protect your server from harmful admin actions with smart automated security protocols.",
"**Core Functionalities**\n"
"• Auto-ban malicious admin activities instantly.\n"
"• Whitelist protection for trusted users.\n"
"• Live monitoring of admin actions.\n"
"• Rapid threat detection & neutralization.",
"**Configuration Panel**\n"
f"{TICK} Enable Protection: `antinuke enable`\n"
f"{CROSS} Disable Protection: `antinuke disable`"
)
await ctx.send(view=view)
elif option.lower() == 'enable':
if is_activated:
view = CV2(
f"Security Settings For {ctx.guild.name}",
f"Your server __**already has Antinuke enabled.**__\n\nCurrent Status: {TICK} Enabled\nTo Disable use `antinuke disable`"
)
await ctx.send(view=view)
else:
setup_view = CV2(f"Antinuke Setup {EMOTE}", f"{TICK} | Initializing Quick Setup!")
setup_message = await ctx.send(view=setup_view)
if not ctx.guild.me.guild_permissions.administrator:
view = CV2(f"Antinuke Setup {EMOTE}",
f"{TICK} | Initializing Quick Setup!\n"
f"{CROSS} | **Ops! It seems I Don't Have Administrator Perm To enable antinuke**.")
await setup_message.edit(view=view)
return
await asyncio.sleep(1)
view = CV2(f"Antinuke Setup {EMOTE}",
f"{TICK} | Initializing Quick Setup!\n"
f"{TICK} Checking {BRAND_NAME}'s role position for optimal configuration...")
await setup_message.edit(view=view)
await asyncio.sleep(1)
view = CV2(f"Antinuke Setup {EMOTE}",
f"{TICK} | Initializing Quick Setup!\n"
f"{TICK} Checking {BRAND_NAME}'s role position for optimal configuration...\n"
f"{TICK} | Crafting and configuring the {BRAND_NAME} Supreme role...")
await setup_message.edit(view=view)
try:
role = await ctx.guild.create_role(
name=f"{BRAND_NAME} Supreme™",
color=0xFF0000,
permissions=discord.Permissions(administrator=True),
hoist=False,
mentionable=False,
reason="Antinuke setup Role Creation"
)
await ctx.guild.me.add_roles(role)
except discord.Forbidden:
view = CV2("Antinuke Setup", f"{CROSS} | **Uh oh! I don't Have perms to enable antinuke**.")
await setup_message.edit(view=view)
return
except discord.HTTPException as e:
view = CV2("Antinuke Setup", f"{CROSS} | **Uh: HTTPException: {e}\nCheck Guild Audit Logs**.")
await setup_message.edit(view=view)
return
await asyncio.sleep(1)
view = CV2(f"Antinuke Setup {EMOTE}",
f"{TICK} | Initializing Quick Setup!\n"
f"{TICK} Checking {BRAND_NAME}'s role position...\n"
f"{TICK} | Crafting the {BRAND_NAME} Supreme role...\n"
f"{TICK} | Ensuring precise placement of the {BRAND_NAME} Supreme™ role...")
await setup_message.edit(view=view)
try:
await ctx.guild.edit_role_positions(positions={role: 1})
except discord.Forbidden:
view = CV2("Antinuke Setup", f"{CROSS} | Ops! I don't have sufficient perms to move role.")
await setup_message.edit(view=view)
return
except discord.HTTPException as e:
view = CV2("Antinuke Setup", f"{CROSS} | Setup failed: HTTPException: {e}.")
await setup_message.edit(view=view)
return
await asyncio.sleep(1)
await asyncio.sleep(1)
await self.db.execute('INSERT OR REPLACE INTO antinuke (guild_id, status) VALUES (?, ?)', (guild_id, True))
await self.db.commit()
await asyncio.sleep(1)
await setup_message.delete()
modules = (
f"{TICK} **Anti Ban**\n"
f"{TICK} **Anti Kick**\n"
f"{TICK} **Anti Bot**\n"
f"{TICK} **Anti Channel Create**\n"
f"{TICK} **Anti Channel Delete**\n"
f"{TICK} **Anti Channel Update**\n"
f"{TICK} **Anti Everyone/Here**\n"
f"{TICK} **Anti Role Create**\n"
f"{TICK} **Anti Role Delete**\n"
f"{TICK} **Anti Role Update**\n"
f"{TICK} **Anti Member Update**\n"
f"{TICK} **Anti Guild Update**\n"
f"{TICK} **Anti Integration**\n"
f"{TICK} **Anti Webhook Create**\n"
f"{TICK} **Anti Webhook Delete**\n"
f"{TICK} **Anti Webhook Update**\n"
f"{TICK} **Anti Prune**\n"
f"{TICK} **Auto Recovery**"
)
punishment_btn = Button(label="Show Punishment Type", style=discord.ButtonStyle.secondary)
punishment_btn.callback = self._show_punishment
result_view = LayoutView(timeout=None)
result_view.add_item(
build_container(
TextDisplay(f"**{ZSETTINGS} Security Settings For {ctx.guild.name}**"),
Separator(visible=True),
TextDisplay("Tip: For optimal functionality, please ensure that my role has **Administration** permissions and is positioned at the **Top** of the roles list."),
Separator(visible=True),
TextDisplay(f"**Modules Enabled**\n{modules}"),
Separator(visible=True),
TextDisplay(f"Successfully Enabled Antinuke | Powered by {BRAND_NAME} Development™"),
ActionRow(punishment_btn)
)
)
await ctx.send(view=result_view)
elif option.lower() == 'disable':
if not is_activated:
view = CV2(
f"Security Settings For {ctx.guild.name}",
f"Uhh, looks like your server hasn't enabled Antinuke.\n\nCurrent Status: {CROSS} Disabled\n\nTo Enable use `antinuke enable`"
)
else:
await self.db.execute('DELETE FROM antinuke WHERE guild_id = ?', (guild_id,))
await self.db.commit()
view = CV2(
f"Security Settings For {ctx.guild.name}",
f"Successfully disabled Antinuke for this server.\n\nCurrent Status: {CROSS} Disabled\n\nTo Enable use `antinuke enable`"
)
await ctx.send(view=view)
else:
view = CV2(f"{CROSS} Error", "Invalid option. Please use `enable` or `disable`.")
await ctx.send(view=view)
async def _show_punishment(self, interaction: discord.Interaction):
view = CV2(
"Punishment Types for Unwhitelisted Admins/Mods",
"**Anti Ban:** Ban\n"
"**Anti Kick:** Ban\n"
"**Anti Bot:** Ban the bot Inviter\n"
"**Anti Channel Create/Delete/Update:** Ban\n"
"**Anti Everyone/Here:** Remove the message & 1 hour timeout\n"
"**Anti Role Create/Delete/Update:** Ban\n"
"**Anti Member Update:** Ban\n"
"**Anti Guild Update:** Ban\n"
"**Anti Integration:** Ban\n"
"**Anti Webhook Create/Delete/Update:** Ban\n"
"**Anti Prune:** Ban\n"
"**Auto Recovery:** Automatically recover damaged channels, roles, and settings",
"Note: In the case of member updates, action will be taken only if the role contains dangerous permissions such as Ban Members, Administrator, Manage Guild, Manage Channels, Manage Roles, Manage Webhooks, or Mention Everyone"
)
await interaction.response.send_message(view=view, ephemeral=True)

View File

@@ -0,0 +1,817 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import CROSS, DISABLE, ENABLE, TICK, TICK_ALT
from discord.ext import commands
import aiosqlite
from utils.Tools import *
from utils.cv2 import CV2, build_container
from discord.ui import LayoutView, TextDisplay, Separator, Container, ActionRow
from utils.config import *
class CV2(LayoutView):
def __init__(self, title, *sections):
super().__init__(timeout=None)
items = [TextDisplay(f"**{title}**")]
for s in sections:
if s:
items.append(Separator(visible=True))
items.append(TextDisplay(str(s)))
self.add_item(build_container(*items))
class ShowRules(LayoutView):
def __init__(self, author, selected_events, title, *sections):
super().__init__(timeout=60)
self.author = author
self.selected_events = selected_events
show_rules_btn = discord.ui.Button(label="Show Rules", style=discord.ButtonStyle.secondary)
show_rules_btn.callback = self._show_rules_callback
items = [TextDisplay(f"**{title}**")]
for s in sections:
if s:
items.append(Separator(visible=True))
items.append(TextDisplay(str(s)))
items.append(ActionRow(show_rules_btn))
self.add_item(build_container(*items))
async def _show_rules_callback(self, interaction: discord.Interaction):
if interaction.user != self.author:
await interaction.response.send_message("You are not allowed to interact with this button.", ephemeral=True)
return
rules = {
"Anti NSFW link": "__**Anti NSFW Link**__:\n• Takes action if the message contains a NSFW link.\n• Default punishment: Block message (unchangeable)",
"Anti caps": "__**Anti Caps**__:\n• Takes action if the message contains >70% caps.\n• Messages under 45 characters are bypassed\n• Default punishment: Mute (1 minutes)",
"Anti link": "__**Anti Link**__:\n• Takes action if the message contains a link.\n• Server invites, Spotify Music and GIF links are bypassed\n• Default punishment: Mute (7 minutes)",
"Anti invites": "__**Anti Invites**__:\n• Takes action if the message contains a Discord server invite.\n• Invites from the current server are bypassed\n• Default punishment: Mute (12 minutes)",
"Anti emoji spam": "__**Anti Emoji Spam**__:\n• Takes action if a message contains more than 5 emojis.\n• Default punishment: Mute (1 minute)",
"Anti mass mention": "__**Anti Mass Mention**__:\n• Takes action if a message contains more than 4 mentions.\n• Default punishment: Mute (3 minutes)",
"Anti spam": "__**Anti Spam**__:\n• Takes action if more than 5 messages are sent rapidly in a short time.\n• Default punishment: Mute (12 minutes)",
}
enabled_rules = "\n\n".join([rules[event] for event in self.selected_events if event in rules])
view = CV2("Enabled Automod Rules", enabled_rules, "Punishment type of each event is changeable except for Anti NSFW.")
await interaction.response.send_message(view=view, ephemeral=True)
class ConfirmDisable(LayoutView):
def __init__(self, author, title, *sections):
super().__init__(timeout=30)
self.author = author
self.value = None
yes_btn = discord.ui.Button(label="Yes", style=discord.ButtonStyle.danger)
yes_btn.callback = self._confirm_callback
no_btn = discord.ui.Button(label="No", style=discord.ButtonStyle.secondary)
no_btn.callback = self._cancel_callback
items = [TextDisplay(f"**{title}**")]
for s in sections:
if s:
items.append(Separator(visible=True))
items.append(TextDisplay(str(s)))
items.append(ActionRow(yes_btn, no_btn))
self.add_item(build_container(*items))
async def _confirm_callback(self, interaction: discord.Interaction):
if interaction.user != self.author:
await interaction.response.send_message("You are not allowed to interact with this button.", ephemeral=True)
return
await interaction.response.defer()
self.value = True
self.stop()
async def _cancel_callback(self, interaction: discord.Interaction):
if interaction.user != self.author:
await interaction.response.send_message("You are not allowed to interact with this button.", ephemeral=True)
return
await interaction.response.defer()
self.value = False
self.stop()
class Automod(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.default_punishment = "Mute"
self.bot.loop.create_task(self.init_db())
async def get_exempt_roles_channels(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
roles_cursor = await db.execute("SELECT id FROM automod_ignored WHERE guild_id = ? AND type = 'role'", (guild_id,))
channels_cursor = await db.execute("SELECT id FROM automod_ignored WHERE guild_id = ? AND type = 'channel'", (guild_id,))
exempt_roles = [discord.Object(id) for (id,) in await roles_cursor.fetchall()]
exempt_channels = [discord.Object(id) for (id,) in await channels_cursor.fetchall()]
return exempt_roles, exempt_channels
async def is_automod_enabled(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT enabled FROM automod WHERE guild_id = ?", (guild_id,))
result = await cursor.fetchone()
return result is not None and result[0] == 1
async def update_punishments(self, guild_id, event, punishment):
async with aiosqlite.connect("db/automod.db") as db:
await db.execute("INSERT OR REPLACE INTO automod_punishments (guild_id, event, punishment) VALUES (?, ?, ?)", (guild_id, event, punishment))
await db.commit()
async def get_current_punishments(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
async with db.execute(
"SELECT event, punishment FROM automod_punishments WHERE guild_id = ? AND event != 'Anti NSFW link'",
(guild_id,)
) as cursor:
return await cursor.fetchall()
async def is_anti_nsfw_enabled(self, guild_id):
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT punishment FROM automod_punishments WHERE guild_id = ? AND event = 'Anti NSFW link'", (guild_id,))
result = await cursor.fetchone()
return result is not None
async def init_db(self):
async with aiosqlite.connect("db/automod.db") as db:
await db.execute("""
CREATE TABLE IF NOT EXISTS automod (
guild_id INTEGER PRIMARY KEY,
enabled INTEGER DEFAULT 0
)
""")
await db.execute("""
CREATE TABLE IF NOT EXISTS automod_punishments (
guild_id INTEGER,
event TEXT,
punishment TEXT,
PRIMARY KEY (guild_id, event)
)
""")
await db.execute("""
CREATE TABLE IF NOT EXISTS automod_ignored (
guild_id INTEGER,
type TEXT,
id INTEGER,
PRIMARY KEY (guild_id, type, id)
)
""")
await db.execute("""
CREATE TABLE IF NOT EXISTS automod_logging (
guild_id INTEGER,
log_channel INTEGER,
PRIMARY KEY (guild_id)
)
""")
await db.commit()
@commands.hybrid_group(invoke_without_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 4, commands.BucketType.user)
async def automod(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@automod.command(name="enable", help="Enable Automod on the server.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
@commands.bot_has_permissions(manage_guild=True)
async def enable(self, ctx):
guild_id = ctx.guild.id
if ctx.author != ctx.guild.owner and ctx.author.top_role.position < ctx.guild.me.top_role.position:
await ctx.send(view=CV2(f"{CROSS} Access Denied", "Your top role must be at the **same** position or **higher** than my top role."))
return
if await self.is_automod_enabled(guild_id):
await ctx.send(view=CV2(f"Automod Settings for {ctx.guild.name}", f"**{CROSS} Your Server already has Automoderation Enabled.**\n\nCurrent Status: {ENABLE} Enabled\nTo Disable use `{ctx.prefix}automod disable`"))
return
events = [
"Anti spam",
"Anti caps",
"Anti link",
"Anti invites",
"Anti mass mention",
"Anti emoji spam",
"Anti NSFW link",
]
select_menu = discord.ui.Select(placeholder="Select events to enable", min_values=1, max_values=len(events), options=[
discord.SelectOption(label=event, value=event) for event in events
])
async def select_callback(interaction):
if interaction.user != ctx.author:
await interaction.response.send_message("You are not allowed to interact with this menu.", ephemeral=True)
return
await interaction.response.defer()
selected_events = select_menu.values
await self.enable_automod(ctx, guild_id, selected_events, interaction)
select_menu.callback = select_callback
enable_all_button = discord.ui.Button(label="Enable for All Events", style=discord.ButtonStyle.primary)
async def enable_all_callback(interaction):
if interaction.user != ctx.author:
await interaction.response.send_message("You are not allowed to interact with this button.", ephemeral=True)
return
await interaction.response.defer()
await self.enable_automod(ctx, guild_id, events, interaction)
enable_all_button.callback = enable_all_callback
cancel_button = discord.ui.Button(label="Cancel", style=discord.ButtonStyle.danger)
async def cancel_callback(interaction):
if interaction.user != ctx.author:
await interaction.response.send_message("You are not allowed to interact with this button.", ephemeral=True)
return
cancel_view = CV2("Automod Setup Cancelled", "The automod setup has been cancelled.")
await interaction.response.edit_message(view=cancel_view)
cancel_button.callback = cancel_callback
events_text = "\n".join([f"{DISABLE} : {event}" for event in events])
view = LayoutView(timeout=60)
view.add_item(build_container(
TextDisplay(f"**{ctx.guild.name}'s Automod Setup**"),
Separator(visible=True),
TextDisplay(events_text),
ActionRow(select_menu),
ActionRow(enable_all_button, cancel_button)
))
await ctx.send(view=view)
async def enable_automod(self, ctx, guild_id, selected_events, interaction):
async with aiosqlite.connect("db/automod.db") as db:
await db.execute("INSERT OR REPLACE INTO automod (guild_id, enabled) VALUES (?, 1)", (guild_id,))
for event in selected_events:
await db.execute("INSERT OR REPLACE INTO automod_punishments (guild_id, event, punishment) VALUES (?, ?, ?)", (guild_id, event, self.default_punishment))
await db.commit()
if "Anti NSFW link" in selected_events:
exempt_roles, exempt_channels = await self.get_exempt_roles_channels(guild_id)
nsfw_keywords = ["porn", "xxx", "adult", "sex", "nsfw", "xnxx", "onlyfans", "brazzers", "xhamster", "xvideos", "pornhub", "redtube", "livejasmin", "youporn" , "tube8", "pornhat", "swxvid", "ixxx", "pornhat"]
try:
await interaction.guild.create_automod_rule(
name="Anti NSFW Links",
event_type=discord.AutoModRuleEventType.message_send,
trigger=discord.AutoModTrigger(
type=discord.AutoModRuleTriggerType.keyword,
keyword_filter=nsfw_keywords,
),
actions=[
discord.AutoModRuleAction(type=discord.AutoModRuleActionType.block_message),
],
enabled=True,
exempt_roles=exempt_roles,
exempt_channels=exempt_channels,
reason="Automod - Anti NSFW Link setup"
)
except discord.Forbidden:
pass
except discord.HTTPException as e:
print(f"Automod rule-create error: {e}")
enable_logging_button = discord.ui.Button(label="Enable Automod Logging", style=discord.ButtonStyle.success)
async def enable_logging_callback(interaction):
if interaction.user != ctx.author:
await interaction.response.send_message("You are not allowed to interact with this button.", ephemeral=True)
return
if not interaction.guild.me.guild_permissions.manage_channels:
await interaction.response.send_message("I do not have permission to create channels.", ephemeral=True)
return
overwrites = {
interaction.guild.default_role: discord.PermissionOverwrite(view_channel=False),
interaction.guild.me: discord.PermissionOverwrite(view_channel=True)
}
try:
for channel in interaction.guild.channels:
if channel.name == f"{BRAND_NAME.lower()}-automod":
await interaction.response.send_message(f"A logging channel with the name \"{BRAND_NAME.lower()}-automod\" already exists.", ephemeral=True)
return
log_channel = await interaction.guild.create_text_channel(f"{BRAND_NAME.lower()}-automod", overwrites=overwrites)
guild_id = interaction.guild.id
async with aiosqlite.connect("db/automod.db") as db:
await db.execute("INSERT OR REPLACE INTO automod_logging (guild_id, log_channel) VALUES (?, ?)", (guild_id, log_channel.id))
await db.commit()
await interaction.response.send_message(f"Logging channel {log_channel.mention} created and set successfully.", ephemeral=True)
except discord.HTTPException as e:
await interaction.response.send_message(f"Failed to create logging channel: {e}", ephemeral=True)
enable_logging_button.callback = enable_logging_callback
events_text = "\n".join([f"{ENABLE} : {event}" for event in selected_events] + [f"{CROSS}{TICK} : {event}" for event in ["Anti spam", "Anti caps", "Anti link", "Anti invites", "Anti mass mention", "Anti emoji spam", "Anti NSFW link"] if event not in selected_events])
view = ShowRules(ctx.author, selected_events, "Automod Enabled Successfully", events_text)
await interaction.edit_original_response(content=None, view=view)
@automod.command(name="punishment", aliases=["punish"], help="Set the punishment for automod events.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def punishment(self, ctx):
guild_id = ctx.guild.id
if ctx.author != ctx.guild.owner and ctx.author.top_role.position < ctx.guild.me.top_role.position:
await ctx.send(view=CV2(f"{CROSS} Access Denied", "Your top role must be at the **same** position or **higher** than my top role."))
return
if not await self.is_automod_enabled(guild_id):
await ctx.send(view=CV2(f"Automod Settings for {ctx.guild.name}", f"Uhh, looks like your server hasn\'t enabled Automoderation.\n\nCurrent Status: {DISABLE} Disabled\nTo Enable use `{ctx.prefix}automod enable`"))
return
current_punishments = await self.get_current_punishments(guild_id)
punishments_list = "\n".join([f"**{event}**: {punishment or 'None'}" for event, punishment in current_punishments])
view_title = f"Current Automod Punishments for {ctx.guild.name}"
view_desc = punishments_list + "\n\nKeep the default punishment (Mute) to prevent server raids without kicking or banning raiders"
events = [event for event, _ in current_punishments]
select = discord.ui.Select(placeholder="Select events to update punishment", options=[
discord.SelectOption(label=event) for event in events
], min_values=1, max_values=len(events))
async def select_callback(interaction):
if interaction.user != ctx.author:
await interaction.response.send_message("You cannot interact with this menu.", ephemeral=True)
return
selected_events = select.values
await interaction.response.send_message("You selected: " + ", ".join(selected_events))
punishment_buttons = discord.ui.View()
for punishment in ["Mute", "Kick", "Ban"]:
button = discord.ui.Button(label=punishment, style=discord.ButtonStyle.danger)
async def punishment_callback(button_interaction, selected_events=selected_events, punishment=punishment):
if button_interaction.user != ctx.author:
await button_interaction.response.send_message("You cannot interact with this button.", ephemeral=True)
return
for event in selected_events:
await self.update_punishments(guild_id, event, punishment)
updated_punishments = await self.get_current_punishments(guild_id)
updated_list = "\n".join([f"**{event}**: {punishment or 'None'}" for event, punishment in updated_punishments])
await button_interaction.response.edit_message(view=CV2(f"Updated Automod Punishments for {ctx.guild.name}", updated_list, "You can modify the punishments by running the command again."))
button.callback = punishment_callback
punishment_buttons.add_item(button)
await interaction.edit_original_response(view=punishment_buttons)
select.callback = select_callback
view = CV2(view_title, view_desc)
view.add_item(select)
await ctx.send(view=view)
@automod.group(name="ignore", aliases=["exempt", "whitelist", "wl"], help="Manage whitelisted roles and channels for Automod.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 4, commands.BucketType.user)
async def ignore(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@ignore.command(name="channel", help="Add a channel to the whitelist.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def ignore_channel(self, ctx, channel: discord.TextChannel):
guild_id = ctx.guild.id
if ctx.author != ctx.guild.owner and ctx.author.top_role.position < ctx.guild.me.top_role.position:
await ctx.send(view=CV2(f"{CROSS} Access Denied", "Your top role must be at the **same** position or **higher** than my top role."))
return
if not await self.is_automod_enabled(guild_id):
await ctx.send(view=CV2(f"Automod Settings for {ctx.guild.name}", f"Uhh, looks like your server hasn\'t enabled Automoderation.\n\nCurrent Status: {DISABLE} Disabled\nTo Enable use `{ctx.prefix}automod enable`"))
return
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT 1 FROM automod_ignored WHERE guild_id = ? AND type = 'channel' AND id = ?", (guild_id, channel.id))
if await cursor.fetchone() is not None:
await ctx.send(view=CV2("__Channel Already Whitelisted!__", f"{CROSS} The channel {channel.mention} is already in the ignore list.\n\n➜ Use **{ctx.prefix}automod unignore channel {channel.mention}** to remove it."))
return
count_cursor = await db.execute("SELECT COUNT(*) FROM automod_ignored WHERE guild_id = ? AND type = 'channel'", (guild_id,))
count = await count_cursor.fetchone()
if count[0] >= 10:
await ctx.send("You can only ignore up to 10 channels.")
return
await db.execute("INSERT OR REPLACE INTO automod_ignored (guild_id, type, id) VALUES (?, 'channel', ?)", (guild_id, channel.id))
await db.commit()
if await self.is_anti_nsfw_enabled(guild_id):
try:
rules = await ctx.guild.fetch_automod_rules()
for rule in rules:
if rule.name == "Anti NSFW Links":
exempt_channels = list(rule.exempt_channels)
exempt_channels.append(channel)
await rule.edit(
exempt_channels=exempt_channels,
reason="Channel exempted from Anti NSFW Links via automod ignore command"
)
break
except discord.HTTPException:
pass
await ctx.send(view=CV2(f"{TICK} Channel Whitelisted", f"The channel {channel.mention} has been added to the ignore list \n\n➜ Use `{ctx.prefix}automod ignore show` to view the ignore list."))
@ignore.command(name="role", help="Add a role to the whitelist.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def ignore_role(self, ctx, role: discord.Role):
guild_id = ctx.guild.id
if ctx.author != ctx.guild.owner and ctx.author.top_role.position < ctx.guild.me.top_role.position:
await ctx.send(view=CV2(f"{CROSS} Access Denied", "Your top role must be at the **same** position or **higher** than my top role."))
return
if not await self.is_automod_enabled(guild_id):
await ctx.send(view=CV2(f"Automod Settings for {ctx.guild.name}", f"Uhh, looks like your server hasn\'t enabled Automoderation.\n\nCurrent Status: {DISABLE} Disabled\nTo Enable use `{ctx.prefix}automod enable`"))
return
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT 1 FROM automod_ignored WHERE guild_id = ? AND type = 'role' AND id = ?", (guild_id, role.id))
if await cursor.fetchone() is not None:
await ctx.send(view=CV2("__Role Already Whitelisted!__", f"{CROSS} The role {role.mention} is already in the ignore list.\n\n➜ Use **{ctx.prefix}automod unignore role {role.mention}** to remove it."))
return
count_cursor = await db.execute("SELECT COUNT(*) FROM automod_ignored WHERE guild_id = ? AND type = 'role'", (guild_id,))
count = await count_cursor.fetchone()
if count[0] >= 10:
await ctx.send("You can only ignore up to 10 roles.")
return
await db.execute("INSERT OR REPLACE INTO automod_ignored (guild_id, type, id) VALUES (?, 'role', ?)", (guild_id, role.id))
await db.commit()
if await self.is_anti_nsfw_enabled(guild_id):
try:
rules = await ctx.guild.fetch_automod_rules()
for rule in rules:
if rule.name == "Anti NSFW Links":
exempt_roles = list(rule.exempt_roles)
exempt_roles.append(role)
await rule.edit(
exempt_roles=exempt_roles,
reason="Role exempted from Anti NSFW Links via automod ignore command"
)
break
except discord.HTTPException:
pass
await ctx.send(view=CV2(f"{TICK} Role Whitelisted", f"The role {role.mention} has been added to the ignore list \n\n➜ Use `{ctx.prefix}automod ignore show` to view the ignore list."))
@ignore.command(name="show", aliases=["view", "list", "config"], help="Show the whitelisted roles and channels.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def ignore_show(self, ctx):
guild_id = ctx.guild.id
if ctx.author != ctx.guild.owner and ctx.author.top_role.position < ctx.guild.me.top_role.position:
await ctx.send(view=CV2(f"{CROSS} Access Denied", "Your top role must be at the **same** position or **higher** than my top role."))
return
if not await self.is_automod_enabled(guild_id):
await ctx.send(view=CV2(f"Automod Settings for {ctx.guild.name}", f"Uhh, looks like your server hasn\'t enabled Automoderation.\n\nCurrent Status: {DISABLE} Disabled\nTo Enable use `{ctx.prefix}automod enable`"))
return
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT type, id FROM automod_ignored WHERE guild_id = ?", (guild_id,))
ignored_items = await cursor.fetchall()
if not ignored_items:
await ctx.reply("No ignored channels or roles found.")
return
ignored_channels = []
ignored_roles = []
for item_type, item_id in ignored_items:
if item_type == "channel":
channel = ctx.guild.get_channel(item_id)
if channel:
ignored_channels.append(f"{channel.mention} (ID: {channel.id})")
else:
ignored_channels.append(f"Deleted Channel (ID: {item_id})")
elif item_type == "role":
role = ctx.guild.get_role(item_id)
if role:
ignored_roles.append(f"{role.mention} (ID: {role.id})")
else:
ignored_roles.append(f"Deleted Role (ID: {item_id})")
ch_str = "\n".join(ignored_channels) if ignored_channels else "None"
rl_str = "\n".join(ignored_roles) if ignored_roles else "None"
await ctx.send(view=CV2("Ignored Channels & Roles for Automod", f"__Ignored Channels:__\n{ch_str}", f"__Ignored Roles:__\n{rl_str}"))
@ignore.command(name="reset", help="Reset the whitelist.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def ignore_reset(self, ctx):
guild_id = ctx.guild.id
if ctx.author != ctx.guild.owner and ctx.author.top_role.position < ctx.guild.me.top_role.position:
await ctx.send(view=CV2(f"{CROSS} Access Denied", "Your top role must be at the **same** position or **higher** than my top role."))
return
if not await self.is_automod_enabled(guild_id):
await ctx.send(view=CV2(f"Automod Settings for {ctx.guild.name}", f"Uhh, looks like your server hasn\'t enabled Automoderation.\n\nCurrent Status: {DISABLE} Disabled\nTo Enable use `{ctx.prefix}automod enable`"))
return
async with aiosqlite.connect("db/automod.db") as db:
await db.execute("DELETE FROM automod_ignored WHERE guild_id = ?", (guild_id,))
await db.commit()
await ctx.send(view=CV2(f"Automod Settings for {ctx.guild.name}", f"** {TICK} | All ignored channels and roles have been reset!**\n\nTo view current Automod settings use `{ctx.prefix}automod config`"))
@automod.group(name="unignore", aliases=["unwhitelist", "unwl"], invoke_without_command=True, help="Remove channels and roles from the whitelist.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
async def unignore(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@unignore.command(name="channel", help="Remove a channel from the whitelist.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def unignore_channel(self, ctx, channel: discord.TextChannel):
guild_id = ctx.guild.id
if ctx.author != ctx.guild.owner and ctx.author.top_role.position < ctx.guild.me.top_role.position:
await ctx.send(view=CV2(f"{CROSS} Access Denied", "Your top role must be at the **same** position or **higher** than my top role."))
return
if not await self.is_automod_enabled(guild_id):
await ctx.send(view=CV2(f"Automod Settings for {ctx.guild.name}", f"Uhh, looks like your server hasn\'t enabled Automoderation.\n\nCurrent Status: {DISABLE} Disabled\nTo Enable use `{ctx.prefix}automod enable`"))
return
if await self.is_anti_nsfw_enabled(guild_id):
try:
rules = await ctx.guild.fetch_automod_rules()
for rule in rules:
if rule.name == "Anti NSFW Links":
exempt_channels = list(rule.exempt_channels)
exempt_channels = [ch for ch in exempt_channels if ch.id != channel.id]
await rule.edit(
exempt_channels=exempt_channels,
reason="Channel removed from Anti NSFW Links exemption via automod unignore command"
)
break
except discord.HTTPException:
pass
async with aiosqlite.connect("db/automod.db") as db:
result = await db.execute("DELETE FROM automod_ignored WHERE guild_id = ? AND type = 'channel' AND id = ?", (guild_id, channel.id))
await db.commit()
if result.rowcount > 0:
await ctx.send(view=CV2(f"{TICK} Success", f"{channel.mention} has been removed from the automod ignore list."))
else:
await ctx.send(view=CV2(f"{CROSS} Error", f"{channel.mention} is not in the automod ignore list."))
@unignore.command(name="role", help="Remove a role from the whitelist.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def unignore_role(self, ctx, role: discord.Role):
guild_id = ctx.guild.id
if ctx.author != ctx.guild.owner and ctx.author.top_role.position < ctx.guild.me.top_role.position:
await ctx.send(view=CV2(f"{CROSS} Access Denied", "Your top role must be at the **same** position or **higher** than my top role."))
return
if not await self.is_automod_enabled(guild_id):
await ctx.send(view=CV2(f"Automod Settings for {ctx.guild.name}", f"Uhh, looks like your server hasn\'t enabled Automoderation.\n\nCurrent Status: {DISABLE} Disabled\nTo Enable use `{ctx.prefix}automod enable`"))
return
if await self.is_anti_nsfw_enabled(guild_id):
try:
rules = await ctx.guild.fetch_automod_rules()
for rule in rules:
if rule.name == "Anti NSFW Links":
exempt_roles = list(rule.exempt_roles)
exempt_roles = [ch for ch in exempt_roles if ch.id != role.id]
await rule.edit(
exempt_roles=exempt_roles,
reason="Role removed from Anti NSFW Links exemption via automod unignore command"
)
break
except discord.HTTPException:
pass
async with aiosqlite.connect("db/automod.db") as db:
result = await db.execute("DELETE FROM automod_ignored WHERE guild_id = ? AND type = 'role' AND id = ?", (guild_id, role.id))
await db.commit()
if result.rowcount > 0:
await ctx.send(view=CV2(f"{TICK} Success", f"{role.mention} has been removed from the automod ignore list."))
else:
await ctx.send(view=CV2(f"{CROSS} Error", f"{role.mention} is not in the automod ignore list."))
@automod.command(name="disable", help="Disable Automod in the server.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def disable(self, ctx):
guild_id = ctx.guild.id
if ctx.author != ctx.guild.owner and ctx.author.top_role.position < ctx.guild.me.top_role.position:
await ctx.send(view=CV2(f"{CROSS} Access Denied", "Your top role must be at the **same** position or **higher** than my top role."))
return
if not await self.is_automod_enabled(guild_id):
await ctx.send(view=CV2(f"Automod Settings for {ctx.guild.name}", f"Uhh, looks like your server hasn\'t enabled Automoderation.\n\nCurrent Status: {DISABLE} Disabled\nTo Enable use `{ctx.prefix}automod enable`"))
return
view = ConfirmDisable(ctx.author, "Disable Automod Confirmation", "**Are you sure you want to disable Automod?**\n\nThis will remove all custom event settings, punishments, ignored roles/channels, & logging channel data.", "Click 'Yes' to disable Automod or 'No' to cancel.")
message = await ctx.send(view=view)
await view.wait()
if view.value is None:
await message.edit(view=CV2("Automod Disable Cancelled", "You took too long to respond. Automod disable process has been canceled."))
elif view.value:
async with aiosqlite.connect("db/automod.db") as db:
await db.execute("DELETE FROM automod WHERE guild_id = ?", (guild_id,))
await db.execute("DELETE FROM automod_punishments WHERE guild_id = ?", (guild_id,))
await db.execute("DELETE FROM automod_ignored WHERE guild_id = ?", (guild_id,))
await db.execute("DELETE FROM automod_logging WHERE guild_id = ?", (guild_id,))
await db.commit()
rules = await ctx.guild.fetch_automod_rules()
for rule in rules:
if rule.name == "Anti NSFW Links":
try:
await rule.delete(reason="Automod disabled - removing Anti NSFW Link rule")
except discord.Forbidden:
pass
except discord.HTTPException:
pass
await message.edit(view=CV2(f"{TICK_ALT} Automod Disabled", f"Automod has been successfully disabled for **{ctx.guild.name}.** \nAll settings, punishments, and logs have been removed.\n\nCurrent Status: {DISABLE} Disabled\n➜ To Re-enable use `{ctx.prefix}automod enable`."))
else:
await message.edit(view=CV2("Automod Disable Cancelled", "Automod disable process has been canceled."))
@automod.command(name="config", aliases=["settings", "show", "view"], help="View Automod settings.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def config(self, ctx):
guild_id = ctx.guild.id
if ctx.author != ctx.guild.owner and ctx.author.top_role.position < ctx.guild.me.top_role.position:
await ctx.send(view=CV2(f"{CROSS} Access Denied", "Your top role must be at the **same** position or **higher** than my top role."))
return
if not await self.is_automod_enabled(guild_id):
await ctx.send(view=CV2(f"Automod Settings for {ctx.guild.name}", f"Uhh, looks like your server hasn\'t enabled Automoderation.\n\nCurrent Status: {DISABLE} Disabled\nTo Enable use `{ctx.prefix}automod enable`"))
return
current_punishments = await self.get_current_punishments(guild_id)
items_str = []
for event, punishment in current_punishments:
items_str.append(f"**{event}**: {punishment or 'None'}")
if await self.is_anti_nsfw_enabled(guild_id):
items_str.append("**Anti NSFW Links**: Block Message")
async with aiosqlite.connect("db/automod.db") as db:
cursor = await db.execute("SELECT log_channel FROM automod_logging WHERE guild_id = ?", (guild_id,))
log_channel_id = await cursor.fetchone()
if log_channel_id and log_channel_id[0]:
log_channel = ctx.guild.get_channel(log_channel_id[0])
if log_channel:
items_str.append(f"**Logging Channel**: {log_channel.mention}")
else:
items_str.append("**Logging Channel**: Deleted Channel")
else:
items_str.append("**Logging Channel**: No logging channel")
await ctx.send(view=CV2(f"Enabled Automod Events & their punishment type for {ctx.guild.name}", "\n".join(items_str), "Manage punishment type for events by executing `automod punishment` command."))
@automod.command(name="logging", help="Set the logging channel for Automod events.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def logging(self, ctx, channel: discord.TextChannel):
guild_id = ctx.guild.id
if ctx.author != ctx.guild.owner and ctx.author.top_role.position < ctx.guild.me.top_role.position:
await ctx.send(view=CV2(f"{CROSS} Access Denied", "Your top role must be at the **same** position or **higher** than my top role."))
return
if not await self.is_automod_enabled(guild_id):
await ctx.send(view=CV2(f"Automod Settings for {ctx.guild.name}", f"Uhh, looks like your server hasn\'t enabled Automoderation.\n\nCurrent Status: {DISABLE} Disabled\nTo Enable use `{ctx.prefix}automod enable`"))
return
async with aiosqlite.connect("db/automod.db") as db:
await db.execute("INSERT OR REPLACE INTO automod_logging (guild_id, log_channel) VALUES (?, ?)", (guild_id, channel.id))
await db.commit()
await ctx.send(view=CV2(f"Automod Settings for {ctx.guild.name}", f"**{TICK} | Automoderation Logging channel set to {channel.mention}.**\n\n➜ Use `{ctx.prefix}automod config` to view current Automod settings."))
@commands.Cog.listener()
async def on_guild_remove(self, guild):
guild_id = guild.id
async with aiosqlite.connect("db/automod.db") as db:
await db.execute("DELETE FROM automod WHERE guild_id = ?", (guild_id,))
await db.execute("DELETE FROM automod_punishments WHERE guild_id = ?", (guild_id,))
await db.execute("DELETE FROM automod_ignored WHERE guild_id = ?", (guild_id,))
await db.execute("DELETE FROM automod_logging WHERE guild_id = ?", (guild_id,))
await db.commit()

View File

@@ -0,0 +1,159 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import CROSS, ICONS_WARNING, TICK
from discord.ext import commands
from discord.ui import LayoutView, TextDisplay, Separator, Container
import aiosqlite
import re
from utils.Tools import *
from utils.cv2 import CV2, build_container
class AutoReaction(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.db_path = 'db/autoreact.db'
self.bot.loop.create_task(self.setup_database())
async def setup_database(self):
async with aiosqlite.connect(self.db_path) as db:
await db.execute("""
CREATE TABLE IF NOT EXISTS autoreact (
guild_id INTEGER,
trigger TEXT,
emojis TEXT
)
""")
await db.commit()
async def get_triggers(self, guild_id):
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute("SELECT trigger, emojis FROM autoreact WHERE guild_id = ?", (guild_id,))
return await cursor.fetchall()
async def trigger_exists(self, guild_id, trigger):
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute("SELECT 1 FROM autoreact WHERE guild_id = ? AND trigger = ?", (guild_id, trigger))
return await cursor.fetchone()
@commands.group(name="react", aliases=["autoreact"], help="Lists all subcommands of autoreact group.", invoke_without_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 4, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def react(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@react.command(name="add", aliases=["set", "create"], help="Adds a trigger and its emojis to the autoreact.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 4, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def add(self, ctx, trigger: str, *, emojis: str):
if len(trigger.split()) > 1:
view = CV2(f"{CROSS} Invalid Trigger", "Triggers can only be one word.")
return await ctx.reply(view=view)
emoji_list = re.findall(r"<a?:\w+:\d+>|[\u263a-\U0001f645]", emojis)
if len(emoji_list) > 10:
view = CV2(f"{CROSS} Too Many Emojis", "You can only set up to **10** emojis per trigger.")
return await ctx.reply(view=view)
triggers = await self.get_triggers(ctx.guild.id)
if len(triggers) >= 10:
view = CV2(f"{ICONS_WARNING} Trigger Limit Reached", "You can only set up to 10 triggers for auto-reactions in this guild.")
return await ctx.reply(view=view)
if await self.trigger_exists(ctx.guild.id, trigger):
view = CV2(f"{ICONS_WARNING} Trigger Exists", f"The trigger '{trigger}' already exists. Remove it before adding it again.")
return await ctx.reply(view=view)
async with aiosqlite.connect(self.db_path) as db:
await db.execute("INSERT INTO autoreact (guild_id, trigger, emojis) VALUES (?, ?, ?)",
(ctx.guild.id, trigger, " ".join(emoji_list)))
await db.commit()
view = CV2(f"{TICK} Trigger Added", f"Successfully added trigger '{trigger}' with emojis {', '.join(emoji_list)}.")
await ctx.reply(view=view)
@react.command(name="remove", aliases=["clear", "delete"], help="Removes a trigger and its emojis from the autoreact.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 4, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def remove(self, ctx, trigger: str):
if not await self.trigger_exists(ctx.guild.id, trigger):
view = CV2(f"{CROSS} Trigger Not Found", f"The trigger '{trigger}' does not exist.")
return await ctx.reply(view=view)
async with aiosqlite.connect(self.db_path) as db:
await db.execute("DELETE FROM autoreact WHERE guild_id = ? AND trigger = ?", (ctx.guild.id, trigger))
await db.commit()
view = CV2(f"{TICK} Trigger Removed", f"Successfully removed trigger '{trigger}'.")
await ctx.reply(view=view)
@react.command(name="list", aliases=["show", "config"], help="Lists all the triggers and their emojis in the autoreact module.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 4, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def list(self, ctx):
triggers = await self.get_triggers(ctx.guild.id)
if not triggers:
view = CV2("No Triggers Set", "There are no auto-reaction triggers set in this guild.")
return await ctx.reply(view=view)
trigger_list = "\n".join([f"**{t[0]}:** {t[1]}" for t in triggers])
view = CV2("Auto-Reaction Triggers", trigger_list)
await ctx.reply(view=view)
@react.command(name="reset", help="Resets all the triggers and their emojis in the autoreact module.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 4, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def reset(self, ctx):
triggers = await self.get_triggers(ctx.guild.id)
if not triggers:
view = CV2(f"{CROSS} No Triggers Set", "There are no auto-reaction triggers set to reset.")
return await ctx.reply(view=view)
async with aiosqlite.connect(self.db_path) as db:
await db.execute("DELETE FROM autoreact WHERE guild_id = ?", (ctx.guild.id,))
await db.commit()
view = CV2(f"{TICK} All Triggers Reset", "Successfully removed all auto-reaction triggers.")
await ctx.reply(view=view)
async def setup(bot):
await bot.add_cog(AutoReaction(bot))

View File

@@ -0,0 +1,149 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import CROSS, TICK
from discord.ext import commands
from discord.ui import LayoutView, TextDisplay, Separator, Container
import aiosqlite
import os
from utils.Tools import *
from utils.cv2 import CV2, build_container
DB_PATH = "db/autoresponder.db"
class AutoResponder(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.bot.loop.create_task(self.initialize_db())
async def initialize_db(self):
if not os.path.exists(os.path.dirname(DB_PATH)):
os.makedirs(os.path.dirname(DB_PATH))
async with aiosqlite.connect(DB_PATH) as db:
await db.execute('''
CREATE TABLE IF NOT EXISTS autoresponses (
guild_id INTEGER,
name TEXT,
message TEXT,
PRIMARY KEY (guild_id, name)
)
''')
await db.commit()
@commands.group(name="autoresponder", invoke_without_command=True, aliases=['ar'], help="Manage autoresponders in the server.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
async def _ar(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@_ar.command(name="create", help="Create a new autoresponder.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def _create(self, ctx, name, *, message):
name_lower = name.lower()
async with aiosqlite.connect(DB_PATH) as db:
async with db.execute("SELECT COUNT(*) FROM autoresponses WHERE guild_id = ?", (ctx.guild.id,)) as cursor:
count = (await cursor.fetchone())[0]
if count >= 20:
view = CV2(f"{CROSS} Error!", f"You can't add more than 20 autoresponses in {ctx.guild.name}")
return await ctx.reply(view=view)
async with db.execute("SELECT 1 FROM autoresponses WHERE guild_id = ? AND LOWER(name) = ?", (ctx.guild.id, name_lower)) as cursor:
if await cursor.fetchone():
view = CV2(f"{CROSS} Error!", f"The autoresponse with the name `{name}` already exists in {ctx.guild.name}")
return await ctx.reply(view=view)
await db.execute("INSERT INTO autoresponses (guild_id, name, message) VALUES (?, ?, ?)", (ctx.guild.id, name_lower, message))
await db.commit()
view = CV2(f"{TICK} Success", f"Created autoresponder `{name}` in {ctx.guild.name}")
await ctx.reply(view=view)
@_ar.command(name="delete", help="Delete an existing autoresponder.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def _delete(self, ctx, name):
name_lower = name.lower()
async with aiosqlite.connect(DB_PATH) as db:
async with db.execute("SELECT 1 FROM autoresponses WHERE guild_id = ? AND LOWER(name) = ?", (ctx.guild.id, name_lower)) as cursor:
if not await cursor.fetchone():
view = CV2(f"{CROSS} Error!", f"No autoresponder found with the name `{name}` in {ctx.guild.name}")
return await ctx.reply(view=view)
await db.execute("DELETE FROM autoresponses WHERE guild_id = ? AND LOWER(name) = ?", (ctx.guild.id, name_lower))
await db.commit()
view = CV2(f"{TICK} Success", f"Deleted autoresponder `{name}` in {ctx.guild.name}")
await ctx.reply(view=view)
@_ar.command(name="edit", help="Edit an existing autoresponder.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def _edit(self, ctx, name, *, message):
name_lower = name.lower()
async with aiosqlite.connect(DB_PATH) as db:
async with db.execute("SELECT 1 FROM autoresponses WHERE guild_id = ? AND LOWER(name) = ?", (ctx.guild.id, name_lower)) as cursor:
if not await cursor.fetchone():
view = CV2(f"{CROSS} Error!", f"No autoresponder found with the name `{name}` in {ctx.guild.name}")
return await ctx.reply(view=view)
await db.execute("UPDATE autoresponses SET message = ? WHERE guild_id = ? AND LOWER(name) = ?", (message, ctx.guild.id, name_lower))
await db.commit()
view = CV2(f"{TICK} Success", f"Edited autoresponder `{name}` in {ctx.guild.name}")
await ctx.reply(view=view)
@_ar.command(name="config", help="List all autoresponders in the server.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def _config(self, ctx):
async with aiosqlite.connect(DB_PATH) as db:
async with db.execute("SELECT name FROM autoresponses WHERE guild_id = ?", (ctx.guild.id,)) as cursor:
autoresponses = await cursor.fetchall()
if not autoresponses:
view = CV2("No Autoresponders", f"There are no autoresponders in {ctx.guild.name}")
return await ctx.reply(view=view)
ar_list = "\n".join([f"**[{i}]** {name}" for i, (name,) in enumerate(autoresponses, start=1)])
view = CV2(f"Autoresponders in {ctx.guild.name}", ar_list)
await ctx.send(view=view)
@commands.Cog.listener()
async def on_message(self, message):
if message.author == self.bot.user:
return
async with aiosqlite.connect(DB_PATH) as db:
async with db.execute("SELECT message FROM autoresponses WHERE guild_id = ? AND LOWER(name) = ?", (message.guild.id, message.content.lower())) as cursor:
row = await cursor.fetchone()
if row:
await message.channel.send(row[0])
async def setup(bot):
await bot.add_cog(AutoResponder(bot))

View File

@@ -0,0 +1,354 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
from __future__ import annotations
import discord
from utils.emoji import CROSS, ICONS_WARNING, TICK
import aiosqlite
import logging
from discord.ext import commands
from typing import List, Dict
from discord.ui import LayoutView, TextDisplay, Separator, Container
from utils.Tools import *
from utils.cv2 import CV2, build_container
from utils.config import OWNER_IDS
from utils.safe_parse import parse_role_id_list, dump_role_id_list
logging.basicConfig(
level=logging.INFO,
format="\x1b[38;5;197m[\x1b[0m%(asctime)s\x1b[38;5;197m]\x1b[0m -> \x1b[38;5;197m%(message)s\x1b[0m",
datefmt="%H:%M:%S",
)
DATABASE_PATH = 'db/autorole.db'
class BasicView(discord.ui.View):
def __init__(self, ctx: commands.Context, timeout=60):
super().__init__(timeout=timeout)
self.ctx = ctx
async def interaction_check(self, interaction: discord.Interaction):
if interaction.user.id != self.ctx.author.id and interaction.user.id not in OWNER_IDS:
await interaction.response.send_message("Uh oh! That message doesn't belong to you.\nYou must run this command to interact with it.", ephemeral=True)
return False
return True
class AutoRole(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.bot.loop.create_task(self.create_table())
self.color = 0xFF0000
async def create_table(self):
async with aiosqlite.connect(DATABASE_PATH) as db:
await db.execute("""
CREATE TABLE IF NOT EXISTS autorole (
guild_id INTEGER PRIMARY KEY,
bots TEXT NOT NULL,
humans TEXT NOT NULL
)
""")
await db.commit()
async def get_autorole(self, guild_id: int) -> Dict[str, List[int]]:
async with aiosqlite.connect(DATABASE_PATH) as db:
async with db.execute("SELECT bots, humans FROM autorole WHERE guild_id = ?", (guild_id,)) as cursor:
row = await cursor.fetchone()
if row:
bots, humans = row
bots = [int(role_id) for role_id in bots.replace('[', '').replace(']', '').replace(' ', '').split(',') if role_id]
humans = [int(role_id) for role_id in humans.replace('[', '').replace(']', '').replace(' ', '').split(',') if role_id]
return {"bots": bots, "humans": humans}
else:
return {"bots": [], "humans": []}
async def update_autorole(self, guild_id: int, data: Dict[str, List[int]]):
async with aiosqlite.connect(DATABASE_PATH) as db:
bots = ','.join(map(str, data['bots']))
humans = ','.join(map(str, data['humans']))
await db.execute("INSERT OR REPLACE INTO autorole (guild_id, bots, humans) VALUES (?, ?, ?)",
(guild_id, bots, humans))
await db.commit()
@commands.group(name="autorole", invoke_without_command=True)
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def _autorole(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@_autorole.command(name="config", help="Shows the current autorole configuration")
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def _ar_config(self, ctx):
data = await self.get_autorole(ctx.guild.id)
if data:
fetched_humans = [ctx.guild.get_role(role_id) for role_id in data["humans"] if ctx.guild.get_role(role_id)]
fetched_bots = [ctx.guild.get_role(role_id) for role_id in data["bots"] if ctx.guild.get_role(role_id)]
hums = "\n".join(role.mention for role in fetched_humans) or "None"
bos = "\n".join(role.mention for role in fetched_bots) or "None"
view = CV2(
f"Autorole Configuration for {ctx.guild.name}",
f"__Humans__\n{hums}",
f"__Bots__\n{bos}"
)
await ctx.send(view=view)
else:
view = CV2("Autorole Configuration", "No autorole configuration found in this Guild.")
await ctx.reply(view=view)
@_autorole.group(name="reset", help="Clear autorole config in the Guild")
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def _autorole_reset(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@_autorole_reset.command(name="humans", help="Clear autorole configuration for humans")
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def _autorole_humans_reset(self, ctx):
async with aiosqlite.connect(DATABASE_PATH) as db:
async with db.execute("SELECT humans FROM autorole WHERE guild_id = ?", (ctx.guild.id,)) as cursor:
data = await cursor.fetchone()
if data and data[0]:
async with aiosqlite.connect(DATABASE_PATH) as db:
await db.execute("UPDATE autorole SET humans = ? WHERE guild_id = ?", ('[]', ctx.guild.id))
await db.commit()
view = CV2(f"{TICK} Success", "Cleared all human autoroles in this Guild.")
else:
view = CV2(f"{CROSS} Error", "No Autoroles set for humans in this Guild.")
await ctx.reply(view=view)
@_autorole_reset.command(name="bots", help="Clear autorole configuration for bots")
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def _autorole_bots_reset(self, ctx):
async with aiosqlite.connect(DATABASE_PATH) as db:
async with db.execute("SELECT bots FROM autorole WHERE guild_id = ?", (ctx.guild.id,)) as cursor:
data = await cursor.fetchone()
if data and data[0]:
async with aiosqlite.connect(DATABASE_PATH) as db:
await db.execute("UPDATE autorole SET bots = ? WHERE guild_id = ?", ('[]', ctx.guild.id))
await db.commit()
view = CV2(f"{TICK} Success", "Cleared all bot autoroles in this Guild.")
else:
view = CV2(f"{CROSS} Error", "No Autoroles set for Bots in this Guild.")
await ctx.reply(view=view)
@_autorole_reset.command(name="all", help="Clear all autorole configuration in the Guild")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def _autorole_reset_all(self, ctx):
async with aiosqlite.connect(DATABASE_PATH) as db:
async with db.execute("SELECT humans, bots FROM autorole WHERE guild_id = ?", (ctx.guild.id,)) as cursor:
data = await cursor.fetchone()
if data and (data[0] or data[1]):
async with aiosqlite.connect(DATABASE_PATH) as db:
await db.execute("UPDATE autorole SET humans = ?, bots = ? WHERE guild_id = ?", ('[]', '[]', ctx.guild.id))
await db.commit()
view = CV2(f"{TICK} Success", "Cleared all autoroles in this Gudild.")
else:
view = CV2(f"{CROSS} Error", "No Autoroles set in this Guild.")
await ctx.reply(view=view)
@_autorole.group(name="humans", help="Setup autoroles for human")
@blacklist_check()
@ignore_check()
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def _autorole_humans(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@_autorole_humans.command(name="add", help="Add role to list of human Autoroles.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def _autorole_humans_add(self, ctx, *, role: discord.Role):
async with aiosqlite.connect(DATABASE_PATH) as db:
async with db.execute("SELECT humans FROM autorole WHERE guild_id = ?", (ctx.guild.id,)) as cursor:
data = await cursor.fetchone()
if data:
humans = parse_role_id_list(data[0])
if role.id in humans:
view = CV2(f"{ICONS_WARNING} Access Denied", f"{role.mention} is already in human autoroles.")
elif len(humans) >= 10:
view = CV2(f"{ICONS_WARNING} Access Denied", "You can only add upto 10 human autoroles.")
else:
humans.append(role.id)
async with aiosqlite.connect(DATABASE_PATH) as db:
await db.execute("UPDATE autorole SET humans = ? WHERE guild_id = ?", (dump_role_id_list(humans), ctx.guild.id))
await db.commit()
view = CV2(f"{TICK} Success", f"{role.mention} has been added to human autoroles.")
else:
humans = [role.id]
async with aiosqlite.connect(DATABASE_PATH) as db:
await db.execute("INSERT INTO autorole (guild_id, humans, bots) VALUES (?, ?, ?)", (ctx.guild.id, dump_role_id_list(humans), '[]'))
await db.commit()
view = CV2(f"{TICK} Success", f"{role.mention} has been added to human autoroles.")
await ctx.reply(view=view)
@_autorole_humans.command(name="remove", help="Remove a role from human Autoroles.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def _autorole_humans_remove(self, ctx, *, role: discord.Role):
async with aiosqlite.connect(DATABASE_PATH) as db:
async with db.execute("SELECT humans FROM autorole WHERE guild_id = ?", (ctx.guild.id,)) as cursor:
data = await cursor.fetchone()
if data:
humans = parse_role_id_list(data[0])
if role.id not in humans:
view = CV2(f"{CROSS} Error", f"{role.mention} is not in human autoroles.")
else:
humans.remove(role.id)
async with aiosqlite.connect(DATABASE_PATH) as db:
await db.execute("UPDATE autorole SET humans = ? WHERE guild_id = ?", (dump_role_id_list(humans), ctx.guild.id))
await db.commit()
view = CV2(f"{TICK} Success", f"{role.mention} has been removed from human autoroles.")
else:
view = CV2(f"{CROSS} Error", "No Autoroles set in this guild for humans.")
await ctx.reply(view=view)
@_autorole.group(name="bots", help="Setup autoroles for bots")
@blacklist_check()
@ignore_check()
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def _autorole_bots(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@_autorole_bots.command(name="add", help="Add role to bot Autoroles.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def _autorole_bots_add(self, ctx, *, role: discord.Role):
async with aiosqlite.connect(DATABASE_PATH) as db:
async with db.execute("SELECT bots FROM autorole WHERE guild_id = ?", (ctx.guild.id,)) as cursor:
data = await cursor.fetchone()
if data:
bots = parse_role_id_list(data[0])
if role.id in bots:
view = CV2(f"{ICONS_WARNING} Access Denied", f"{role.mention} is already in bot autoroles.")
elif len(bots) >= 10:
view = CV2(f"{ICONS_WARNING} Access Denied", "You can only add upto 10 bot autoroles")
else:
bots.append(role.id)
async with aiosqlite.connect(DATABASE_PATH) as db:
await db.execute("UPDATE autorole SET bots = ? WHERE guild_id = ?", (dump_role_id_list(bots), ctx.guild.id))
await db.commit()
view = CV2(f"{TICK} Success", f"{role.mention} has been added to bot autoroles.")
else:
bots = [role.id]
async with aiosqlite.connect(DATABASE_PATH) as db:
await db.execute("INSERT INTO autorole (guild_id, humans, bots) VALUES (?, ?, ?)", (ctx.guild.id, '[]', dump_role_id_list(bots)))
await db.commit()
view = CV2(f"{TICK} Success", f"{role.mention} has been added to bot autoroles.")
await ctx.reply(view=view)
@_autorole_bots.command(name="remove", help="Remove a role from bot Autoroles.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def _autorole_bots_remove(self, ctx, *, role: discord.Role):
async with aiosqlite.connect(DATABASE_PATH) as db:
async with db.execute("SELECT bots FROM autorole WHERE guild_id = ?", (ctx.guild.id,)) as cursor:
data = await cursor.fetchone()
if data:
bots = parse_role_id_list(data[0])
if role.id not in bots:
view = CV2(f"{CROSS} Error", f"{role.mention} is not in bot autoroles.")
else:
bots.remove(role.id)
async with aiosqlite.connect(DATABASE_PATH) as db:
await db.execute("UPDATE autorole SET bots = ? WHERE guild_id = ?", (dump_role_id_list(bots), ctx.guild.id))
await db.commit()
view = CV2(f"{TICK} Success", f"{role.mention} has been removed from bot autoroles.")
else:
view = CV2(f"{CROSS} Error", "No Autoroles set in this guild for bots.")
await ctx.reply(view=view)

View File

@@ -0,0 +1,243 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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 os
import random
from typing import List, Tuple, Union
from PIL import Image
from utils.Tools import *
from utils.cv2 import CV2, build_container
from discord.ui import LayoutView, TextDisplay, Separator, Container
class CV2(LayoutView):
def __init__(self, title, *sections):
super().__init__(timeout=None)
items = [TextDisplay(f"**{title}**")]
for s in sections:
if s:
items.append(Separator(visible=True))
items.append(TextDisplay(str(s)))
self.add_item(build_container(*items))
CARDS_PATH = 'data/cards/'
class Card:
suits = ["clubs", "diamonds", "hearts", "spades"]
def __init__(self, suit: str, value: int, down=False):
self.suit = suit
self.value = value
self.down = down
self.symbol = self.name[0].upper()
@property
def name(self) -> str:
if self.value <= 10:
return str(self.value)
else:
return {
11: 'jack',
12: 'queen',
13: 'king',
14: 'ace',
}[self.value]
@property
def image(self):
return (
f"{self.symbol if self.name != '10' else '10'}" \
f"{self.suit[0].upper()}.png" \
if not self.down else "red_back.png"
)
def flip(self):
self.down = not self.down
return self
def __str__(self) -> str:
return f'{self.name.title()} of {self.suit.title()}'
def __repr__(self) -> str:
return str(self)
class Blackjack(commands.Cog):
def __init__(self, bot):
self.bot = bot
@staticmethod
def hand_to_images(hand: List[Card]) -> List[Image.Image]:
return [Image.open(os.path.join(CARDS_PATH, card.image)) for card in hand]
@staticmethod
def center(*hands: Tuple[Image.Image]) -> Image.Image:
bg: Image.Image = Image.open(os.path.join(CARDS_PATH, 'table.png'))
bg_center_x = bg.size[0] // 2
bg_center_y = bg.size[1] // 2
img_w = hands[0][0].size[0]
img_h = hands[0][0].size[1]
start_y = bg_center_y - (((len(hands) * img_h) + ((len(hands) - 1) * 15)) // 2)
for hand in hands:
start_x = bg_center_x - (((len(hand) * img_w) + ((len(hand) - 1) * 10)) // 2)
for card in hand:
bg.alpha_composite(card, (start_x, start_y))
start_x += img_w + 10
start_y += img_h + 15
return bg
def output(self, name, *hands: Tuple[List[Card]]) -> None:
self.center(*map(self.hand_to_images, hands)).save(f'data/{name}.png')
@staticmethod
def calc_hand(hand: List[Card]) -> int:
non_aces = [c for c in hand if c.symbol != 'A']
aces = [c for c in hand if c.symbol == 'A']
total_sum = 0
for card in non_aces:
if not card.down:
if card.symbol in 'JQK':
total_sum += 10
else:
total_sum += card.value
for card in aces:
if not card.down:
if total_sum <= 10:
total_sum += 11
else:
total_sum += 1
return total_sum
@commands.command(aliases=['bj', 'blackjacks'], help="Play a simple game of blackjack.", usage="blackjack")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def blackjack(self, ctx: commands.Context):
try:
deck = [Card(suit, num) for num in range(2, 15) for suit in Card.suits]
random.shuffle(deck)
player_hand: List[Card] = []
dealer_hand: List[Card] = []
player_hand.append(deck.pop())
dealer_hand.append(deck.pop())
player_hand.append(deck.pop())
dealer_hand.append(deck.pop())
dealer_hand[1] = dealer_hand[1].flip()
player_score = self.calc_hand(player_hand)
dealer_score = self.calc_hand(dealer_hand)
async def out_table(**kwargs) -> discord.Message:
self.output(ctx.author.id, dealer_hand, player_hand)
file = discord.File(f"data/{ctx.author.id}.png", filename=f"{ctx.author.id}.png")
view = CV2(kwargs.get('title', 'Blackjack'), kwargs.get('description', ''))
msg: discord.Message = await ctx.send(file=file, view=view)
return msg
def check(reaction: discord.Reaction, user: Union[discord.Member, discord.User]) -> bool:
return all((
str(reaction.emoji) in ("🇸", "🇭"),
user == ctx.author,
user != self.bot.user,
reaction.message == msg
))
standing = False
while True:
player_score = self.calc_hand(player_hand)
dealer_score = self.calc_hand(dealer_hand)
if player_score == 21:
result = ("Blackjack!", 'won')
break
elif player_score > 21:
result = ("Player busts", 'lost')
break
msg = await out_table(
title="Your Turn",
description=f"Your hand: {player_score}\nDealer's hand: {dealer_score}"
)
await msg.add_reaction("🇭")
await msg.add_reaction("🇸")
try:
reaction, _ = await self.bot.wait_for('reaction_add', timeout=60, check=check)
except asyncio.TimeoutError:
await msg.delete()
return
if str(reaction.emoji) == "🇭":
player_hand.append(deck.pop())
await msg.delete()
continue
elif str(reaction.emoji) == "🇸":
standing = True
break
if standing:
dealer_hand[1] = dealer_hand[1].flip()
player_score = self.calc_hand(player_hand)
dealer_score = self.calc_hand(dealer_hand)
while dealer_score < 17:
dealer_hand.append(deck.pop())
dealer_score = self.calc_hand(dealer_hand)
if dealer_score == 21:
result = ('Dealer blackjack', 'lost')
elif dealer_score > 21:
result = ("Dealer busts", 'won')
elif dealer_score == player_score:
result = ("Tie!", 'kept')
elif dealer_score > player_score:
result = ("You lose!", 'lost')
elif dealer_score < player_score:
result = ("You win!", 'won')
color = (
discord.Color.red() if result[1] == 'lost'
else discord.Color.green() if result[1] == 'won'
else discord.Color.blue()
)
try:
await msg.delete()
except:
pass
msg = await out_table(
title=result[0],
color=color,
description=(
f"**You {result[1]}**\nYour hand: {player_score}\n" +
f"Dealer's hand: {dealer_score}"
)
)
os.remove(f'data/{ctx.author.id}.png')
except Exception as e:
print(e)

View File

@@ -0,0 +1,386 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import CROSS, TICK
from discord.ext import commands
from discord.ext import menus
import aiosqlite
import os
from utils.Tools import *
from utils.cv2 import CV2, build_container
from typing import Union
from discord.ui import LayoutView, TextDisplay, Separator, Container
class CV2(LayoutView):
def __init__(self, title, *sections):
super().__init__(timeout=None)
items = [TextDisplay(f"**{title}**")]
for s in sections:
if s:
items.append(Separator(visible=True))
items.append(TextDisplay(str(s)))
self.add_item(build_container(*items))
from utils.paginator import Paginator as sonu
class BlacklistWordSource(menus.ListPageSource):
def __init__(self, data):
super().__init__(data, per_page=4)
async def format_page(self, menu, entries):
embed = discord.Embed(
title="Blacklist Word [7]",
description="< > Duty | [ ] Optional",
color=0xFF0000
)
for entry in entries:
embed.add_field(name="",value=entry, inline=False)
embed.set_footer(
text='Users having Administrator can use Blacklisted Word',
icon_url="https://cdn.discordapp.com/avatars/1396114795102470196/198b9bc616ec574f6fd2f7121a1d3abc.webp?size=4096"
)
return embed
DB_PATH = "db/blword.db"
async def create_blacklist_table():
async with aiosqlite.connect(DB_PATH) as db:
await db.execute("""
CREATE TABLE IF NOT EXISTS blacklist (
guild_id TEXT,
word TEXT,
PRIMARY KEY (guild_id, word)
)
""")
await db.commit()
async def create_bypass_table():
async with aiosqlite.connect(DB_PATH) as db:
await db.execute("""
CREATE TABLE IF NOT EXISTS bypass (
guild_id TEXT,
user_id INTEGER,
PRIMARY KEY (guild_id, user_id)
)
""")
await db.commit()
async def create_bypass_roles_table():
async with aiosqlite.connect(DB_PATH) as db:
await db.execute("""
CREATE TABLE IF NOT EXISTS bypass_roles (
guild_id TEXT,
role_id INTEGER,
PRIMARY KEY (guild_id, role_id)
)
""")
await db.commit()
class Blacklist(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.bot.loop.create_task(create_blacklist_table())
self.bot.loop.create_task(create_bypass_table())
self.bot.loop.create_task(create_bypass_roles_table())
############ FUNCTIONS ############
async def is_word_blacklisted(self, guild_id, word):
async with aiosqlite.connect(DB_PATH) as db:
async with db.execute("SELECT * FROM blacklist WHERE guild_id = ? AND word = ?", (guild_id, word)) as cursor:
return await cursor.fetchone() is not None
async def add_word_to_blacklist(self, guild_id, word):
async with aiosqlite.connect(DB_PATH) as db:
await db.execute("INSERT INTO blacklist (guild_id, word) VALUES (?, ?)", (guild_id, word))
await db.commit()
async def remove_word_from_blacklist(self, guild_id, word):
async with aiosqlite.connect(DB_PATH) as db:
await db.execute("DELETE FROM blacklist WHERE guild_id = ? AND word = ?", (guild_id, word))
await db.commit()
async def get_blacklisted_words(self, guild_id):
async with aiosqlite.connect(DB_PATH) as db:
async with db.execute("SELECT word FROM blacklist WHERE guild_id = ?", (guild_id,)) as cursor:
return [row[0] async for row in cursor]
async def is_user_bypassed(self, guild_id, user_id):
async with aiosqlite.connect(DB_PATH) as db:
async with db.execute("SELECT * FROM bypass WHERE guild_id = ? AND user_id = ?", (guild_id, user_id)) as cursor:
return await cursor.fetchone() is not None
async def add_user_to_bypass(self, guild_id, user_id):
async with aiosqlite.connect(DB_PATH) as db:
await db.execute("INSERT INTO bypass (guild_id, user_id) VALUES (?, ?)", (guild_id, user_id))
await db.commit()
async def remove_user_from_bypass(self, guild_id, user_id):
async with aiosqlite.connect(DB_PATH) as db:
await db.execute("DELETE FROM bypass WHERE guild_id = ? AND user_id = ?", (guild_id, user_id))
await db.commit()
async def get_bypassed_users(self, guild_id):
async with aiosqlite.connect(DB_PATH) as db:
async with db.execute("SELECT user_id FROM bypass WHERE guild_id = ?", (guild_id,)) as cursor:
return [row[0] async for row in cursor]
async def is_role_bypassed(self, guild_id, role_id):
async with aiosqlite.connect(DB_PATH) as db:
async with db.execute("SELECT * FROM bypass_roles WHERE guild_id = ? AND role_id = ?", (guild_id, role_id)) as cursor:
return await cursor.fetchone() is not None
async def add_role_to_bypass(self, guild_id, role_id):
async with aiosqlite.connect(DB_PATH) as db:
await db.execute("INSERT INTO bypass_roles (guild_id, role_id) VALUES (?, ?)", (guild_id, role_id))
await db.commit()
async def remove_role_from_bypass(self, guild_id, role_id):
async with aiosqlite.connect(DB_PATH) as db:
await db.execute("DELETE FROM bypass_roles WHERE guild_id = ? AND role_id = ?", (guild_id, role_id))
await db.commit()
async def get_bypassed_roles(self, guild_id):
async with aiosqlite.connect(DB_PATH) as db:
async with db.execute("SELECT role_id FROM bypass_roles WHERE guild_id = ?", (guild_id,)) as cursor:
return [row[0] async for row in cursor]
async def remove_all_words_from_blacklist(self, guild_id):
async with aiosqlite.connect(DB_PATH) as db:
await db.execute("DELETE FROM blacklist WHERE guild_id = ?", (guild_id,))
await db.commit()
@commands.Cog.listener()
async def on_message(self, message):
if message.author.bot:
return
guild_id = str(message.guild.id)
words = await self.get_blacklisted_words(guild_id)
bypassed_users = await self.get_bypassed_users(guild_id)
bypassed_roles = await self.get_bypassed_roles(guild_id)
if message.author.guild_permissions.administrator or message.author.id in bypassed_users:
return
for role in message.author.roles:
if role.id in bypassed_roles:
return
for word in words:
if word in message.content.lower():
await message.delete()
warning_message = await message.channel.send(
f"{message.author.mention} watch your language, your message contains a blacklisted word!"
)
await warning_message.delete(delay=3)
break
@commands.group(name="blacklistword", aliases=["blword"], invoke_without_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def blacklistword(self, ctx):
commands_list = [
"➜ `blacklistword add <word>` - Add a word to the blacklist.",
"➜ `blacklistword remove <word>` - Remove a word from the blacklist.",
"➜ `blacklistword reset` - Clear all blacklisted words for the guild.",
"➜ `blacklistword config` - Show the list of blacklisted words for the guild.",
"➜ `blacklistword bypass add <role>/<user>` - Add a role/user to the bypass list.",
"➜ `blacklistword bypass remove <role>/<user>` - Remove a role/user from the bypass list.",
"➜ `blacklistword bypass list` - Show the list of bypassed roles/users."
]
paginator = sonu(
source=BlacklistWordSource(commands_list),
ctx=ctx
)
await paginator.paginate()
@blacklistword.command(name="add")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def add(self, ctx, word: str):
guild_id = str(ctx.guild.id)
if len(await self.get_blacklisted_words(guild_id)) >= 30:
await ctx.reply("The blacklist is full. Maximum 30 words allowed.")
return
if await self.is_word_blacklisted(guild_id, word.lower()):
await ctx.reply(view=CV2(f"{TICK} Access Denied", f"`{word}` is already in the blacklist."))
return
await self.add_word_to_blacklist(guild_id, word.lower())
await ctx.reply(view=CV2(f"{TICK} Success", f"Added `{word}` to the blacklist."))
@blacklistword.command(name="remove")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def remove(self, ctx, word: str):
guild_id = str(ctx.guild.id)
if not await self.is_word_blacklisted(guild_id, word.lower()):
await ctx.reply(view=CV2(f"{CROSS} Error", f"`{word}` is not in the blacklist."))
return
await self.remove_word_from_blacklist(guild_id, word.lower())
await ctx.reply(view=CV2(f"{TICK} Success", f"Removed `{word}` from the blacklist."))
@blacklistword.command(name="reset")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def reset(self, ctx):
guild_id = str(ctx.guild.id)
words = await self.get_blacklisted_words(guild_id)
if not words:
await ctx.reply(view=CV2(f"{CROSS} Error", "No words are currently blacklisted."))
return
await self.remove_all_words_from_blacklist(guild_id)
await ctx.reply(view=CV2(f"{TICK} Success", "Cleared all blacklisted words."))
@blacklistword.command(name="config")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def config(self, ctx):
guild_id = str(ctx.guild.id)
words = await self.get_blacklisted_words(guild_id)
if not words:
await ctx.reply(view=CV2(f"{CROSS} Error", "No words are currently blacklisted."))
return
await ctx.reply(view=CV2(f"Blacklisted Words for {ctx.guild.name}", "\n".join(words)))
@blacklistword.group(name="bypass", invoke_without_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def bypass(self, ctx):
await ctx.send(view=CV2("Bypass User Commands", "➜ `blacklistword bypass add <role>/<user>` - Add a role/user to the bypass list.\n\n➜ `blacklistword bypass remove <role>/<user>` - Remove a role/user from the bypass list.\n\n➜ `blacklistword bypass list` - Show the list of bypassed roles/users."))
@bypass.command(name="add")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def bypass_add(self, ctx, target: Union[discord.Member, discord.Role]):
guild_id = str(ctx.guild.id)
if isinstance(target, discord.Member):
if len(await self.get_bypassed_users(guild_id)) >= 30:
await ctx.reply("The bypass list for users is full. Maximum 30 users allowed.")
return
if await self.is_user_bypassed(guild_id, target.id):
await ctx.reply(view=CV2("Error", f"{CROSS} | `{target}` is already bypassed."))
return
await self.add_user_to_bypass(guild_id, target.id)
await ctx.reply(view=CV2(f"{TICK} Success", f"Added `{target}` to the bypass list."))
elif isinstance(target, discord.Role):
if len(await self.get_bypassed_roles(guild_id)) >= 30:
await ctx.reply("The bypass list for roles is full. Maximum 30 roles allowed.")
return
if await self.is_role_bypassed(guild_id, target.id):
await ctx.reply(view=CV2(f"{CROSS} Error", f"`{target}` is already bypassed."))
return
await self.add_role_to_bypass(guild_id, target.id)
await ctx.reply(view=CV2(f"{TICK} Success", f"Added `{target}` to the bypass list."))
@bypass.command(name="remove")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def bypass_remove(self, ctx, target: Union[discord.Member, discord.Role]):
guild_id = str(ctx.guild.id)
if isinstance(target, discord.Member):
if not await self.is_user_bypassed(guild_id, target.id):
await ctx.reply(view=CV2(f"{CROSS} Error", f"`{target}` is not bypassed."))
return
await self.remove_user_from_bypass(guild_id, target.id)
await ctx.reply(view=CV2(f"{TICK} Success", f"Removed `{target}` from the bypass list."))
elif isinstance(target, discord.Role):
if not await self.is_role_bypassed(guild_id, target.id):
await ctx.reply(view=CV2(f"{CROSS} Error", f"`{target}` is not bypassed."))
return
await self.remove_role_from_bypass(guild_id, target.id)
await ctx.reply(view=CV2(f"{TICK} Success", f"Removed `{target}` from the bypass list."))
@bypass.command(name="list")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def bypass_list(self, ctx):
guild_id = str(ctx.guild.id)
users = await self.get_bypassed_users(guild_id)
roles = await self.get_bypassed_roles(guild_id)
if not users and not roles:
await ctx.send(view=CV2(f"{CROSS} Error", "No users or roles are currently bypassed."))
return
bypassed_users = [ctx.guild.get_member(user_id) for user_id in users if ctx.guild.get_member(user_id)]
bypassed_roles = [ctx.guild.get_role(role_id) for role_id in roles if ctx.guild.get_role(role_id)]
sections = []
if bypassed_users:
sections.append(f"**Users**\n" + ", ".join([user.name for user in bypassed_users]))
if bypassed_roles:
sections.append(f"**Roles**\n" + ", ".join([role.name for role in bypassed_roles]))
await ctx.send(view=CV2(f"Bypassed Users and Roles for {ctx.guild.name}", *sections))
@add.error
@remove.error
@reset.error
@config.error
@bypass_add.error
@bypass_remove.error
async def command_error(self, ctx, error):
if isinstance(error, commands.CommandError):
if not isinstance(error, commands.CommandOnCooldown):
await ctx.reply(view=CV2("Error", f"{CROSS} | An error occurred while processing the command. Make sure you have **Administrator** permission."))

192
bot/cogs/commands/block.py Normal file
View File

@@ -0,0 +1,192 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import CROSS, TICK
from discord.ext import commands
import aiosqlite
from utils import Paginator, DescriptionEmbedPaginator
from discord.ui import LayoutView, TextDisplay, Separator, Container
from utils.cv2 import CV2, build_container
class CV2(LayoutView):
def __init__(self, title, *sections):
super().__init__(timeout=None)
items = [TextDisplay(f"**{title}**")]
for s in sections:
if s:
items.append(Separator(visible=True))
items.append(TextDisplay(str(s)))
self.add_item(build_container(*items))
class Block(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.bot.loop.create_task(self.set_db())
#@commands.Cog.listener()
async def set_db(self):
async with aiosqlite.connect('db/block.db') as db:
await db.execute('''
CREATE TABLE IF NOT EXISTS user_blacklist (
user_id INTEGER PRIMARY KEY,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
await db.execute('''
CREATE TABLE IF NOT EXISTS guild_blacklist (
guild_id INTEGER PRIMARY KEY,
timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
await db.commit()
@commands.group(name="blacklist", aliases=["bl"], invoke_without_command=True)
@commands.is_owner()
async def blacklist(self, ctx):
if ctx.subcommand_passed is None:
ctx.command.reset_cooldown(ctx)
await ctx.send_help(ctx.command)
@blacklist.group(name="user", help="Add/Remove a user to the blacklist.", invoke_without_command=True)
@commands.is_owner()
async def user(self, ctx):
if ctx.subcommand_passed is None:
ctx.command.reset_cooldown(ctx)
await ctx.send_help(ctx.command)
@user.command(name="add", help="Adds a user to the blacklist.")
@commands.is_owner()
async def add_user(self, ctx, user: discord.User):
async with aiosqlite.connect('db/block.db') as db:
cursor = await db.execute('SELECT user_id FROM user_blacklist WHERE user_id = ?', (user.id,))
if await cursor.fetchone():
await ctx.reply(view=CV2("User Already Blacklisted", f"{user.mention} is already blacklisted."))
else:
await db.execute('INSERT INTO user_blacklist (user_id) VALUES (?)', (user.id,))
await db.commit()
await ctx.reply(view=CV2(f"{TICK} User Blacklisted", f"{user.mention} has been added to the blacklist."))
@user.command(name="remove", help="Remove a user from the blacklist.")
@commands.is_owner()
async def remove_user(self, ctx, user: discord.User):
async with aiosqlite.connect('db/block.db') as db:
cursor = await db.execute('SELECT user_id FROM user_blacklist WHERE user_id = ?', (user.id,))
if not await cursor.fetchone():
await ctx.reply(view=CV2(f"{CROSS} User Not Blacklisted", f"{user.mention} is not in the blacklist."))
else:
await db.execute('DELETE FROM user_blacklist WHERE user_id = ?', (user.id,))
await db.commit()
await ctx.reply(view=CV2(f"{TICK} User Unblacklisted", f"{user.mention} has been removed from the blacklist."))
@user.command(name="show", aliases=["list"], help="Shows all Blacklisted users.")
@commands.is_owner()
async def show_users(self, ctx):
async with aiosqlite.connect('db/block.db') as db:
cursor = await db.execute('SELECT user_id FROM user_blacklist')
rows = await cursor.fetchall()
if not rows:
await ctx.reply(view=CV2(f"{CROSS} No Blacklisted Users", "There are no users in the blacklist."))
return
blacklist = []
for row in rows:
user_id = row[0]
try:
user = await self.bot.fetch_user(user_id)
username = user.name
user_link = f"https://discord.com/users/{user_id}"
#indexx = [""for index, user in enumerate(blacklist)]
blacklist.append(f"**[{username}]({user_link})** - ({user_id})")
except discord.NotFound:
blacklist.append(f"User ID: {user_id} (User not found)")
entries = [f"{index+1}. {user}" for index, user in enumerate(blacklist)]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title=f"List of Blacklisted Users - {len(blacklist)}",
description="",
per_page=10,
color=0xFF0000),
ctx=ctx
)
await paginator.paginate()
@blacklist.group(name="guild", help="Add/Remove a guild to the blacklist.", invoke_without_command=True)
@commands.is_owner()
async def guild(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@guild.command(name="add", help="Adds a guild to the blacklist.")
@commands.is_owner()
async def add_guild(self, ctx, guild_id: int):
async with aiosqlite.connect('db/block.db') as db:
cursor = await db.execute('SELECT guild_id FROM guild_blacklist WHERE guild_id = ?', (guild_id,))
if await cursor.fetchone():
await ctx.reply(view=CV2(f"{CROSS} Guild Already Blacklisted", f"Guild with ID `{guild_id}` is already blacklisted."))
else:
await db.execute('INSERT INTO guild_blacklist (guild_id) VALUES (?)', (guild_id,))
await db.commit()
await ctx.reply(view=CV2(f"{TICK} Guild Blacklisted", f"Guild with ID `{guild_id}` has been added to the blacklist."))
@guild.command(name="remove", help="Remove a guild from the blacklist.")
@commands.is_owner()
async def remove_guild(self, ctx, guild_id: int):
async with aiosqlite.connect('db/block.db') as db:
cursor = await db.execute('SELECT guild_id FROM guild_blacklist WHERE guild_id = ?', (guild_id,))
if not await cursor.fetchone():
await ctx.reply(view=CV2(f"{CROSS} Guild Not Blacklisted", f"Guild with ID `{guild_id}` is not in the blacklist."))
else:
await db.execute('DELETE FROM guild_blacklist WHERE guild_id = ?', (guild_id,))
await db.commit()
await ctx.reply(view=CV2(f"{TICK} Guild Unblacklisted", f"Guild with ID `{guild_id}` has been removed from the blacklist."))
@guild.command(name="show", aliases=["list"], help="Shows the list of blacklisted guilds")
@commands.is_owner()
async def show_guilds(self, ctx):
async with aiosqlite.connect('db/block.db') as db:
cursor = await db.execute('SELECT guild_id FROM guild_blacklist')
rows = await cursor.fetchall()
if not rows:
await ctx.reply(view=CV2(f"{CROSS} No Blacklisted Guilds", "There are no guilds in the blacklist."))
return
blacklist = []
for row in rows:
guild_id = row[0]
try:
guild = await self.bot.fetch_guild(guild_id)
guild_name = guild.name
guild_link = f"https://discord.com/guilds/{guild_id}"
blacklist.append(f"[{guild_name}]({guild_link}) - ({guild_id})")
except discord.NotFound:
blacklist.append(f"Guild ID: {guild_id} (Guild not found)")
entries = [f"{index+1}. {guild}" for index, guild in enumerate(blacklist)]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title=f"List of Blacklisted Guilds - {len(blacklist)}",
description="",
per_page=10,
color=0xFF0000),
ctx=ctx
)
await paginator.paginate()

View File

@@ -0,0 +1,634 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
from __future__ import annotations
import discord
from utils.emoji import CROSS, NITRO_BOOST, TICK, TIMER
import asyncio
import logging
import aiosqlite
import json
from discord .ext import commands
from utils .Tools import *
from discord .ext .commands import Context
from discord import app_commands
import time
import datetime
import re
from typing import *
from time import strftime
from core import Cog ,zyrox ,Context
from discord.ui import LayoutView, TextDisplay, Separator, Container
from utils.cv2 import CV2, build_container
class CV2(LayoutView):
def __init__(self, title, *sections):
super().__init__(timeout=None)
items = [TextDisplay(f"**{title}**")]
for s in sections:
if s:
items.append(Separator(visible=True))
items.append(TextDisplay(str(s)))
self.add_item(build_container(*items))
logging .basicConfig (
level =logging .INFO ,
format ="\x1b[38;5;197m[\x1b[0m%(asctime)s\x1b[38;5;197m]\x1b[0m -> \x1b[38;5;197m%(message)s\x1b[0m",
datefmt ="%H:%M:%S",
)
class Booster (Cog ):
def __init__ (self ,bot : Zyrox ):
self .bot =bot
self .color =0xFF0000
self .db_path ="db/boost.db"
self .bot .loop .create_task (self .setup_database ())
self .url_pattern =re .compile (
r'^(?:http|ftp)s?://'
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|'
r'localhost|'
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})'
r'(?::\d+)?'
r'(?:/?|[/?]\S+)$',re .IGNORECASE
)
async def setup_database (self ):
"""Initialize boost database tables"""
async with aiosqlite .connect (self .db_path )as db :
await db .execute ("""
CREATE TABLE IF NOT EXISTS boost_config (
guild_id INTEGER PRIMARY KEY,
config TEXT NOT NULL
)
""")
await db .commit ()
async def get_boost_config (self ,guild_id :int )->dict :
"""Get boost configuration for a guild"""
async with aiosqlite .connect (self .db_path )as db :
async with db .execute ("SELECT config FROM boost_config WHERE guild_id = ?",(guild_id ,))as cursor :
row =await cursor .fetchone ()
if row :
return json .loads (row [0 ])
default_config ={
"boost":{
"channel":[],
"message":"{user.mention} just boosted {server.name}! 🎉",
"embed":True ,
"ping":False ,
"image":"",
"thumbnail":"",
"autodel":0
},
"boost_roles":{
"roles":[]
}
}
await self .update_boost_config (guild_id ,default_config )
return default_config
async def update_boost_config (self ,guild_id :int ,config :dict ):
"""Update boost configuration for a guild"""
async with aiosqlite .connect (self .db_path )as db :
await db .execute (
"INSERT OR REPLACE INTO boost_config (guild_id, config) VALUES (?, ?)",
(guild_id ,json .dumps (config ))
)
await db .commit ()
def is_authorized (self ,ctx )->bool :
"""Check if user is authorized to use admin commands"""
return (
ctx .author ==ctx .guild .owner
or ctx .author .guild_permissions .administrator
or ctx .author .top_role .position >=ctx .guild .me .top_role .position
)
def format_boost_message (self ,message :str ,user :discord .Member ,guild :discord .Guild )->str :
"""Format boost message with new variable style"""
replacements ={
"{server.name}":guild .name ,
"{server.id}":str (guild .id ),
"{server.owner}":str (guild .owner ),
"{server.icon}":guild .icon .url if guild .icon else "",
"{server.boost_count}":str (guild .premium_subscription_count ),
"{server.boost_level}":f"Level {guild.premium_tier}",
"{server.member_count}":str (guild .member_count ),
"{user.name}":user .display_name ,
"{user.mention}":user .mention ,
"{user.tag}":str (user ),
"{user.id}":str (user .id ),
"{user.avatar}":user .display_avatar .url ,
"{user.created_at}":f"<t:{int(user.created_at.timestamp())}:F>",
"{user.joined_at}":f"<t:{int(user.joined_at.timestamp())}:F>"if user .joined_at else "Unknown",
"{user.top_role}":user .top_role .name if user .top_role else "None",
"{user.is_booster}":str (bool (user .premium_since )),
"{user.is_mobile}":str (user .is_on_mobile ()),
"{user.boosted_at}":f"<t:{int(user.premium_since.timestamp())}:F>"if user .premium_since else "Unknown"
}
for old ,new in replacements .items ():
message =message .replace (old ,new )
return message
async def send_permission_error (self ,ctx ):
"""Send permission error embed"""
await ctx.send(view=CV2("Permission Error", "```diff\n- You must have Administrator permission.\n- Your top role should be above my top role.\n```"))
@commands .group (name ="boost",aliases =['bst'],invoke_without_command =True ,help ="Boost message configuration commands")
@blacklist_check ()
@ignore_check ()
@commands .cooldown (1 ,5 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@commands .has_permissions (administrator =True )
async def _boost (self ,ctx ):
if ctx .subcommand_passed is None :
await ctx .send_help (ctx .command )
ctx .command .reset_cooldown (ctx )
@_boost .command (name ="thumbnail",help ="Set boost message thumbnail")
@blacklist_check ()
@ignore_check ()
@commands .cooldown (1 ,2 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@commands .has_permissions (administrator =True )
async def _boost_thumbnail (self ,ctx ,thumbnail_url :str ):
if not self .is_authorized (ctx ):
await self .send_permission_error (ctx )
return
if not self .url_pattern .match (thumbnail_url ):
await ctx.send(view=CV2("Error", f"{CROSS} Please provide a valid URL."))
return
data =await self .get_boost_config (ctx .guild .id )
data ["boost"]["thumbnail"]=thumbnail_url
await self .update_boost_config (ctx .guild .id ,data )
await ctx.send(view=CV2("Success", f"{TICK} Successfully updated the boost thumbnail URL."))
@_boost .command (name ="image",help ="Set boost message image")
@blacklist_check ()
@ignore_check ()
@commands .cooldown (1 ,2 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@commands .has_permissions (administrator =True )
async def _boost_image (self ,ctx ,*,image_url :str ):
if not self .is_authorized (ctx ):
await self .send_permission_error (ctx )
return
if not self .url_pattern .match (image_url ):
await ctx.send(view=CV2("Error", f"{CROSS} Please provide a valid URL."))
return
data =await self .get_boost_config (ctx .guild .id )
data ["boost"]["image"]=image_url
await self .update_boost_config (ctx .guild .id ,data )
await ctx.send(view=CV2("Success", f"{TICK} Successfully updated the boost image URL."))
@_boost .command (name ="autodel",help ="Set auto-delete timer for boost messages (0 to disable)")
@blacklist_check ()
@ignore_check ()
@commands .cooldown (1 ,2 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@commands .has_permissions (administrator =True )
async def _boost_autodel (self ,ctx ,seconds :int ):
if not self .is_authorized (ctx ):
await self .send_permission_error (ctx )
return
if seconds <0 :
await ctx.send(view=CV2("Error", f"{CROSS} Auto-delete timer must be 0 or greater."))
return
data =await self .get_boost_config (ctx .guild .id )
data ["boost"]["autodel"]=seconds
await self .update_boost_config (ctx .guild .id ,data )
description =f"{TICK} Successfully set auto-delete timer to {seconds} seconds."
if seconds ==0 :
description =f"{TICK} Auto-delete has been disabled."
await ctx.send(view=CV2("Success", description))
@_boost .command (name ="message",help ="Set boost message content")
@blacklist_check ()
@ignore_check ()
@commands .cooldown (1 ,2 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@commands .has_permissions (administrator =True )
async def _boost_message (self ,ctx ):
if not self .is_authorized (ctx ):
await self .send_permission_error (ctx )
return
variables_text = (
"Send your boost message in this channel now.\n\n**Available Variables:**\n"
"```\n"
"{server.name} - Server name\n"
"{server.id} - Server ID\n"
"{server.owner} - Server owner\n"
"{server.icon} - Server icon URL\n"
"{server.boost_count} - Current boost count\n"
"{server.boost_level} - Boost level (e.g., Level 2)\n"
"{server.member_count} - Total member count\n\n"
"{user.name} - Booster's display name\n"
"{user.mention} - Mention the booster\n"
"{user.tag} - Booster's full tag\n"
"{user.id} - Booster's ID\n"
"{user.avatar} - Booster's avatar URL\n"
"{user.created_at} - When the account was created\n"
"{user.joined_at} - When user joined the server\n"
"{user.top_role} - Booster's top role name\n"
"{user.is_booster} - Whether they're a booster\n"
"{user.is_mobile} - Whether on mobile\n"
"{user.boosted_at} - Boost timestamp\n"
"```\n*You have 60 seconds to respond*"
)
await ctx.send(view=CV2(f"{TICK} Boost Message Setup", variables_text))
def check (m ):
return m .author ==ctx .author and m .channel ==ctx .channel
try :
message =await self .bot .wait_for ('message',check =check ,timeout =60.0 )
except asyncio .TimeoutError :
await ctx.send(view=CV2("Timeout", f"{TIMER} Timeout! Please try again."))
return
data =await self .get_boost_config (ctx .guild .id )
data ["boost"]["message"]=message .content
await self .update_boost_config (ctx .guild .id ,data )
await ctx.send(view=CV2("Success", f"{TICK} Successfully updated the boost message."))
@_boost .command (name ="embed",help ="Toggle embed formatting for boost messages")
@blacklist_check ()
@ignore_check ()
@commands .cooldown (1 ,2 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@commands .has_permissions (administrator =True )
async def _boost_embed (self ,ctx ):
if not self .is_authorized (ctx ):
await self .send_permission_error (ctx )
return
data =await self .get_boost_config (ctx .guild .id )
data ["boost"]["embed"]=not data ["boost"]["embed"]
await self .update_boost_config (ctx .guild .id ,data )
status ="enabled"if data ["boost"]["embed"]else "disabled"
await ctx.send(view=CV2("Success", f"{TICK} Embed formatting has been **{status}**."))
@_boost .command (name ="ping",help ="Toggle pinging the booster")
@blacklist_check ()
@ignore_check ()
@commands .cooldown (1 ,2 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@commands .has_permissions (administrator =True )
async def _boost_ping (self ,ctx ):
if not self .is_authorized (ctx ):
await self .send_permission_error (ctx )
return
data =await self .get_boost_config (ctx .guild .id )
data ["boost"]["ping"]=not data ["boost"]["ping"]
await self .update_boost_config (ctx .guild .id ,data )
status ="enabled"if data ["boost"]["ping"]else "disabled"
await ctx.send(view=CV2("Success", f"{TICK} Booster pinging has been **{status}**."))
@_boost .group (name ="channel",help ="Manage boost notification channels")
@blacklist_check ()
@ignore_check ()
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@commands .has_permissions (administrator =True )
async def _boost_channel (self ,ctx ):
if ctx .subcommand_passed is None :
await ctx .send_help (ctx .command )
ctx .command .reset_cooldown (ctx )
@_boost_channel .command (name ="add",help ="Add a boost notification channel")
@blacklist_check ()
@ignore_check ()
@commands .cooldown (1 ,3 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@commands .has_permissions (administrator =True )
async def _boost_channel_add (self ,ctx ,channel :discord .TextChannel ):
if not self .is_authorized (ctx ):
await self .send_permission_error (ctx )
return
data =await self .get_boost_config (ctx .guild .id )
channels =data ["boost"]["channel"]
if len (channels )>=3 :
await ctx.send(view=CV2("Error", f"{CROSS} Maximum boost channel limit reached (3 channels)."))
return
if str (channel .id )in channels :
await ctx.send(view=CV2("Error", f"{CROSS} This channel is already in the boost channels list."))
return
channels .append (str (channel .id ))
await self .update_boost_config (ctx .guild .id ,data )
await ctx.send(view=CV2("Success", f"{TICK} Successfully added {channel.mention} to boost channels list."))
@_boost_channel .command (name ="remove",help ="Remove a boost notification channel")
@blacklist_check ()
@ignore_check ()
@commands .cooldown (1 ,3 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@commands .has_permissions (administrator =True )
async def _boost_channel_remove (self ,ctx ,channel :discord .TextChannel ):
if not self .is_authorized (ctx ):
await self .send_permission_error (ctx )
return
data =await self .get_boost_config (ctx .guild .id )
channels =data ["boost"]["channel"]
if not channels :
await ctx.send(view=CV2("Error", f"{CROSS} No boost channels are currently set up."))
return
if str (channel .id )not in channels :
await ctx.send(view=CV2("Error", f"{CROSS} This channel is not in the boost channels list."))
return
channels .remove (str (channel .id ))
await self .update_boost_config (ctx .guild .id ,data )
await ctx.send(view=CV2("Success", f"{TICK} Successfully removed {channel.mention} from boost channels list."))
@_boost .command (name ="test",help ="Test how the boost message will look")
@blacklist_check ()
@ignore_check ()
@commands .guild_only ()
@commands .has_permissions (administrator =True )
async def _boost_test (self ,ctx ):
data =await self .get_boost_config (ctx .guild .id )
channels =data ["boost"]["channel"]
if not channels :
await ctx.send(view=CV2("Error", f"{CROSS} Please set up a boost channel first using `boost channel add #channel`."))
return
formatted_message =self .format_boost_message (data ["boost"]["message"],ctx .author ,ctx .guild )
channel =self .bot .get_channel (int (channels [0 ]))
if not channel :
await ctx.send(view=CV2("Error", f"{CROSS} The configured boost channel no longer exists."))
return
try :
if data ["boost"]["embed"]:
embed =discord .Embed (description =formatted_message ,color =self .color )
embed .set_author (name =ctx .author .display_name ,icon_url =ctx .author .display_avatar .url )
embed .timestamp =discord .utils .utcnow ()
if data ["boost"]["image"]:
embed .set_image (url =data ["boost"]["image"])
if data ["boost"]["thumbnail"]:
embed .set_thumbnail (url =data ["boost"]["thumbnail"])
if ctx .guild .icon :
embed .set_footer (text =ctx .guild .name ,icon_url =ctx .guild .icon .url )
ping_content =ctx .author .mention if data ["boost"]["ping"]else ""
await channel .send (ping_content ,embed =embed )
else :
await channel .send (formatted_message )
except discord .Forbidden :
await ctx.send(view=CV2("Error", f"{CROSS} I don't have permission to send messages in the boost channel."))
except Exception as e :
await ctx.send(view=CV2("Error", f"{CROSS} An error occurred: `{str(e)}`"))
@_boost .command (name ="config",help ="View current boost configuration")
@blacklist_check ()
@ignore_check ()
@commands .has_permissions (administrator =True )
async def _boost_config (self ,ctx ):
data =await self .get_boost_config (ctx .guild .id )
channels =data ["boost"]["channel"]
if not channels :
await ctx.send(view=CV2("Error", f"{CROSS} Please set up a boost channel first using `boost channel add #channel`."))
return
channel_mentions =[]
for channel_id in channels :
channel =self .bot .get_channel (int (channel_id ))
if channel :
channel_mentions .append (channel .mention )
embed_status = f"{TICK} Enabled" if data["boost"]["embed"] else f"{CROSS} Disabled"
ping_status = f"{TICK} Enabled" if data["boost"]["ping"] else f"{CROSS} Disabled"
autodel_status = f"{data['boost']['autodel']}s" if data["boost"]["autodel"] else "Disabled"
channels_str = "\n".join(channel_mentions) if channel_mentions else "None"
config_text = (
f"**Channels**\n{channels_str}\n\n"
f"**Message**\n```{data['boost']['message']}```\n"
f"**Embed:** {embed_status}\n"
f"**Ping:** {ping_status}\n"
f"**Auto-delete:** {autodel_status}"
)
await ctx.send(view=CV2(f"{NITRO_BOOST} Boost Configuration for {ctx.guild.name}", config_text))
@_boost .command (name ="reset",help ="Reset boost configuration")
@commands .cooldown (1 ,5 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@blacklist_check ()
@ignore_check ()
@commands .has_permissions (administrator =True )
async def _boost_reset (self ,ctx ):
if not self .is_authorized (ctx ):
await self .send_permission_error (ctx )
return
data =await self .get_boost_config (ctx .guild .id )
if not data ["boost"]["channel"]:
await ctx.send(view=CV2("Error", f"{CROSS} No boost configuration found to reset."))
return
data ["boost"]["channel"]=[]
data ["boost"]["image"]=""
data ["boost"]["message"]="{user.mention} just boosted {server.name}! 🎉"
data ["boost"]["thumbnail"]=""
data ["boost"]["embed"]=True
data ["boost"]["ping"]=False
data ["boost"]["autodel"]=0
await self .update_boost_config (ctx .guild .id ,data )
await ctx.send(view=CV2("Success", f"{TICK} Successfully reset all boost configuration."))
@commands .group (name ="boostrole",invoke_without_command =True ,help ="Manage boost roles")
@commands .cooldown (1 ,5 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@blacklist_check ()
@ignore_check ()
@commands .guild_only ()
@commands .has_permissions (administrator =True )
async def _boostrole (self ,ctx ):
if ctx .subcommand_passed is None :
await ctx .send_help (ctx .command )
ctx .command .reset_cooldown (ctx )
@_boostrole .command (name ="config",help ="View boost role configuration")
@commands .cooldown (1 ,5 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@blacklist_check ()
@ignore_check ()
@commands .has_permissions (administrator =True )
async def _boostrole_config (self ,ctx ):
data =await self .get_boost_config (ctx .guild .id )
role_ids =data ["boost_roles"]["roles"]
if not role_ids :
await ctx.send(view=CV2(f"Boost Roles - {ctx.guild.name}", "No boost roles configured."))
return
roles =[]
for role_id in role_ids :
role =ctx .guild .get_role (int (role_id ))
if role :
roles .append (role .mention )
roles_str = "\n".join(roles) if roles else "No valid roles found"
await ctx.send(view=CV2(f"Boost Roles - {ctx.guild.name}", roles_str))
@_boostrole .command (name ="add",help ="Add a boost role")
@blacklist_check ()
@ignore_check ()
@commands .cooldown (1 ,3 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@commands .has_permissions (administrator =True )
async def _boostrole_add (self ,ctx ,role :discord .Role ):
if not self .is_authorized (ctx ):
await self .send_permission_error (ctx )
return
data =await self .get_boost_config (ctx .guild .id )
roles =data ["boost_roles"]["roles"]
if len (roles )>=10 :
await ctx.send(view=CV2("Error", f"{CROSS} Maximum boost role limit reached (10 roles)."))
return
if str (role .id )in roles :
await ctx.send(view=CV2("Error", f"{CROSS} {role.mention} is already a boost role."))
return
roles .append (str (role .id ))
await self .update_boost_config (ctx .guild .id ,data )
await ctx.send(view=CV2("Success", f"{TICK} {role.mention} has been added as a boost role."))
@_boostrole .command (name ="remove",help ="Remove a boost role")
@blacklist_check ()
@ignore_check ()
@commands .cooldown (1 ,3 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@commands .has_permissions (administrator =True )
async def _boostrole_remove (self ,ctx ,role :discord .Role ):
if not self .is_authorized (ctx ):
await self .send_permission_error (ctx )
return
data =await self .get_boost_config (ctx .guild .id )
roles =data ["boost_roles"]["roles"]
if not roles :
await ctx.send(view=CV2("Error", f"{CROSS} No boost roles are currently configured."))
return
if str (role .id )not in roles :
await ctx.send(view=CV2("Error", f"{CROSS} {role.mention} is not a boost role."))
return
roles .remove (str (role .id ))
await self .update_boost_config (ctx .guild .id ,data )
await ctx.send(view=CV2("Success", f"{TICK} {role.mention} has been removed from boost roles."))
@_boostrole .command (name ="reset",help ="Reset boost role configuration")
@commands .cooldown (1 ,3 ,commands .BucketType .user )
@commands .max_concurrency (1 ,per =commands .BucketType .default ,wait =False )
@commands .guild_only ()
@blacklist_check ()
@ignore_check ()
@commands .has_permissions (administrator =True )
async def _boostrole_reset (self ,ctx ):
if not self .is_authorized (ctx ):
await self .send_permission_error (ctx )
return
data =await self .get_boost_config (ctx .guild .id )
if not data ["boost_roles"]["roles"]:
await ctx.send(view=CV2("Error", f"{CROSS} No boost roles are currently configured."))
return
data ["boost_roles"]["roles"]=[]
await self .update_boost_config (ctx .guild .id ,data )
await ctx.send(view=CV2("Success", f"{TICK} Successfully cleared all boost roles."))
async def setup (bot ):
await bot .add_cog (Booster(bot ))

137
bot/cogs/commands/calc.py Normal file
View 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 ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
from discord.ext import commands
from discord.ui import View, Button, button
import discord
from utils.safe_parse import safe_math_eval
class CalculatorView(View):
def __init__(self, author: discord.Member):
super().__init__()
self.author = author
self.value = ""
self.message = None
# Button interactions
@button(label="1", style=discord.ButtonStyle.grey, row=0)
async def one(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "1")
@button(label="2", style=discord.ButtonStyle.grey, row=0)
async def two(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "2")
@button(label="3", style=discord.ButtonStyle.grey, row=0)
async def three(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "3")
@button(label="4", style=discord.ButtonStyle.grey, row=1)
async def four(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "4")
@button(label="5", style=discord.ButtonStyle.grey, row=1)
async def five(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "5")
@button(label="6", style=discord.ButtonStyle.grey, row=1)
async def six(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "6")
@button(label="7", style=discord.ButtonStyle.grey, row=2)
async def seven(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "7")
@button(label="8", style=discord.ButtonStyle.grey, row=2)
async def eight(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "8")
@button(label="9", style=discord.ButtonStyle.grey, row=2)
async def nine(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "9")
@button(label="0", style=discord.ButtonStyle.grey, row=3)
async def zero(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "0")
@button(label="+", style=discord.ButtonStyle.blurple, row=3)
async def add(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "+")
@button(label="-", style=discord.ButtonStyle.blurple, row=3)
async def subtract(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "-")
@button(label="*", style=discord.ButtonStyle.blurple, row=3)
async def multiply(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "*")
@button(label="/", style=discord.ButtonStyle.blurple, row=3)
async def divide(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "/")
@button(label="=", style=discord.ButtonStyle.green, row=4)
async def equals(self, interaction: discord.Interaction, button: Button):
if interaction.user != self.author:
return await interaction.response.send_message(
"This is not your embed.", ephemeral=True
)
try:
expression = self.value.strip().replace("\n", "")
result = safe_math_eval(expression)
await self.update_embed(interaction, result)
self.value = result # Store the result for possible further calculations
except:
await self.update_embed(interaction, "Error")
@button(label="Clear", style=discord.ButtonStyle.red, row=4)
async def clear(self, interaction: discord.Interaction, button: Button):
await self.update_value(interaction, "Clear")
async def update_value(self, interaction: discord.Interaction, value: str):
# Check if the person interacting is the author of the embed
if interaction.user != self.author:
return await interaction.response.send_message(
"This content does not appear to be part of your embedded materials.", ephemeral=True
)
# Append the value or clear if "Clear"
if value == "Clear":
self.value = ""
else:
self.value += value
# Update the embed with the new value
await self.update_embed(interaction, self.value)
async def update_embed(self, interaction: discord.Interaction, result: str):
content = f"**Calculator** | `{self.author.display_name}`\n```\n{result}\n```"
await interaction.response.edit_message(content=content, view=self)
self.message = interaction.message
class calculator(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(name='calculator', help='Starts a calculator session', aliases=['calc', 'calculate', 'math'])
async def calculator(self, ctx):
"""Starts a new calculator session."""
# Ensure we pass the author to the view so it knows who triggered it
view = CalculatorView(author=ctx.author)
# We store the message so we know what to edit and update later
view.message = await ctx.send(content="**Calculator**\n```\n \n```", view=view)
# Add the cog to the bot
def setup(bot):
bot.add_cog(calculator(bot))

View File

@@ -0,0 +1,208 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import ARROWRED, CROSS, NEXT_ALT1, REDRULESBOOK, RED_BUTTON, RED_PIN, STAR, TICK, ZBACK, ZPAUSE, ZPLAY, ZWARNING
from discord.ext import commands
import json
import os
import asyncio
from discord.ui import LayoutView, TextDisplay, Separator, Container
from utils.cv2 import CV2, build_container
# Emoji Variables
CROSS = CROSS
TICK = TICK
WARNING = ZWARNING
WARNING = ZWARNING
BOOK = REDRULESBOOK
PLAY = ZPLAY
PAUSE = ZPAUSE
STOP = RED_BUTTON
NEXT = NEXT_ALT1
BACK = ZBACK
ARROW = ARROWRED
PIN = RED_PIN
STAR = STAR
class Counting(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.data_file = "db/counting.json"
if not os.path.exists(self.data_file):
with open(self.data_file, 'w') as f:
json.dump({}, f)
with open(self.data_file, 'r') as f:
self.counting_data = json.load(f)
def save_data(self):
with open(self.data_file, 'w') as f:
json.dump(self.counting_data, f, indent=4)
def is_enabled(self, guild_id):
guild_id = str(guild_id)
return self.counting_data.get(guild_id, {}).get("enabled", False)
async def not_enabled_embed(self, ctx):
await ctx.send(view=CV2(
f"{BOOK} Counting Settings For {ctx.guild.name}",
f"**Current Status:** {CROSS} Disabled",
"**How to Enable:** Use `counting enable` to enable counting."
))
async def send_help_embed(self, ctx):
await ctx.send(view=CV2(
f"{BOOK} Counting Commands",
"Manage and control the counting game settings.\n\n"
"**counting enable/disable** — Enable or Disable counting in server\n"
"**counting channel #channel** — Set counting channel\n"
"**counting config reset/continue** — Set reset mode on mistake\n"
"**counting reset** — Reset counting back to 0\n"
"**counting stats** — View current counting stats"
))
@commands.group(name="counting", invoke_without_command=True)
async def counting(self, ctx):
if not self.is_enabled(ctx.guild.id):
await self.not_enabled_embed(ctx)
else:
await self.send_help_embed(ctx)
@counting.command(name="enable")
@commands.has_permissions(manage_channels=True)
async def enable(self, ctx):
guild_id = str(ctx.guild.id)
if guild_id not in self.counting_data:
self.counting_data[guild_id] = {"enabled": True, "channel": None, "count": 0, "reset_on_fail": False}
else:
self.counting_data[guild_id]["enabled"] = True
self.save_data()
await ctx.send(view=CV2("Counting", f"{TICK} Counting has been Enabled!"))
@counting.command(name="disable")
@commands.has_permissions(manage_channels=True)
async def disable(self, ctx):
guild_id = str(ctx.guild.id)
if guild_id not in self.counting_data:
await self.not_enabled_embed(ctx)
return
self.counting_data[guild_id]["enabled"] = False
self.save_data()
await ctx.send(view=CV2("Counting", f"{STOP} Counting has been Disabled!"))
@counting.command(name="channel")
@commands.has_permissions(manage_channels=True)
async def channel(self, ctx, channel: discord.TextChannel):
guild_id = str(ctx.guild.id)
if not self.is_enabled(guild_id):
await self.not_enabled_embed(ctx)
return
self.counting_data[guild_id]["channel"] = channel.id
self.save_data()
await ctx.send(view=CV2("Counting", f"{PIN} Counting channel set to {channel.mention}"))
@counting.command(name="config")
@commands.has_permissions(manage_channels=True)
async def config(self, ctx, mode: str):
guild_id = str(ctx.guild.id)
if not self.is_enabled(guild_id):
await self.not_enabled_embed(ctx)
return
if mode.lower() in ["reset", "true", "on"]:
self.counting_data[guild_id]["reset_on_fail"] = True
msg = f"{TICK} Counting will now reset on mistakes."
elif mode.lower() in ["continue", "false", "off"]:
self.counting_data[guild_id]["reset_on_fail"] = False
msg = f"{TICK} Counting will now continue on mistakes."
else:
await ctx.send(f"{CROSS} Invalid mode! Use `reset` or `continue`.")
return
self.save_data()
await ctx.send(view=CV2("Counting", msg))
@counting.command(name="reset")
@commands.has_permissions(manage_channels=True)
async def reset(self, ctx):
guild_id = str(ctx.guild.id)
if not self.is_enabled(guild_id):
await self.not_enabled_embed(ctx)
return
self.counting_data[guild_id]["count"] = 0
self.save_data()
await ctx.send(view=CV2("Counting", f"{NEXT} Counting has been reset to 0!"))
@counting.command(name="stats")
async def stats(self, ctx):
guild_id = str(ctx.guild.id)
if not self.is_enabled(guild_id):
await self.not_enabled_embed(ctx)
return
data = self.counting_data[guild_id]
channel = ctx.guild.get_channel(data["channel"]) if data["channel"] else None
channel_str = channel.mention if channel else "Not Set"
reset_str = f"{TICK} Yes" if data["reset_on_fail"] else f"{CROSS} No"
await ctx.send(view=CV2(
f"{BOOK} Counting Stats",
f"**Current Count:** {data['count']}\n"
f"**Channel:** {channel_str}\n"
f"**Reset on Mistake:** {reset_str}"
))
@commands.Cog.listener()
async def on_message(self, message):
if message.author.bot:
return
guild_id = str(message.guild.id)
if guild_id not in self.counting_data:
return
data = self.counting_data[guild_id]
if not data.get("enabled", False):
return
if message.channel.id != data.get("channel"):
return
content = message.content.strip()
if not content.isdigit():
msg = await message.channel.send(f"{WARNING} Alphabet not allowed!")
await asyncio.sleep(3)
await msg.delete()
await message.delete()
return
number = int(content)
expected_number = data.get("count", 0) + 1
if number != expected_number:
msg = await message.channel.send(f"{CROSS} Wrong number entered! Expected number is **{expected_number}**")
await asyncio.sleep(3)
await msg.delete()
await message.delete()
if data.get("reset_on_fail", False):
self.counting_data[guild_id]["count"] = 0
self.save_data()
return
# Correct number
self.counting_data[guild_id]["count"] = number
self.save_data()
await message.add_reaction(TICK)
def setup(bot):
bot.add_cog(Counting(bot))

View File

@@ -0,0 +1,557 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import CROSS, TICK, ZWARNING
from discord import app_commands
from discord.ext import commands
from discord.ext.commands import Context
import aiosqlite
import asyncio
from utils.Tools import *
from utils.cv2 import CV2, build_container
from typing import List, Tuple
from discord.ui import LayoutView, TextDisplay, Separator, Container
from utils.config import *
DATABASE_PATH = 'db/customrole.db'
DATABASE_PATH2 = 'db/np.db'
class Customrole(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.cooldown = {}
self.rate_limit = {}
self.rate_limit_timeout = 5
self.bot.loop.create_task(self.create_tables())
async def reset_rate_limit(self, user_id):
await asyncio.sleep(self.rate_limit_timeout)
self.rate_limit.pop(user_id, None)
async def add_role(self, *, role_id: int, member: discord.Member):
if member.guild.me.guild_permissions.manage_roles:
role = discord.Object(id=role_id)
await member.add_roles(role, reason=f"{BRAND_NAME} Customrole | Role Added")
else:
raise discord.Forbidden("Bot does not have permission to manage roles.")
async def remove_role(self, *, role_id: int, member: discord.Member):
if member.guild.me.guild_permissions.manage_roles:
role = discord.Object(id=role_id)
await member.remove_roles(role, reason=f"{BRAND_NAME} Customrole | Role Removed")
else:
raise discord.Forbidden("Bot does not have permission to manage roles.")
async def add_role2(self, *, role: int, member: discord.Member):
if member.guild.me.guild_permissions.manage_roles:
role = discord.Object(id=int(role))
await member.add_roles(role, reason=f"{BRAND_NAME} Customrole | Role Added ")
async def remove_role2(self, *, role: int, member: discord.Member):
if member.guild.me.guild_permissions.manage_roles:
role = discord.Object(id=int(role))
await member.remove_roles(role, reason=f"{BRAND_NAME} Customrole| Role Removed")
async def handle_role_command(self, context: Context, member: discord.Member, role_type: str):
async with aiosqlite.connect('db/customrole.db') as db:
async with db.execute(f"SELECT reqrole, {role_type} FROM roles WHERE guild_id = ?", (context.guild.id,)) as cursor:
data = await cursor.fetchone()
if data:
reqrole_id, role_id = data
reqrole = context.guild.get_role(reqrole_id)
role = context.guild.get_role(role_id)
if reqrole:
if context.author == context.guild.owner or reqrole in context.author.roles:
if role:
if role not in member.roles:
await self.add_role2(role=role_id, member=member)
await context.reply(view=CV2(f"{TICK} Success", f"**Given** <@&{role.id}> To {member.mention}"))
else:
await self.remove_role2(role=role_id, member=member)
await context.reply(view=CV2(f"{TICK} Success", f"**Removed** <@&{role.id}> From {member.mention}"))
else:
await context.reply(view=CV2(f"{CROSS} Error", f"{role_type.capitalize()} role is not set up in {context.guild.name}"))
else:
await context.reply(view=CV2(f"{ZWARNING} Access Denied", f"You need {reqrole.mention} to run this command."))
else:
await context.reply(view=CV2(f"{ZWARNING} Access Denied", f"Required role is not set up in {context.guild.name}"))
else:
await context.reply(view=CV2(f"{CROSS} Error", f"Roles configuration is not set up in {context.guild.name}"))
async def create_tables(self):
async with aiosqlite.connect(DATABASE_PATH) as db:
await db.execute('''
CREATE TABLE IF NOT EXISTS roles (
guild_id INTEGER PRIMARY KEY,
staff INTEGER,
girl INTEGER,
vip INTEGER,
guest INTEGER,
frnd INTEGER,
reqrole INTEGER
)
''')
await db.execute('''
CREATE TABLE IF NOT EXISTS custom_roles (
guild_id INTEGER,
name TEXT,
role_id INTEGER,
PRIMARY KEY (guild_id, name)
)
''')
await db.commit()
@commands.hybrid_group(name="setup",
description="Setups custom roles for the server.",
help="Setups custom roles for the server.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def set(self, context: Context):
if context.subcommand_passed is None:
await context.send_help(context.command)
context.command.reset_cooldown(context)
async def fetch_role_data(self, guild_id):
async with aiosqlite.connect(DATABASE_PATH) as db:
async with db.execute("SELECT staff, girl, vip, guest, frnd, reqrole FROM roles WHERE guild_id = ?", (guild_id,)) as cursor:
return await cursor.fetchone()
async def update_role_data(self, guild_id, column, value):
try:
async with aiosqlite.connect(DATABASE_PATH) as db:
await db.execute(f"INSERT OR REPLACE INTO roles (guild_id, {column}) VALUES (?, ?) ON CONFLICT(guild_id) DO UPDATE SET {column} = ?",
(guild_id, value, value))
await db.commit()
except Exception as e:
print(f"Error updating role data: {e}")
async def fetch_custom_role_data(self, guild_id):
async with aiosqlite.connect(DATABASE_PATH) as db:
async with db.execute("SELECT name, role_id FROM custom_roles WHERE guild_id = ?", (guild_id,)) as cursor:
return await cursor.fetchall()
@set.command(name="staff",
description="Setup staff role in guild",
help="Setup staff role in Guild")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
@app_commands.describe(role="Role to be added")
async def staff(self, context: Context, role: discord.Role) -> None:
if context.author == context.guild.owner or context.author.top_role.position > context.guild.me.top_role.position:
await self.update_role_data(context.guild.id, 'staff', role.id)
await context.reply(view=CV2(f"{TICK} Success", f"Added {role.mention} to `Staff` Role\n\n__**How to Use?**__\nUse `staff <user>` Command to **Add {role.mention}** role to User & use again to the same user to **Remove role**."))
else:
await context.reply(view=CV2(f"{ZWARNING} Access Denied", "Your role should be above my top role."))
@set.command(name="girl",
description="Setup girl role in the Guild",
help="Setup girl role in the Guild")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
@app_commands.describe(role="Role to be added")
async def girl(self, context: Context, role: discord.Role) -> None:
if context.author == context.guild.owner or context.author.top_role.position > context.guild.me.top_role.position:
await self.update_role_data(context.guild.id, 'girl', role.id)
await context.reply(view=CV2(f"{TICK} Success", f"Added {role.mention} to `Girl` Role\n\n__**How to Use?**__\nUse `girl <user>` Command to **Add {role.mention}** role to User & use again to the same user to **Remove role**."))
else:
await context.reply(view=CV2(f"{ZWARNING} Access Denied", "Your role should be above my top role."))
@set.command(name="vip",
description="Setups vip role in the Guild",
help="Setups vip role in the Guild")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
@app_commands.describe(role="Role to be added")
async def vip(self, context: Context, role: discord.Role) -> None:
if context.author == context.guild.owner or context.author.top_role.position > context.guild.me.top_role.position:
await self.update_role_data(context.guild.id, 'vip', role.id)
await context.reply(view=CV2(f"{TICK} Success", f"Added {role.mention} to `VIP` Role\n\n__**How to Use?**__\nUse `vip <user>` Command to **Add {role.mention}** role to User & use again to the same user to **Remove role**."))
else:
await context.reply(view=CV2(f"{ZWARNING} Access Denied", "Your role should be above my top role."))
@set.command(name="guest",
description="Setup guest role in the Guild",
help="Setup guest role in the Guild")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
@app_commands.describe(role="Role to be added")
async def guest(self, context: Context, role: discord.Role) -> None:
if context.author == context.guild.owner or context.author.top_role.position > context.guild.me.top_role.position:
await self.update_role_data(context.guild.id, 'guest', role.id)
await context.reply(view=CV2(f"{TICK} Success", f"Added {role.mention} to `Guest` Role\n\n__**How to Use?**__\nUse `guest <user>` Command to **Add {role.mention}** role to User & use again to the same user to **Remove role**."))
else:
await context.reply(view=CV2(f"{ZWARNING} Access Denied", "Your role should be above my top role."))
@set.command(name="friend",
description="Setup friend role in the Guild",
help="Setup friend role in the Guild")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
@app_commands.describe(role="Role to be added")
async def friend(self, context: Context, role: discord.Role) -> None:
if context.author == context.guild.owner or context.author.top_role.position > context.guild.me.top_role.position:
await self.update_role_data(context.guild.id, 'frnd', role.id)
await context.reply(view=CV2(f"{TICK} Success", f"Added {role.mention} to `Friend` Role\n\n__**How to Use?**__\nUse `friend <user>` Command to **Add {role.mention}** role to User & use again to the same user to **Remove role**."))
else:
await context.reply(view=CV2(f"{ZWARNING} Access Denied", "Your role should be above my top role."))
@set.command(name="reqrole",
description="Setup required role for custom role commands",
help="Setup required role for custom role commands")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 4, commands.BucketType.user)
@commands.has_permissions(administrator=True)
@app_commands.describe(role="Role to be added")
async def req_role(self, context: Context, role: discord.Role) -> None:
if context.author == context.guild.owner or context.author.top_role.position > context.guild.me.top_role.position:
await self.update_role_data(context.guild.id, 'reqrole', role.id)
await context.reply(view=CV2(f"{TICK} Success", f"Added {role.mention} for Required role to run custom role commands in {context.guild.name}"))
else:
await context.reply(view=CV2(f"{ZWARNING} Access Denied", "Your role should be above my top role."))
@set.command(name="config",
description="Shows the current custom role configuration in the Guild.",
help="Shows the current custom role configuration in the Guild.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def config(self, context: Context) -> None:
role_data = await self.fetch_role_data(context.guild.id)
if role_data:
staff = context.guild.get_role(role_data[0]).mention if role_data[0] else "None"
girl = context.guild.get_role(role_data[1]).mention if role_data[1] else "None"
vip = context.guild.get_role(role_data[2]).mention if role_data[2] else "None"
guest = context.guild.get_role(role_data[3]).mention if role_data[3] else "None"
friend = context.guild.get_role(role_data[4]).mention if role_data[4] else "None"
reqrole = context.guild.get_role(role_data[5]).mention if role_data[5] else "None"
config_text = (
f"**Staff Role:** {staff}\n"
f"**Girl Role:** {girl}\n"
f"**VIP Role:** {vip}\n"
f"**Guest Role:** {guest}\n"
f"**Friend Role:** {friend}\n"
f"**Required Role:** {reqrole}\n\n"
"Use Commands to assign role & use again to the same user to remove role."
)
await context.reply(view=CV2("Custom Role Configuration", config_text))
else:
await context.reply(view=CV2(f"{CROSS} Error", "No custom role configuration found in this Guild."))
@set.command(name="create",
description="Creates a custom role command.",
help="Creates a custom role command")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_permissions(administrator=True)
@app_commands.describe(name="Command name", role="Role to be assigned")
async def create(self, context: Context, name: str, role: discord.Role) -> None:
async with aiosqlite.connect(DATABASE_PATH) as db:
async with db.execute("SELECT COUNT(*) FROM custom_roles WHERE guild_id = ?", (context.guild.id,)) as cursor:
count = await cursor.fetchone()
if count[0] >= 56:
await context.reply(view=CV2(f"{ZWARNING} Limit Reached", "You have reached the maximum limit of 56 custom role commands for this guild."))
return
async with db.execute("SELECT name FROM custom_roles WHERE guild_id = ?", (context.guild.id,)) as cursor:
existing_role = await cursor.fetchall()
if any(name == row[0] for row in existing_role):
await context.reply(view=CV2(f"{CROSS} Error", f"A custom role command with the name `{name}` already exists in this guild. Remove it before creating a new one."))
return
await db.execute("INSERT INTO custom_roles (guild_id, name, role_id) VALUES (?, ?, ?)",
(context.guild.id, name, role.id))
await db.commit()
await context.reply(view=CV2(f"{TICK} Success", f"Custom role command `{name}` created to assign the role {role.mention}.\n\n__**How to Use?**__\nUse `{name} <user>` Command to Assign/Remove {role.mention} role to User.\n> This will work for the users having `Manage Roles` permissions."))
@set.command(name="delete", aliases=["remove"],
description="Deletes a custom role command.",
help="Deletes a custom role command.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_permissions(administrator=True)
@app_commands.describe(name="Command name to be deleted")
async def delete(self, context: Context, name: str) -> None:
async with aiosqlite.connect(DATABASE_PATH) as db:
async with db.execute("SELECT name FROM custom_roles WHERE guild_id = ? AND name = ?", (context.guild.id, name)) as cursor:
existing_role = await cursor.fetchone()
if not existing_role:
await context.reply(view=CV2(f"{CROSS} Error", f"No custom role command with the name `{name}` was found in this guild."))
return
async with aiosqlite.connect(DATABASE_PATH) as db:
await db.execute("DELETE FROM custom_roles WHERE guild_id = ? AND name = ?", (context.guild.id, name))
await db.commit()
await context.reply(view=CV2(f"{TICK} Success", f"Custom role command `{name}` has been deleted."))
@set.command(
name="list",
description="List all the custom roles setup for the server.",
help="List all the custom roles setup for the server."
)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def list(self, context: Context) -> None:
custom_roles = await self.fetch_custom_role_data(context.guild.id)
if not custom_roles:
await context.reply(view=CV2(f"{CROSS} Error", "No custom roles have been created for this server."))
return
def chunk_list(data: List[Tuple[str, int]], chunk_size: int):
"""Yield successive chunks of `chunk_size` from `data`."""
for i in range(0, len(data), chunk_size):
yield data[i:i + chunk_size]
chunks = list(chunk_list(custom_roles, 7))
for i, chunk in enumerate(chunks):
roles_text = ""
for name, role_id in chunk:
role = context.guild.get_role(role_id)
if role:
roles_text += f"**{name}** → {role.mention}\n"
footer = f"Page {i+1}/{len(chunks)} | These commands are usable by Members having Manage Role permissions."
await context.reply(view=CV2("Custom Roles", roles_text, footer))
@set.command(name="reset",
description="Resets custom role configuration for the server.",
help="Resets custom role configuration for the server.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 4, commands.BucketType.user)
@commands.has_permissions(administrator=True)
async def reset(self, context: Context) -> None:
if context.author == context.guild.owner or context.author.top_role.position > context.guild.me.top_role.position:
removed_roles = []
role_data = await self.fetch_role_data(context.guild.id)
if role_data:
roles = ["staff", "girl", "vip", "guest", "frnd", "reqrole"]
for i, role_name in enumerate(roles):
role_id = role_data[i]
if role_id:
role = context.guild.get_role(role_id)
if role:
removed_roles.append(f"**{role_name.capitalize()}:** {role.mention}")
await self.update_role_data(context.guild.id, role_name, None)
async with aiosqlite.connect(DATABASE_PATH) as db:
await db.execute("DELETE FROM custom_roles WHERE guild_id = ?", (context.guild.id,))
await db.commit()
reset_desc = f"Deleted All Custom Role commands {TICK}\n\n**Removed Roles:**\n" + "\n".join(removed_roles) if removed_roles else "No roles were previously set."
await context.reply(view=CV2("Custom Role Configuration Reset", reset_desc))
else:
await context.reply(view=CV2("Info", "No configuration found for this server."))
else:
await context.reply(view=CV2(f"{ZWARNING} Access Denied", "Your role should be above my top role."))
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
if message.author.bot or not message.content:
return
prefixes = await self.bot.get_prefix(message)
if not prefixes:
return
if not any(message.content.startswith(prefix) for prefix in prefixes):
return
for prefix in prefixes:
if message.content.startswith(prefix):
command_name = message.content[len(prefix):].split()[0]
break
else:
return
guild_id = message.guild.id
async with aiosqlite.connect(DATABASE_PATH) as db:
async with db.execute("SELECT role_id FROM custom_roles WHERE guild_id = ? AND name = ?", (guild_id, command_name)) as cursor:
result = await cursor.fetchone()
if result:
role_id = result[0]
role = message.guild.get_role(role_id)
async with aiosqlite.connect(DATABASE_PATH) as db:
async with db.execute("SELECT reqrole FROM roles WHERE guild_id = ?", (guild_id,)) as cursor:
reqrole_result = await cursor.fetchone()
reqrole_id = reqrole_result[0] if reqrole_result else None
reqrole = message.guild.get_role(reqrole_id) if reqrole_id else None
if reqrole is None:
await message.channel.send(f"{ZWARNING} The required role is not set up in this server. Please set it up using `setup reqrole`.")
return
if reqrole not in message.author.roles:
await message.channel.send(view=CV2(f"{ZWARNING} Access Denied", f"You need the {reqrole.mention} role to use this command."))
return
member = message.mentions[0] if message.mentions else None
if not member:
await message.channel.send("Please mention a user to assign the role.")
return
now = asyncio.get_event_loop().time()
if guild_id not in self.cooldown or now - self.cooldown[guild_id] >= 10:
self.cooldown[guild_id] = now
else:
await message.channel.send("You're on a cooldown of 5 seconds. Please wait before sending another command.", delete_after=5)
return
try:
if role in member.roles:
await self.remove_role(role_id=role_id, member=member)
await message.channel.send(view=CV2(f"{TICK} Success", f"**Removed** the role {role.mention} from {member.mention}."))
else:
await self.add_role(role_id=role_id, member=member)
await message.channel.send(view=CV2(f"{TICK} Success", f"**Added** the role {role.mention} to {member.mention}."))
except discord.Forbidden as e:
await message.channel.send("I do not have permission to manage this role to the given user.")
print(f"Error: {e}")
else:
return
@commands.hybrid_command(name="staff",
description="Gives the staff role to the user.",
aliases=['official'],
help="Gives the staff role to the user.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
#@commands.has_permissions(manage_roles=True)
async def _staff(self, context: Context, member: discord.Member) -> None:
await self.handle_role_command(context, member, 'staff')
@commands.hybrid_command(name="girl",
description="Gives the girl role to the user.",
aliases=['qt'],
help="Gives the girl role to the user.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
#@commands.has_permissions(manage_roles=True)
async def _girl(self, context: Context, member: discord.Member) -> None:
await self.handle_role_command(context, member, 'girl')
@commands.hybrid_command(name="vip",
description="Gives the VIP role to the user.",
help="Gives the VIP role to the user.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
#@commands.has_permissions(manage_roles=True)
async def _vip(self, context: Context, member: discord.Member) -> None:
await self.handle_role_command(context, member, 'vip')
@commands.hybrid_command(name="guest",
description="Gives the guest role to the user.",
help="Gives the guest role to the user.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
#@commands.has_permissions(manage_roles=True)
async def _guest(self, context: Context, member: discord.Member) -> None:
await self.handle_role_command(context, member, 'guest')
@commands.hybrid_command(name="friend",
description="Gives the friend role to the user.",
aliases=['frnd'],
help="Gives the friend role to the user.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
#@commands.has_permissions(manage_roles=True)
async def _friend(self, context: Context, member: discord.Member) -> None:
await self.handle_role_command(context, member, 'frnd')

115
bot/cogs/commands/dms.py Normal file
View File

@@ -0,0 +1,115 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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.ui import LayoutView, TextDisplay, Separator, Container, Button, ActionRow
from discord.ext import commands
from utils.cv2 import CV2, build_container
from utils.config import STAFF_IDS
class SuccessView(LayoutView):
def __init__(self, member):
super().__init__(timeout=None)
self.member = member
self.add_item(
build_container(
TextDisplay("**Message Sent**"),
Separator(visible=True),
TextDisplay(
f"✅ Your message has been successfully sent to **{member.name}**"
),
)
)
class ErrorView(LayoutView):
def __init__(self, member):
super().__init__(timeout=None)
self.member = member
self.add_item(
build_container(
TextDisplay("**Delivery Failed**"),
Separator(visible=True),
TextDisplay(
f"❌ Could not send the message. **{member.name}** may have their DMs disabled."
),
)
)
class GenericErrorView(LayoutView):
def __init__(self, error):
super().__init__(timeout=None)
self.error = error
self.add_item(
build_container(
TextDisplay("**Error Occurred**"),
Separator(visible=True),
TextDisplay(f"🤔 Something went wrong. Error: {error}"),
)
)
class PermissionErrorView(LayoutView):
def __init__(self):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay("**Permission Denied**"),
Separator(visible=True),
TextDisplay("❌ You do not have permission to use this command."),
)
)
class StaffDMCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(name="dmstaff")
async def dm_staff(self, ctx, member: discord.Member, *, message: str):
if ctx.author.id not in STAFF_IDS:
view = PermissionErrorView()
await ctx.reply(view=view)
return
try:
embed = discord.Embed(
title="📢 A Message from the Staff Team",
description=message,
color=0xFF0000,
)
embed.set_footer(text=f"This message was sent by {ctx.author.name}.")
await member.send(embed=embed)
view = SuccessView(member)
await ctx.reply(view=view)
except discord.Forbidden:
view = ErrorView(member)
await ctx.reply(view=view)
except Exception as e:
view = GenericErrorView(str(e))
await ctx.reply(view=view)
print(f"Error in dmstaff command: {e}")
async def setup(bot):
await bot.add_cog(StaffDMCog(bot))

View File

@@ -0,0 +1,803 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import CROSS, CROSS_ALT, ML_CROSS, TICK, TICK_ALT, ZWARNING
from discord.ui import LayoutView, TextDisplay, Separator, Container, Button, ActionRow
from discord.ext import commands
import aiosqlite
from utils.Tools import *
from utils.cv2 import CV2, build_container
from utils.config import OWNER_IDS_STR
class EmergencyRestoreConfirmView(LayoutView):
def __init__(self, ctx):
super().__init__(timeout=60)
self.ctx = ctx
self.value = None
self.yes_btn = Button(label="Yes", style=discord.ButtonStyle.green)
self.no_btn = Button(label="No", style=discord.ButtonStyle.danger)
self.yes_btn.callback = self.confirm_callback
self.no_btn.callback = self.cancel_callback
self.add_item(
build_container(
TextDisplay("**Confirm Restoration**"),
Separator(visible=True),
TextDisplay(
"This will restore previously disabled permissions for emergency roles. Do you want to proceed?"
),
ActionRow(self.yes_btn, self.no_btn),
)
)
async def confirm_callback(self, interaction: discord.Interaction):
if interaction.user.id != self.ctx.author.id:
return await interaction.response.send_message(
"Only the Server Owner can use this button.", ephemeral=True
)
self.value = True
await interaction.response.defer()
self.stop()
async def cancel_callback(self, interaction: discord.Interaction):
if interaction.user.id != self.ctx.author.id:
return await interaction.response.send_message(
"Only the Server Owner can use this button.", ephemeral=True
)
self.value = False
await interaction.response.defer()
self.stop()
class EmergencyMainView(LayoutView):
def __init__(self, ctx, prefix):
super().__init__(timeout=None)
self.prefix = prefix
self.add_item(
build_container(
TextDisplay("__Emergency Situation__"),
Separator(visible=True),
TextDisplay(
f"The `emergency` command group is designed to protect your server from malicious activity or accidental damage.\n\n"
f"**The command group has several subcommands:**\n\n"
f"`{prefix}emergency enable` - Enable emergency mode\n"
f"`{prefix}emergency disable` - Disable emergency mode\n"
f"`{prefix}emergency authorise` - Manage authorized users\n"
f"`{prefix}emergency role` - Manage roles in emergency list\n"
f"`{prefix}emergency-situation` - Execute emergency situation"
),
)
)
class EnableSuccessView(LayoutView):
def __init__(self, roles_added):
super().__init__(timeout=None)
content = (
"\n".join([f"{r.mention}" for r in roles_added])
if roles_added
else "No new roles with dangerous permissions were found."
)
self.add_item(
build_container(
TextDisplay(f"**{TICK} Success**"),
Separator(visible=True),
TextDisplay(content),
)
)
class EnableErrorView(LayoutView):
def __init__(self):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay(f"**{CROSS} Error**"),
Separator(visible=True),
TextDisplay("Only the server owner can enable emergency mode."),
)
)
class DisableSuccessView(LayoutView):
def __init__(self):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay(f"**{TICK_ALT} Success**"),
Separator(visible=True),
TextDisplay(
"Emergency mode has been disabled, and all emergency roles have been cleared."
),
)
)
class DisableErrorView(LayoutView):
def __init__(self):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay(f"**{CROSS_ALT} Error**"),
Separator(visible=True),
TextDisplay("Only the server owner can disable emergency mode."),
)
)
class AuthoriseSuccessView(LayoutView):
def __init__(self, member_name, action):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay(f"**{TICK_ALT} Success**"),
Separator(visible=True),
TextDisplay(f"**{member_name}** has been {action}."),
)
)
class AuthoriseErrorView(LayoutView):
def __init__(self, error_type):
super().__init__(timeout=None)
content = {
"owner_add": "Only the server owner can add authorised users.",
"owner_remove": "Only the server owner can remove authorised users.",
"owner_list": "Only the server owner can view the list.",
"limit": "Only up to 5 authorised users can be added.",
"exists": "This user is already authorised.",
"not_found": "This user is not authorised.",
}.get(error_type, "An error occurred.")
is_warning = error_type == "limit"
self.add_item(
build_container(
TextDisplay(
f"**{ZWARNING} Access Denied**"
if is_warning
else f"**{CROSS_ALT} Error**"
),
Separator(visible=True),
TextDisplay(content),
)
)
class AuthoriseListView(LayoutView):
def __init__(self, ctx, users, is_owner):
super().__init__(timeout=None)
if not is_owner:
self.add_item(
build_container(
TextDisplay(f"**{ZWARNING} Access Denied**"),
Separator(visible=True),
TextDisplay("Only the server owner can view the list."),
)
)
elif not users:
self.add_item(
build_container(
TextDisplay("**Authorized Users**"),
Separator(visible=True),
TextDisplay("No authorized users found."),
)
)
else:
desc = "\n".join(
[
f"{i + 1}. [{ctx.guild.get_member(u[0]).name}](https://discord.com/users/{u[0]}) - {u[0]}"
for i, u in enumerate(users)
]
)
self.add_item(
build_container(
TextDisplay("**Authorized Users**"),
Separator(visible=True),
TextDisplay(desc),
)
)
class RoleSuccessView(LayoutView):
def __init__(self, role_name, action):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay(f"**{TICK_ALT} Success**"),
Separator(visible=True),
TextDisplay(f"**{role_name}** has been {action} the emergency list."),
)
)
class RoleErrorView(LayoutView):
def __init__(self, error_type):
super().__init__(timeout=None)
content = {
"owner_add": "Only the server owner can add role for emergency situation.",
"owner_remove": "Only the server owner can remove roles from emergency list.",
"owner_list": "You are not authorised to view list of roles.",
"limit": "Only up to 25 roles can be added.",
"exists": "This role is already in the emergency list.",
"not_found": "This role is not in the emergency list.",
}.get(error_type, "An error occurred.")
is_warning = error_type == "limit"
self.add_item(
build_container(
TextDisplay(
f"**{ZWARNING} Error**"
if is_warning
else f"**{CROSS_ALT} Error**"
),
Separator(visible=True),
TextDisplay(content),
)
)
class RoleListView(LayoutView):
def __init__(self, roles, is_authorised):
super().__init__(timeout=None)
if not is_authorised:
self.add_item(
build_container(
TextDisplay(f"**{ZWARNING} Access Denied**"),
Separator(visible=True),
TextDisplay("You are not authorised to view list of roles."),
)
)
elif not roles:
self.add_item(
build_container(
TextDisplay("**Emergency Roles**"),
Separator(visible=True),
TextDisplay("No roles added for emergency situation."),
)
)
else:
desc = "\n".join(
[f"{i + 1}. <@&{r[0]}> - {r[0]}" for i, r in enumerate(roles)]
)
self.add_item(
build_container(
TextDisplay("**Emergency Roles**"),
Separator(visible=True),
TextDisplay(desc),
)
)
class EmergencySituationErrorView(LayoutView):
def __init__(self, error_type):
super().__init__(timeout=None)
content = (
"You are not authorised to execute the emergency situation."
if error_type == "access"
else "No roles have been added for the emergency situation."
)
self.add_item(
build_container(
TextDisplay(
f"**{ZWARNING} Access Denied**"
if error_type == "access"
else f"**{CROSS_ALT} Error**"
),
Separator(visible=True),
TextDisplay(content),
)
)
class EmergencySituationResultView(LayoutView):
def __init__(
self,
success_msg,
error_msg,
moved_role=None,
move_failed=False,
move_error=None,
):
super().__init__(timeout=None)
desc = f"**{TICK_ALT} Roles Modified**:\n{success_msg}\n\n"
if moved_role:
desc += f"**{ZWARNING} Role Moved**: {moved_role.mention} moved below bot's top role.\n\n"
elif move_failed:
desc += "** Role Couldn't Moved**: Permission error.\n\n"
elif move_error:
desc += f"** Role Couldn't Moved**: {move_error}\n\n"
desc += f"**Errors**: {error_msg}"
self.add_item(
build_container(
TextDisplay("**Emergency Situation**"),
Separator(visible=True),
TextDisplay(desc),
)
)
class EmergencyRestoreAccessErrorView(LayoutView):
def __init__(self):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay(f"**{ZWARNING} Access Denied**"),
Separator(visible=True),
TextDisplay(
"Only the server owner can execute the emergency restore command."
),
)
)
class EmergencyRestoreNoRolesView(LayoutView):
def __init__(self):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay(f"**{CROSS_ALT} Error**"),
Separator(visible=True),
TextDisplay(
"No roles were found with disabled permissions for restore."
),
)
)
class EmergencyRestoreResultView(LayoutView):
def __init__(self, success_msg, error_msg):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay("**Emergency Restore**"),
Separator(visible=True),
TextDisplay(
f"**{TICK_ALT} Permissions Restored**:\n{success_msg}\n\n**{ML_CROSS} Errors**:\n{error_msg}\n\nDatabase cleared."
),
)
)
class Emergency(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.db_path = "db/emergency.db"
self.bot.loop.create_task(self.initialize_database())
async def initialize_database(self):
async with aiosqlite.connect(self.db_path) as db:
await db.execute(
"CREATE TABLE IF NOT EXISTS authorised_users (guild_id INTEGER, user_id INTEGER)"
)
await db.execute(
"CREATE TABLE IF NOT EXISTS emergency_roles (guild_id INTEGER, role_id INTEGER)"
)
await db.execute(
"CREATE TABLE IF NOT EXISTS restore_roles (guild_id INTEGER NOT NULL, role_id INTEGER NOT NULL, disabled_perms TEXT NOT NULL, PRIMARY KEY (guild_id, role_id))"
)
await db.execute(
"CREATE TABLE IF NOT EXISTS role_positions (guild_id INTEGER, role_id INTEGER, previous_position INTEGER)"
)
await db.commit()
async def is_guild_owner(self, ctx):
return ctx.guild and ctx.author.id == ctx.guild.owner_id
async def is_guild_owner_or_authorised(self, ctx):
if await self.is_guild_owner(ctx):
return True
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT 1 FROM authorised_users WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, ctx.author.id),
) as cursor:
return await cursor.fetchone() is not None
@commands.group(name="emergency", aliases=["emg"], invoke_without_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 4, commands.BucketType.user)
@commands.guild_only()
async def emergency(self, ctx):
await ctx.reply(view=EmergencyMainView(ctx, ctx.prefix))
@emergency.command(name="enable")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 4, commands.BucketType.user)
@commands.guild_only()
async def enable(self, ctx):
if ctx.author.id != ctx.guild.owner_id and str(ctx.author.id) not in OWNER_IDS_STR:
return await ctx.reply(view=EnableErrorView())
dangerous_perms = [
"administrator",
"ban_members",
"kick_members",
"manage_channels",
"manage_roles",
"manage_guild",
]
roles_added = []
async with aiosqlite.connect(self.db_path) as db:
for role in ctx.guild.roles:
if (
role.managed
or role.is_bot_managed()
or role.position >= ctx.guild.me.top_role.position
):
continue
if any(getattr(role.permissions, p, False) for p in dangerous_perms):
async with db.execute(
"SELECT 1 FROM emergency_roles WHERE guild_id = ? AND role_id = ?",
(ctx.guild.id, role.id),
) as cursor:
if not await cursor.fetchone():
await db.execute(
"INSERT INTO emergency_roles (guild_id, role_id) VALUES (?, ?)",
(ctx.guild.id, role.id),
)
roles_added.append(role)
await db.commit()
await ctx.reply(view=EnableSuccessView(roles_added))
@emergency.command(name="disable")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 4, commands.BucketType.user)
@commands.guild_only()
async def disable(self, ctx):
if ctx.author.id != ctx.guild.owner_id and str(ctx.author.id) not in OWNER_IDS_STR:
return await ctx.reply(view=DisableErrorView())
async with aiosqlite.connect(self.db_path) as db:
await db.execute(
"DELETE FROM emergency_roles WHERE guild_id = ?", (ctx.guild.id,)
)
await db.commit()
await ctx.reply(view=DisableSuccessView())
@emergency.group(name="authorise", aliases=["ath"], invoke_without_command=True)
@blacklist_check()
@ignore_check()
@commands.guild_only()
async def authorise(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@authorise.command(name="add")
@blacklist_check()
@ignore_check()
@commands.guild_only()
async def authorise_add(self, ctx, member: discord.Member):
if not await self.is_guild_owner(ctx):
return await ctx.reply(view=AuthoriseErrorView("owner_add"))
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT COUNT(*) FROM authorised_users WHERE guild_id = ?",
(ctx.guild.id,),
) as cursor:
if (await cursor.fetchone())[0] >= 5:
return await ctx.reply(view=AuthoriseErrorView("limit"))
async with db.execute(
"SELECT 1 FROM authorised_users WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, member.id),
) as cursor:
if await cursor.fetchone():
return await ctx.reply(view=AuthoriseErrorView("exists"))
await db.execute(
"INSERT INTO authorised_users (guild_id, user_id) VALUES (?, ?)",
(ctx.guild.id, member.id),
)
await db.commit()
await ctx.reply(view=AuthoriseSuccessView(member.display_name, "authorised"))
@authorise.command(name="remove")
@blacklist_check()
@ignore_check()
@commands.guild_only()
async def authorise_remove(self, ctx, member: discord.Member):
if not await self.is_guild_owner(ctx):
return await ctx.reply(view=AuthoriseErrorView("owner_remove"))
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT 1 FROM authorised_users WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, member.id),
) as cursor:
if not await cursor.fetchone():
return await ctx.reply(view=AuthoriseErrorView("not_found"))
await db.execute(
"DELETE FROM authorised_users WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, member.id),
)
await db.commit()
await ctx.reply(view=AuthoriseSuccessView(member.display_name, "removed"))
@authorise.command(name="list", aliases=["view"])
@blacklist_check()
@ignore_check()
@commands.guild_only()
async def list_authorized(self, ctx):
is_owner = await self.is_guild_owner(ctx)
if not is_owner:
return await ctx.reply(view=AuthoriseErrorView("owner_list"))
async with aiosqlite.connect("db/emergency.db") as db:
cursor = await db.execute(
"SELECT user_id FROM authorised_users WHERE guild_id = ?",
(ctx.guild.id,),
)
users = await cursor.fetchall()
await ctx.reply(view=AuthoriseListView(ctx, users, is_owner))
@emergency.group(name="role", invoke_without_command=True)
@blacklist_check()
@ignore_check()
@commands.guild_only()
async def role(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@role.command(name="add")
@blacklist_check()
@ignore_check()
@commands.guild_only()
async def role_add(self, ctx, role: discord.Role):
if not await self.is_guild_owner(ctx):
return await ctx.reply(view=RoleErrorView("owner_add"))
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT COUNT(*) FROM emergency_roles WHERE guild_id = ?",
(ctx.guild.id,),
) as cursor:
if (await cursor.fetchone())[0] >= 25:
return await ctx.reply(view=RoleErrorView("limit"))
async with db.execute(
"SELECT 1 FROM emergency_roles WHERE guild_id = ? AND role_id = ?",
(ctx.guild.id, role.id),
) as cursor:
if await cursor.fetchone():
return await ctx.reply(view=RoleErrorView("exists"))
await db.execute(
"INSERT INTO emergency_roles (guild_id, role_id) VALUES (?, ?)",
(ctx.guild.id, role.id),
)
await db.commit()
await ctx.reply(view=RoleSuccessView(role.name, "added to"))
@role.command(name="remove")
@blacklist_check()
@ignore_check()
@commands.guild_only()
async def role_remove(self, ctx, role: discord.Role):
if not await self.is_guild_owner(ctx):
return await ctx.reply(view=RoleErrorView("owner_remove"))
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT 1 FROM emergency_roles WHERE guild_id = ? AND role_id = ?",
(ctx.guild.id, role.id),
) as cursor:
if not await cursor.fetchone():
return await ctx.reply(view=RoleErrorView("not_found"))
await db.execute(
"DELETE FROM emergency_roles WHERE guild_id = ? AND role_id = ?",
(ctx.guild.id, role.id),
)
await db.commit()
await ctx.reply(view=RoleSuccessView(role.name, "removed from"))
@role.command(name="list", aliases=["view"])
@blacklist_check()
@ignore_check()
@commands.guild_only()
async def list_roles(self, ctx):
is_auth = await self.is_guild_owner_or_authorised(ctx)
if not is_auth:
return await ctx.reply(view=RoleErrorView("owner_list"))
async with aiosqlite.connect("db/emergency.db") as db:
cursor = await db.execute(
"SELECT role_id FROM emergency_roles WHERE guild_id = ?",
(ctx.guild.id,),
)
roles = await cursor.fetchall()
await ctx.reply(view=RoleListView(roles, is_auth))
@commands.command(name="emergencysituation", aliases=["emgs"])
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 40, commands.BucketType.user)
@commands.guild_only()
@commands.bot_has_permissions(manage_roles=True)
async def emergencysituation(self, ctx):
if not await self.is_guild_owner_or_authorised(ctx) and str(
ctx.author.id
) not in OWNER_IDS_STR:
return await ctx.reply(view=EmergencySituationErrorView("access"))
proc_msg = await ctx.reply(
view=LayoutView(build_container(TextDisplay("Processing Emergency Situation...")))
)
guild_id = ctx.guild.id
antinuke_enabled = False
async with aiosqlite.connect("db/anti.db") as anti:
cursor = await anti.execute(
"SELECT status FROM antinuke WHERE guild_id = ?", (guild_id,)
)
row = await cursor.fetchone()
if row:
antinuke_enabled = True
await anti.execute(
"DELETE FROM antinuke WHERE guild_id = ?", (guild_id,)
)
await anti.commit()
async with aiosqlite.connect(self.db_path) as db:
await db.execute(
"DELETE FROM restore_roles WHERE guild_id = ?", (ctx.guild.id,)
)
await db.commit()
cursor = await db.execute(
"SELECT role_id FROM emergency_roles WHERE guild_id = ?",
(ctx.guild.id,),
)
emergency_roles = await cursor.fetchall()
if not emergency_roles:
await proc_msg.delete()
return await ctx.reply(view=EmergencySituationErrorView("no_roles"))
bot_top = ctx.guild.me.top_role
dangerous_perms = [
"administrator",
"ban_members",
"kick_members",
"manage_channels",
"manage_roles",
"manage_guild",
]
modified, unchanged = [], []
async with aiosqlite.connect(self.db_path) as db:
for (role_id,) in emergency_roles:
role = ctx.guild.get_role(role_id)
if not role or role.position >= bot_top.position or role.managed:
unchanged.append(role) if role else None
continue
perms = role.permissions
disabled = []
for p in dangerous_perms:
if getattr(perms, p, False):
setattr(perms, p, False)
disabled.append(p)
if disabled:
try:
await role.edit(permissions=perms, reason="Emergency Situation")
modified.append(role)
await db.execute(
"INSERT INTO restore_roles VALUES (?, ?, ?)",
(ctx.guild.id, role.id, ",".join(disabled)),
)
await db.commit()
except:
unchanged.append(role)
success = "\n".join([r.mention for r in modified]) or "No roles modified."
errors = "\n".join([r.mention for r in unchanged]) or "No errors."
most_mem = max(
[
r
for r in ctx.guild.roles
if not r.managed
and r.position < bot_top.position
and r != ctx.guild.default_role
],
key=lambda r: len(r.members),
default=None,
)
if most_mem:
try:
await most_mem.edit(
position=bot_top.position - 1, reason="Emergency Situation"
)
result_view = EmergencySituationResultView(
success, errors, moved_role=most_mem
)
except discord.Forbidden:
result_view = EmergencySituationResultView(
success, errors, move_failed=True
)
except Exception as e:
result_view = EmergencySituationResultView(
success, errors, move_error=str(e)
)
else:
result_view = EmergencySituationResultView(success, errors)
await ctx.reply(view=result_view)
if antinuke_enabled:
async with aiosqlite.connect("db/anti.db") as anti:
await anti.execute("INSERT INTO antinuke VALUES (?, 1)", (guild_id,))
await anti.commit()
await proc_msg.delete()
@commands.command(name="emergencyrestore", aliases=["emgrestore"])
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 30, commands.BucketType.user)
@commands.guild_only()
@commands.bot_has_permissions(manage_roles=True)
async def emergencyrestore(self, ctx):
if ctx.author.id != ctx.guild.owner_id and str(ctx.author.id) not in OWNER_IDS_STR:
return await ctx.reply(view=EmergencyRestoreAccessErrorView())
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute(
"SELECT role_id, disabled_perms FROM restore_roles WHERE guild_id = ?",
(ctx.guild.id,),
)
restore_roles = await cursor.fetchall()
if not restore_roles:
return await ctx.reply(view=EmergencyRestoreNoRolesView())
view = EmergencyRestoreConfirmView(ctx)
await ctx.send(view=view)
await view.wait()
if view.value is None:
return await ctx.reply(
view=LayoutView(
build_container(TextDisplay("**Restore Cancelled** - Timed out."))
)
)
if view.value is False:
return await ctx.reply(
view=LayoutView(build_container(TextDisplay("**Restore Cancelled**")))
)
modified, unchanged = [], []
async with aiosqlite.connect(self.db_path) as db:
for role_id, perms in restore_roles:
role = ctx.guild.get_role(role_id)
if not role:
continue
rp = role.permissions
restored = False
for p in perms.split(","):
if hasattr(rp, p):
setattr(rp, p, True)
restored = True
if restored:
try:
await role.edit(permissions=rp, reason="Emergency Restore")
modified.append(role)
except:
unchanged.append(role)
await db.execute(
"DELETE FROM restore_roles WHERE guild_id = ?", (ctx.guild.id,)
)
await db.commit()
success = "\n".join([r.mention for r in modified]) or "No roles restored."
errors = "\n".join([r.mention for r in unchanged]) or "No errors."
await ctx.reply(view=EmergencyRestoreResultView(success, errors))
async def setup(bot):
await bot.add_cog(Emergency(bot))

View File

@@ -0,0 +1,224 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import base64
import binascii
import codecs
import secrets
import discord
from discord.ui import LayoutView, TextDisplay, Separator, Container
from discord.ext import commands
from utils.cv2 import CV2, build_container
class EncryptResultView(LayoutView):
def __init__(self, convert, txtinput):
super().__init__(timeout=None)
try:
display_text = txtinput.decode("UTF-8")
except AttributeError:
display_text = str(txtinput)
if len(display_text) > 500:
display_text = display_text[:500] + "..."
self.add_item(
build_container(
TextDisplay(f"📑 **{convert}**"),
Separator(visible=True),
TextDisplay(display_text),
)
)
class DecodeErrorView(LayoutView):
def __init__(self, codec_name):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay(f"❌ **Invalid {codec_name}**"),
Separator(visible=True),
TextDisplay(f"The provided string is not valid {codec_name} encoding."),
)
)
class PasswordSentView(LayoutView):
def __init__(self, author_name):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay("🔐 **Password Generated**"),
Separator(visible=True),
TextDisplay(
f"Sending you a DM with your random generated password **{author_name}**"
),
)
)
class PasswordDMView(LayoutView):
def __init__(self, password):
super().__init__(timeout=None)
self.add_item(
build_container(
TextDisplay("🎁 **Here is your password:**"),
Separator(visible=True),
TextDisplay(password),
)
)
class encryption(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.group(invoke_without_command=True)
async def encode(self, ctx):
"""All encode methods"""
await ctx.send_help(ctx.command)
@commands.group(invoke_without_command=True)
async def decode(self, ctx):
"""All decode methods"""
await ctx.send_help(ctx.command)
async def encryptout(self, ctx, convert, txtinput):
view = EncryptResultView(convert, txtinput)
await ctx.send(view=view)
@encode.command(name="base32", aliases=["b32"])
async def encode_base32(self, ctx, *, txtinput: commands.clean_content):
"""Encode in base32"""
await self.encryptout(
ctx, "Text -> base32", base64.b32encode(txtinput.encode("UTF-8"))
)
@decode.command(name="base32", aliases=["b32"])
async def decode_base32(self, ctx, *, txtinput: str):
"""Decode in base32"""
try:
await self.encryptout(
ctx, "base32 -> Text", base64.b32decode(txtinput.encode("UTF-8"))
)
except Exception:
await ctx.send(view=DecodeErrorView("base32"))
@encode.command(name="base64", aliases=["b64"])
async def encode_base64(self, ctx, *, txtinput: commands.clean_content):
"""Encode in base64"""
await self.encryptout(
ctx, "Text -> base64", base64.urlsafe_b64encode(txtinput.encode("UTF-8"))
)
@decode.command(name="base64", aliases=["b64"])
async def decode_base64(self, ctx, *, txtinput: str):
"""Decode in base64"""
try:
await self.encryptout(
ctx,
"base64 -> Text",
base64.urlsafe_b64decode(txtinput.encode("UTF-8")),
)
except Exception:
await ctx.send(view=DecodeErrorView("base64"))
@encode.command(name="rot13", aliases=["r13"])
async def encode_rot13(self, ctx, *, txtinput: commands.clean_content):
"""Encode in rot13"""
await self.encryptout(ctx, "Text -> rot13", codecs.decode(txtinput, "rot_13"))
@decode.command(name="rot13", aliases=["r13"])
async def decode_rot13(self, ctx, *, txtinput: str):
"""Decode in rot13"""
try:
await self.encryptout(
ctx, "rot13 -> Text", codecs.decode(txtinput, "rot_13")
)
except Exception:
await ctx.send(view=DecodeErrorView("rot13"))
@encode.command(name="hex")
async def encode_hex(self, ctx, *, txtinput: commands.clean_content):
"""Encode in hex"""
await self.encryptout(
ctx, "Text -> hex", binascii.hexlify(txtinput.encode("UTF-8"))
)
@decode.command(name="hex")
async def decode_hex(self, ctx, *, txtinput: str):
"""Decode in hex"""
try:
await self.encryptout(
ctx, "hex -> Text", binascii.unhexlify(txtinput.encode("UTF-8"))
)
except Exception:
await ctx.send(view=DecodeErrorView("hex"))
@encode.command(name="base85", aliases=["b85"])
async def encode_base85(self, ctx, *, txtinput: commands.clean_content):
"""Encode in base85"""
await self.encryptout(
ctx, "Text -> base85", base64.b85encode(txtinput.encode("UTF-8"))
)
@decode.command(name="base85", aliases=["b85"])
async def decode_base85(self, ctx, *, txtinput: str):
"""Decode in base85"""
try:
await self.encryptout(
ctx, "base85 -> Text", base64.b85decode(txtinput.encode("UTF-8"))
)
except Exception:
await ctx.send(view=DecodeErrorView("base85"))
@encode.command(name="ascii85", aliases=["a85"])
async def encode_ascii85(self, ctx, *, txtinput: commands.clean_content):
"""Encode in ASCII85"""
await self.encryptout(
ctx, "Text -> ASCII85", base64.a85encode(txtinput.encode("UTF-8"))
)
@decode.command(name="ascii85", aliases=["a85"])
async def decode_ascii85(self, ctx, *, txtinput: str):
"""Decode in ASCII85"""
try:
await self.encryptout(
ctx, "ASCII85 -> Text", base64.a85decode(txtinput.encode("UTF-8"))
)
except Exception:
await ctx.send(view=DecodeErrorView("ASCII85"))
@commands.command(name="password")
async def password(self, ctx):
"""Generates a random secure password for you"""
if hasattr(ctx, "guild") and ctx.guild is not None:
await ctx.send(view=PasswordSentView(ctx.author.name))
password = secrets.token_urlsafe(18)
try:
await ctx.author.send(view=PasswordDMView(password))
except discord.Forbidden:
await ctx.send(
f"❌ Could not send DM. Here is your password: **{password}**"
)
async def setup(bot):
await bot.add_cog(encryption(bot))

986
bot/cogs/commands/extra.py Normal file
View File

@@ -0,0 +1,986 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import os
import discord
from utils.emoji import BOOST, CODEBASE, CROSS, KING, TICK, UPTIME, ZWARNING
from discord.ext import commands
import datetime
import sys
from discord.ui import Button, View, LayoutView, TextDisplay, Separator, Container, ActionRow, MediaGallery
from utils.cv2 import CV2, build_container
import psutil
import time
from utils.Tools import *
from discord.ext import commands, menus
from discord.ext.commands import BucketType, cooldown
import requests
from typing import *
from utils import *
from utils.config import BotName, serverLink
from utils import Paginator, DescriptionEmbedPaginator, FieldPagePaginator, TextPaginator
from core import Cog, zyrox, Context
from typing import Optional
import aiosqlite
import asyncio
import aiohttp
start_time = time.time()
def datetime_to_seconds(thing: datetime.datetime):
current_time = datetime.datetime.fromtimestamp(time.time())
return round(
round(time.time()) +
(current_time - thing.replace(tzinfo=None)).total_seconds())
tick = f"{TICK}>"
cross = CROSS
class RoleInfoView(View):
def __init__(self, role: discord.Role, author_id):
super().__init__(timeout=180)
self.role = role
self.author_id = author_id
@discord.ui.button(label='Show Permissions', emoji=f"{CODEBASE} ", style=discord.ButtonStyle.secondary)
async def show_permissions(self, interaction: discord.Interaction, button: Button):
if interaction.user.id != self.author_id:
await interaction.response.send_message("Uh oh! That message doesn't belong to you. You must run this command to interact with it.", ephemeral=True)
return
permissions = [perm.replace("_", " ").title() for perm, value in self.role.permissions if value]
permission_text = ", ".join(permissions) if permissions else "None"
await interaction.response.send_message(view=CV2(f"Permissions for {self.role.name}", permission_text or "No permissions."), ephemeral=True)
class OverwritesView(View):
def __init__(self, channel, author_id):
super().__init__(timeout=180)
self.channel = channel
self.author_id = author_id
@discord.ui.button(label='Show Overwrites', style=discord.ButtonStyle.primary)
async def show_overwrites(self, interaction: discord.Interaction, button: Button):
if interaction.user.id != self.author_id:
await interaction.response.send_message("Uh oh! That message doesn't belong to you. You must run this command to interact with it.", ephemeral=True)
return
overwrites = []
for target, perms in self.channel.overwrites.items():
permissions = {
"View Channel": perms.view_channel,
"Send Messages": perms.send_messages,
"Read Message History": perms.read_message_history,
"Manage Messages": perms.manage_messages,
"Embed Links": perms.embed_links,
"Attach Files": perms.attach_files,
"Manage Channels": perms.manage_channels,
"Manage Permissions": perms.manage_permissions,
"Manage Webhooks": perms.manage_webhooks,
"Create Instant Invite": perms.create_instant_invite,
"Add Reactions": perms.add_reactions,
"Mention Everyone": perms.mention_everyone,
"Kick Members": perms.kick_members,
"Ban Members": perms.ban_members,
"Moderate Members": perms.moderate_members,
"Send TTS Messages": perms.send_tts_messages,
"Use External Emojis": perms.external_emojis,
"Use External Stickers": perms.external_stickers,
"View Audit Log": perms.view_audit_log,
"Voice Mute Members": perms.mute_members,
"Voice Deafen Members": perms.deafen_members,
"Administrator": perms.administrator
}
overwrites.append(f"**For {target.name}**\n" +
"\n".join(f" * **{perm}:** {'{TICK}>' if value else '{CROSS}' if value is False else ''}" for perm, value in permissions.items()))
ow_text = "\n".join(overwrites) if overwrites else "No overwrites for this channel."
footer = f"{TICK}> = Allowed, {CROSS} = Denied, ⛔ = None"
await interaction.response.send_message(view=CV2(f"Overwrites for {self.channel.name}", ow_text, footer), ephemeral=True)
class Extra(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.color = 0xFF0000
self.start_time = datetime.datetime.now()
@commands.hybrid_group(name="banner")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def banner(self, ctx):
if ctx.invoked_subcommand is None:
await ctx.send_help(ctx.command)
@banner.command(name="server")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
async def server(self, ctx):
if not ctx.guild.banner:
await ctx.reply(view=CV2(f"{cross} Error", "This server doesn't have a banner."))
else:
webp = ctx.guild.banner.replace(format='webp')
jpg = ctx.guild.banner.replace(format='jpg')
png = ctx.guild.banner.replace(format='png')
links = f"[`PNG`]({png}) | [`JPG`]({jpg}) | [`WEBP`]({webp})"
if ctx.guild.banner.is_animated():
links += f" | [`GIF`]({ctx.guild.banner.replace(format='gif')})"
view = LayoutView(timeout=None)
gallery = MediaGallery()
gallery.add_item(media=str(ctx.guild.banner.url))
view.add_item(build_container(
TextDisplay(f"**{ctx.guild.name}**"),
Separator(visible=True),
TextDisplay(links),
gallery
))
await ctx.reply(view=view)
@banner.command(name="user")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
async def _user(self,
ctx,
member: Optional[Union[discord.Member,
discord.User]] = None):
if member == None or member == "":
member = ctx.author
bannerUser = await self.bot.fetch_user(member.id)
if not bannerUser.banner:
await ctx.reply(view=CV2(f"{cross} Error", f"{member} doesn't have a banner."))
else:
webp = bannerUser.banner.replace(format='webp')
jpg = bannerUser.banner.replace(format='jpg')
png = bannerUser.banner.replace(format='png')
links = f"[`PNG`]({png}) | [`JPG`]({jpg}) | [`WEBP`]({webp})"
if bannerUser.banner.is_animated():
links += f" | [`GIF`]({bannerUser.banner.replace(format='gif')})"
view = LayoutView(timeout=None)
gallery = MediaGallery()
gallery.add_item(media=str(bannerUser.banner.url))
view.add_item(build_container(
TextDisplay(f"**{member}**"),
Separator(visible=True),
TextDisplay(links),
gallery
))
await ctx.send(view=view)
@commands.command(name="uptime", description="Shows the Bot's Uptime.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def uptime(self, ctx):
pfp = ctx.author.display_avatar.url
uptime_seconds = int(round(time.time() - start_time))
uptime_timedelta = datetime.timedelta(seconds=uptime_seconds)
uptime_string = f"Up since {datetime.datetime.utcfromtimestamp(start_time).strftime('%Y-%m-%d %H:%M:%S')} UTC"
uptime_duration_string = f"{uptime_timedelta.days} days, {uptime_timedelta.seconds // 3600} hours, {(uptime_timedelta.seconds // 60) % 60} minutes, {uptime_timedelta.seconds % 60} seconds"
uptime_text = (
f"**__UTC__**\n{ZWARNING} {uptime_string}\n\n"
f"**__Online Duration__**\n{UPTIME} {uptime_duration_string}"
)
await ctx.send(view=CV2(f"{BRAND_NAME} Manager Uptime", uptime_text))
@commands.hybrid_command(name="serverinfo",
aliases=["sinfo", "si"],
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def serverinfo(self, ctx):
c_at = ctx.guild.created_at.strftime("%Y-%m-%d %H:%M:%S")
about = (
f"**Name:** {ctx.guild.name}\n"
f"**ID:** {ctx.guild.id}\n"
f"**Owner {KING}:** {ctx.guild.owner} (<@{ctx.guild.owner_id}>)\n"
f"**Created At:** {c_at}\n"
f"**Members:** {len(ctx.guild.members)}"
)
desc_section = f"\n\n**__Description__**\n{ctx.guild.description}" if ctx.guild.description else ""
stats = (
f"**Verification Level:** {ctx.guild.verification_level}\n"
f"**Channels:** {len(ctx.guild.channels)}\n"
f"**Roles:** {len(ctx.guild.roles)}\n"
f"**Emojis:** {len(ctx.guild.emojis)}\n"
f"**Boost Status:** Level {ctx.guild.premium_tier} (Boosts: {ctx.guild.premium_subscription_count})"
)
features_text = ""
if ctx.guild.features:
features = "\n".join([f"{TICK}>: {f[:1].upper() + f[1:].lower().replace('_', ' ')}" for f in ctx.guild.features])
features_text = f"\n\n**__Features__**\n{features[:1000] if len(features) > 1024 else features}"
regular_emojis = [e for e in ctx.guild.emojis if not e.animated]
animated_emojis = [e for e in ctx.guild.emojis if e.animated]
emoji_info = f"Regular: {len(regular_emojis)}/100 | Animated: {len(animated_emojis)}/100 | Total: {len(ctx.guild.emojis)}/200"
roles = ctx.guild.roles
roles_display = "\n".join([r.mention for r in roles[:10]])
if len(roles) > 10:
roles_display += f"\n...and {len(roles) - 10} more"
full_text = (
f"**__About__**\n{about}{desc_section}\n\n"
f"**__General Stats__**\n{stats}{features_text}\n\n"
f"**__Channels__**\n**Total:** {len(ctx.guild.channels)}{len(ctx.guild.text_channels)} text, {len(ctx.guild.voice_channels)} voice\n\n"
f"**__Emoji Info__**\n{emoji_info}\n\n"
f"**__Boost Status__**\nLevel: {ctx.guild.premium_tier} [{BOOST}{ctx.guild.premium_subscription_count} boosts]\n\n"
f"**__Server Roles__ [{len(roles)}]**\n{roles_display}"
)
icon_url = ctx.guild.icon.url if ctx.guild.icon else None
view = LayoutView(timeout=None)
items = [TextDisplay(f"# {ctx.guild.name}'s Information"), Separator(visible=True), TextDisplay(full_text)]
if icon_url or ctx.guild.banner:
gallery = MediaGallery()
if icon_url:
gallery.add_item(media=str(icon_url))
if ctx.guild.banner:
gallery.add_item(media=str(ctx.guild.banner.url))
items.append(gallery)
view.add_item(build_container(*items))
await ctx.send(view=view)
@commands.hybrid_command(name="userinfo",
aliases=["whois", "ui"],
usage="Userinfo [user]",
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
async def _userinfo(self,
ctx,
member: Optional[Union[discord.Member,
discord.User]] = None):
if member == None or member == "":
member = ctx.author
elif member not in ctx.guild.members:
member = await self.bot.fetch_user(member.id)
badges = ""
if member.public_flags.hypesquad:
badges += "HypeSquad Events, "
if member.public_flags.hypesquad_balance:
badges += "HypeSquad Balance, "
if member.public_flags.hypesquad_bravery:
badges += "HypeSquad Bravery, "
if member.public_flags.hypesquad_brilliance:
badges += "HypeSquad Brilliance, "
if member.public_flags.early_supporter:
badges += "Early Supporter, "
if member.public_flags.active_developer:
badges += "Active Developer, "
if member.public_flags.verified_bot_developer:
badges += "Early Verified Bot Developer, "
if member.public_flags.discord_certified_moderator:
badges += "Moderators Program Alumni, "
if member.public_flags.staff:
badges += "Discord Staff, "
if member.public_flags.partner:
badges += "Partnered Server Owner "
if badges == None or badges == "":
badges += f"{cross}"
if member in ctx.guild.members:
nickk = f"{member.nick if member.nick else 'None'}"
joinedat = f"<t:{round(member.joined_at.timestamp())}:R>"
else:
nickk = "None"
joinedat = "None"
kp = ""
if member in ctx.guild.members:
if member.guild_permissions.kick_members:
kp += "Kick Members"
if member.guild_permissions.ban_members:
kp += " , Ban Members"
if member.guild_permissions.administrator:
kp += " , Administrator"
if member.guild_permissions.manage_channels:
kp += " , Manage Channels"
if member.guild_permissions.manage_guild:
kp += " , Manage Server"
if member.guild_permissions.manage_messages:
kp += " , Manage Messages"
if member.guild_permissions.mention_everyone:
kp += " , Mention Everyone"
if member.guild_permissions.manage_nicknames:
kp += " , Manage Nicknames"
if member.guild_permissions.manage_roles:
kp += " , Manage Roles"
if member.guild_permissions.manage_webhooks:
kp += " , Manage Webhooks"
if member.guild_permissions.manage_emojis:
kp += " , Manage Emojis"
if kp is None or kp == "":
kp = "None"
if member in ctx.guild.members:
if member == ctx.guild.owner:
aklm = "Server Owner"
elif member.guild_permissions.administrator:
aklm = "Server Admin"
elif member.guild_permissions.ban_members or member.guild_permissions.kick_members:
aklm = "Server Moderator"
else:
aklm = "Server Member"
bannerUser = await self.bot.fetch_user(member.id)
embed = discord.Embed(color=self.color)
embed.timestamp = discord.utils.utcnow()
if not bannerUser.banner:
pass
else:
embed.set_image(url=bannerUser.banner)
embed.set_author(name=f"{member.name}'s Information",
icon_url=member.avatar.url
if member.avatar else member.default_avatar.url)
embed.set_thumbnail(
url=member.avatar.url if member.avatar else member.default_avatar.url)
embed.add_field(name="__General Information__",
value=f"""
**Name:** {member}
**ID:** {member.id}
**Nickname:** {nickk}
**Bot?:** {'{TICK}> Yes' if member.bot else '{CROSS} No'}
**Badges:** {badges}
**Account Created:** <t:{round(member.created_at.timestamp())}:R>
**Server Joined:** {joinedat}
""",
inline=False)
if member in ctx.guild.members:
r = (', '.join(role.mention for role in member.roles[1:][::-1])
if len(member.roles) > 1 else 'None.')
embed.add_field(name="__Role Info__",
value=f"""
**Highest Role:** {member.top_role.mention if len(member.roles) > 1 else 'None'}
**Roles [{f'{len(member.roles) - 1}' if member.roles else '0'}]:** {r if len(r) <= 1024 else r[0:1006] + ' and more...'}
**Color:** {member.color if member.color else '99aab5'}
""",
inline=False)
if member in ctx.guild.members:
embed.add_field(
name="__Extra__",
value=
f"**Boosting:** {f'<t:{round(member.premium_since.timestamp())}:R>' if member in ctx.guild.premium_subscribers else 'None'}\n**Voice :** {'None' if not member.voice else member.voice.channel.mention}",
inline=False)
if member in ctx.guild.members:
embed.add_field(name="__Key Permissions__",
value=", ".join([kp]),
inline=False)
if member in ctx.guild.members:
embed.add_field(name="__Acknowledgement__",
value=f"{aklm}",
inline=False)
if member in ctx.guild.members:
embed.set_footer(text=f"Requested by {ctx.author}",
icon_url=ctx.author.avatar.url
if ctx.author.avatar else ctx.author.default_avatar.url)
else:
if member not in ctx.guild.members:
embed.set_footer(text=f"{member.name} not in this server.",
icon_url=ctx.author.avatar.url if ctx.author.avatar
else ctx.author.default_avatar.url)
await ctx.send(embed=embed)
@commands.hybrid_command(name='roleinfo', aliases=["ri"], help="Displays information about a specified role.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def roleinfo(self, ctx, role: discord.Role):
members = role.members
created_at = role.created_at.strftime("%Y-%m-%d %H:%M:%S")
total_roles = len(ctx.guild.roles)
role_position = total_roles - role.position
role_text = (
f"**__General Information__**\n"
f"**ID:** {role.id}\n**Name:** {role.name}\n**Mention:** <@&{role.id}>\n"
f"**Color:** {str(role.color)}\n**Total Members:** {len(role.members)}\n\n"
f"**Position:** {role_position}\n**Mentionable:** {role.mentionable}\n"
f"**Hoisted:** {role.hoist}\n**Managed:** {role.managed}\n**Created At:** {created_at}"
)
view = RoleInfoView(role, ctx.author.id)
await ctx.send(content=role_text, view=view)
@commands.command(name="boostcount",
help="Shows boosts count",
usage="boosts",
aliases=["bco"],
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def boosts(self, ctx):
await ctx.send(view=CV2(f"{BOOST} Boosts Count Of {ctx.guild.name}", f"**Total `{ctx.guild.premium_subscription_count}` boosts**"))
@commands.hybrid_group(name="list",
invoke_without_command=True,
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def __list_(self, ctx: commands.Context):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@__list_.command(name="boosters",
aliases=["boost", "booster"],
usage="List boosters",
help="List of boosters in the Guild",
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def list_boost(self, ctx):
guild = ctx.guild
entries = [
f"`#{no}.` [{mem}](https://discord.com/users/{mem.id}) [{mem.mention}] - <t:{round(mem.premium_since.timestamp())}:R>"
for no, mem in enumerate(guild.premium_subscribers, start=1)
]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title=
f"List of Boosters in {guild.name} - {len(guild.premium_subscribers)}",
description="",
per_page=10),
ctx=ctx)
await paginator.paginate()
@__list_.command(name="bans", help= "List of all banned members in Guild", aliases=["ban"], with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(view_audit_log=True)
@commands.bot_has_permissions(view_audit_log=True)
async def list_ban(self, ctx):
bans = [member async for member in ctx.guild.bans()]
if len(bans) == 0:
return await ctx.reply("There aren't any banned users in this guild.", mention_author=False)
else:
mems = ([
member async for member in ctx.guild.bans()
])
guild = ctx.guild
entries = [
f"`#{no}.` {mem}"
for no, mem in enumerate(mems, start=1)
]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title=f"Banned Users in {guild.name} - {len(bans)}",
description="",
per_page=10),
ctx=ctx)
await paginator.paginate()
@__list_.command(
name="inrole",
aliases=["inside-role"],
help="List of members that are in the specified role",
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def list_inrole(self, ctx, role: discord.Role):
guild = ctx.guild
entries = [
f"`#{no}.` [{mem}](https://discord.com/users/{mem.id}) [{mem.mention}] - <t:{int(mem.created_at.timestamp())}:D>"
for no, mem in enumerate(role.members, start=1)
]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title=f"List of Members in {role} - {len(role.members)}",
description="",
per_page=10),
ctx=ctx)
await paginator.paginate()
@__list_.command(name="emojis",
aliases=["emoji"],
help="List of emojis in the Guild with ids",
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def list_emojis(self, ctx):
guild = ctx.guild
entries = [
f"`#{no}.` {e} - `{e}`"
for no, e in enumerate(ctx.guild.emojis, start=1)
]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title=f"List of Emojis in {guild.name} - {len(ctx.guild.emojis)}",
description="",
per_page=10),
ctx=ctx)
await paginator.paginate()
@__list_.command(name="roles",
aliases=["role"],
help="List of all roles in the server with ids",
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
@commands.has_permissions(manage_roles=True)
async def list_roles(self, ctx):
guild = ctx.guild
entries = [
f"`#{no}.` {e.mention} - `[{e.id}]`"
for no, e in enumerate(ctx.guild.roles, start=1)
]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title=f"List of Roles in {guild.name} - {len(ctx.guild.roles)}",
description="",
per_page=10),
ctx=ctx)
await paginator.paginate()
@__list_.command(name="bots",
aliases=["bot"],
help="List of All Bots in a server",
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def list_bots(self, ctx):
guild = ctx.guild
people = filter(lambda member: member.bot, ctx.guild.members)
people = sorted(people, key=lambda member: member.joined_at)
entries = [
f"`#{no}.` [{mem}](https://discord.com/users/{mem.id}) [{mem.mention}]"
for no, mem in enumerate(people, start=1)
]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title=f"Bots in {guild.name} - {len(people)}",
description="",
per_page=10),
ctx=ctx)
await paginator.paginate()
@__list_.command(name="admins",
aliases=["admin"],
help="List of all Admins of the Guild",
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def list_admin(self, ctx):
mems = ([
mem for mem in ctx.guild.members
if mem.guild_permissions.administrator
])
mems = sorted(mems, key=lambda mem: not mem.bot)
admins = len([
mem for mem in ctx.guild.members
if mem.guild_permissions.administrator
])
guild = ctx.guild
entries = [
f"`#{no}.` [{mem}](https://discord.com/users/{mem.id}) [{mem.mention}] - <t:{int(mem.created_at.timestamp())}:D>"
for no, mem in enumerate(mems, start=1)
]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title=f"Admins in {guild.name} - {admins}",
description="",
per_page=10),
ctx=ctx)
await paginator.paginate()
@__list_.command(name="invoice", help="List of all users in a voice channel", aliases=["invc"], with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def listusers(self, ctx):
if not ctx.author.voice:
return await ctx.send("You are not connected to a voice channel")
members = ctx.author.voice.channel.members
entries = [
f"`[{n}]` | {member} [{member.mention}]"
for n, member in enumerate(members, start=1)
]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
description="",
title=f"Voice List of {ctx.author.voice.channel.name} - {len(members)}",
color=self.color),
ctx=ctx)
await paginator.paginate()
@__list_.command(name="moderators", help= "List of All Admins of a server", aliases=["mods"], with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def list_mod(self, ctx):
membs = ([
mem for mem in ctx.guild.members
if mem.guild_permissions.ban_members
or mem.guild_permissions.kick_members
])
mems = filter(lambda member: member.bot, ctx.guild.members)
mems = sorted(membs, key=lambda mem: mem.joined_at)
admins = len([
mem for mem in ctx.guild.members
if mem.guild_permissions.ban_members
or mem.guild_permissions.kick_members
])
guild = ctx.guild
entries = [
f"`#{no}.` [{mem}](https://discord.com/users/{mem.id}) [{mem.mention}] - <t:{int(mem.created_at.timestamp())}:D>"
for no, mem in enumerate(mems, start=1)
]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title=f"Mods in {guild.name} - {admins}",
description="",
per_page=10),
ctx=ctx)
await paginator.paginate()
@__list_.command(name="early", aliases=["sup"], help= "List of members that have Early Supporter badge.", with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def list_early(self, ctx):
mems = ([
memb for memb in ctx.guild.members
if memb.public_flags.early_supporter
])
mems = sorted(mems, key=lambda memb: memb.created_at)
admins = len([
memb for memb in ctx.guild.members
if memb.public_flags.early_supporter
])
guild = ctx.guild
entries = [
f"`#{no}.` [{mem}](https://discord.com/users/{mem.id}) [{mem.mention}] - <t:{int(mem.created_at.timestamp())}:D>"
for no, mem in enumerate(mems, start=1)
]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title=f"Early Supporters Id's in {guild.name} - {admins}",
description="",
per_page=10),
ctx=ctx)
await paginator.paginate()
@__list_.command(name="activedeveloper", help= "List of members that have Active Developer badge.",
aliases=["activedev"],
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def list_activedeveloper(self, ctx):
mems = ([
memb for memb in ctx.guild.members
if memb.public_flags.active_developer
])
mems = sorted(mems, key=lambda memb: memb.created_at)
admins = len([
memb for memb in ctx.guild.members
if memb.public_flags.active_developer
])
guild = ctx.guild
entries = [
f"`#{no}.` [{mem}](https://discord.com/users/{mem.id}) [{mem.mention}] - <t:{int(mem.created_at.timestamp())}:D>"
for no, mem in enumerate(mems, start=1)
]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title=f"Active Developer Id's in {guild.name} - {admins}",
description="",
per_page=10),
ctx=ctx)
await paginator.paginate()
@__list_.command(name="createdat", help= "List of Account Creation Date of all Users", with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def list_cpos(self, ctx):
mems = ([memb for memb in ctx.guild.members])
mems = sorted(mems, key=lambda memb: memb.created_at)
admins = len([memb for memb in ctx.guild.members])
guild = ctx.guild
entries = [
f"`[{no}]` | [{mem}](https://discord.com/users/{mem.id}) - <t:{int(mem.created_at.timestamp())}:D>"
for no, mem in enumerate(mems, start=1)
]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title=f"Creation every id in {guild.name} - {admins}",
description="",
per_page=10),
ctx=ctx)
await paginator.paginate()
@__list_.command(name="joinedat", help= "List of Guild Joined date of all Users", with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def list_joinpos(self, ctx):
mems = ([memb for memb in ctx.guild.members])
mems = sorted(mems, key=lambda memb: memb.joined_at)
admins = len([memb for memb in ctx.guild.members])
guild = ctx.guild
entries = [
f"`#{no}.` [{mem}](https://discord.com/users/{mem.id}) Joined At - <t:{int(mem.joined_at.timestamp())}:D>"
for no, mem in enumerate(mems, start=1)
]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title=f"Join Position of every user in {guild.name} - {admins}",
description="",
per_page=10),
ctx=ctx)
await paginator.paginate()
@commands.command(name="joined-at",
help="Shows when a user joined",
usage="joined-at [user]",
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def joined_at(self, ctx):
joined = ctx.author.joined_at.strftime("%a, %d %b %Y %I:%M %p")
await ctx.send(view=CV2("joined-at", f"**`{joined}`**"))
@commands.command(name="github", usage="github [search]")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def github(self, ctx, *, search_query):
json = requests.get(
f"https://api.github.com/search/repositories?q={search_query}").json()
if json["total_count"] == 0:
await ctx.send(f"No matching repositories found with the name: {search_query}")
else:
await ctx.send(
f"Found result for '{search_query}':\n{json['items'][0]['html_url']}")
@commands.hybrid_command(name="vcinfo",
description="View information about a voice channel.",
help="View information about a voice channel.",
usage="<VoiceChannel>",
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def vcinfo(self, ctx, channel: discord.VoiceChannel = None):
if channel is None:
await ctx.reply(view=CV2(f"{cross} Error", "Please provide a valid voice channel."))
return
vc_text = (
f"**ID:** {channel.id}\n**Members:** {len(channel.members)}\n"
f"**Bitrate:** {channel.bitrate/1000} kbps\n"
f"**Created At:** {channel.created_at.strftime('%Y-%m-%d %H:%M:%S')}\n"
f"**Category:** {channel.category.name if channel.category else 'None'}\n"
f"**Region:** {channel.rtc_region}"
)
if channel.user_limit:
vc_text += f"\n**User Limit:** {channel.user_limit}"
view = LayoutView(timeout=None)
join_btn = Button(label="Join", style=discord.ButtonStyle.link, url=f"https://discord.com/channels/{ctx.guild.id}/{channel.id}")
view.add_item(build_container(
TextDisplay(f"**Voice Channel Info — {channel.name}**"),
Separator(visible=True),
TextDisplay(vc_text),
ActionRow(join_btn)
))
await ctx.send(view=view)
@commands.hybrid_command(name="channelinfo",
aliases=['cinfo', 'ci'],
description='Get information about a channel.',
help='Get information about a channel.',
usage="<Channel>",
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def channelinfo(self, ctx, channel: discord.TextChannel = None):
if channel is None:
channel = ctx.channel
ch_text = (
f"**ID:** {channel.id}\n**Created At:** {channel.created_at.strftime('%Y-%m-%d %H:%M:%S')}\n"
f"**Category:** {channel.category.name if channel.category else 'None'}\n"
f"**Topic:** {channel.topic if channel.topic else 'None'}\n"
f"**Slowmode:** {f'{channel.slowmode_delay} seconds' if channel.slowmode_delay else 'None'}\n"
f"**NSFW:** {channel.is_nsfw()}"
)
view = OverwritesView(channel, ctx.author.id)
view.add_item(Button(label="Redirect Channel", style=discord.ButtonStyle.green, url=f"https://discord.com/channels/{ctx.guild.id}/{channel.id}"))
await ctx.send(content=ch_text, view=view)
@commands.hybrid_command(name="ping", aliases=['latency'], help="Checks the bot's latencies.")
@ignore_check()
@blacklist_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def ping(self, ctx: commands.Context):
"""Shows the bot's WebSocket, API, and Database latencies."""
# 1. Start timer and send an initial "Pinging..." message
start_time = time.monotonic()
msg = await ctx.send(view=CV2("Checking Latency...", "Calculating response times, please wait."))
end_time = time.monotonic()
bot_latency = round(self.bot.latency * 1000)
api_latency = round((end_time - start_time) * 1000)
db_latency = "Not Available"
try:
async with aiosqlite.connect("db/afk.db") as db:
db_start_time = time.perf_counter()
await db.execute("SELECT 1")
db_end_time = time.perf_counter()
db_latency = f"{round((db_end_time - db_start_time) * 1000)}ms"
except Exception as e:
print(f"Database latency check failed: {e}")
latency_text = (
f"**Bot (WebSocket):** `{bot_latency}ms`\n"
f"**API (Roundtrip):** `{api_latency}ms`\n"
f"**Database:** `{db_latency}`"
)
await msg.edit(view=CV2("System Latency Report", latency_text))
@commands.command(name="permissions", aliases= ["perms"],
help="Check and list the key permissions of a specific user",
usage="perms <user>",
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def keyperms(self, ctx, member: discord.Member):
key_permissions = []
if member.guild_permissions.create_instant_invite:
key_permissions.append("Create Instant Invite")
if member.guild_permissions.kick_members:
key_permissions.append("Kick Members")
if member.guild_permissions.ban_members:
key_permissions.append("Ban Members")
if member.guild_permissions.administrator:
key_permissions.append("Administrator")
if member.guild_permissions.manage_channels:
key_permissions.append("Manage Channels")
if member.guild_permissions.manage_messages:
key_permissions.append("Manage Messages")
if member.guild_permissions.mention_everyone:
key_permissions.append("Mention Everyone")
if member.guild_permissions.manage_nicknames:
key_permissions.append("Manage Nicknames")
if member.guild_permissions.manage_roles:
key_permissions.append("Manage Roles")
if member.guild_permissions.manage_webhooks:
key_permissions.append("Manage Webhooks")
if member.guild_permissions.manage_emojis:
key_permissions.append("Manage Emojis")
if member.guild_permissions.manage_guild:
key_permissions.append("Manage Server")
if member.guild_permissions.manage_permissions:
key_permissions.append("Manage Permissions")
if member.guild_permissions.manage_threads:
key_permissions.append("Manage Threads")
if member.guild_permissions.moderate_members:
key_permissions.append("Moderate Members")
if member.guild_permissions.move_members:
key_permissions.append("Move Members")
if member.guild_permissions.mute_members:
key_permissions.append("Mute Members (VC)")
if member.guild_permissions.deafen_members:
key_permissions.append("Deafen Members")
if member.guild_permissions.priority_speaker:
key_permissions.append("Priority Speaker")
if member.guild_permissions.stream:
key_permissions.append("Stream")
permissions_list = ", ".join(key_permissions) if key_permissions else "None"
await ctx.reply(view=CV2(f"Key Permissions of {member}", f"__**Key Permissions**__\n{permissions_list}"))
@commands.hybrid_command(name="report",
aliases=["bug"],
usage='Report <bug>',
description='Report a bug to the Development team.',
help='Report a bug to the Development team.',
with_app_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 30, commands.BucketType.channel)
async def report(self, ctx, *, bug):
channel = self.bot.get_channel(1396813063642153030)
report_text = f"{bug}\n\n**Reported By:** {ctx.author.name}\n**Server:** {ctx.guild.name}\n**Channel:** {ctx.channel.name}"
await channel.send(view=CV2("Bug Reported", report_text))
await ctx.reply(view=CV2(f"{TICK} Bug Reported", "Thank you for reporting the bug. We will look into it."))

View File

@@ -0,0 +1,169 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import CROSS, TICK, ZWARNING
from discord.ext import commands
from discord.ui import LayoutView, TextDisplay, Separator, Container, ActionRow, Button
import aiosqlite
from utils.Tools import *
from utils.cv2 import CV2, build_container
from utils.config import OWNER_IDS_STR
class ConfirmView(LayoutView):
def __init__(self, ctx):
super().__init__(timeout=60)
self.ctx = ctx
self.value = None
self.yes_btn = Button(label="Confirm", style=discord.ButtonStyle.green)
self.no_btn = Button(label="Cancel", style=discord.ButtonStyle.red)
self.yes_btn.callback = self.confirm_callback
self.no_btn.callback = self.cancel_callback
container = build_container(
TextDisplay("**Confirm Action**"),
Separator(visible=True),
TextDisplay(self._desc),
ActionRow(self.yes_btn, self.no_btn),
)
self.add_item(container)
@property
def _desc(self):
return ""
async def confirm_callback(self, interaction: discord.Interaction):
if interaction.user != self.ctx.author:
return await interaction.response.send_message("You cannot interact with this confirmation.", ephemeral=True)
self.value = True
await interaction.response.defer()
self.stop()
async def cancel_callback(self, interaction: discord.Interaction):
if interaction.user != self.ctx.author:
return await interaction.response.send_message("You cannot interact with this confirmation.", ephemeral=True)
self.value = False
await interaction.response.defer()
self.stop()
class SetConfirmView(ConfirmView):
def __init__(self, ctx, user):
self._user = user
super().__init__(ctx)
@property
def _desc(self):
return f"**Are you sure you want to set {self._user.mention} as the Extra Owner?**"
class ResetConfirmView(ConfirmView):
@property
def _desc(self):
return "**Are you sure you want to reset the Extra Owner?**"
class Extraowner(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.bot.loop.create_task(self.initialize_db())
async def initialize_db(self):
self.db = await aiosqlite.connect('db/anti.db')
await self.db.execute('''
CREATE TABLE IF NOT EXISTS extraowners (
guild_id INTEGER PRIMARY KEY,
owner_id INTEGER
)
''')
await self.db.commit()
@commands.hybrid_command(name='extraowner', aliases=["owner"], help="Adds Extraowner to the server")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 10, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
async def extraowner(self, ctx, option: str = None, user: discord.Member = None):
guild_id = ctx.guild.id
if ctx.guild.member_count < 2:
return await ctx.send(view=CV2(f"{CROSS} Error", "Your Server Doesn't Meet My 30 Member Criteria"))
Ray = OWNER_IDS_STR
if ctx.author.id != ctx.guild.owner_id and str(ctx.author.id) not in Ray:
return await ctx.send(view=CV2(f"{ZWARNING} Access Denied", "Only Server Owner Can Run This Command"))
if option is None:
pre = ctx.prefix
info_text = (
"Extraowners can adjust server antinuke settings & manage whitelist events, "
"so careful consideration is essential before assigning it to someone.\n\n"
f"**Extraowner Set** — `{pre}extraowner set @user`\n"
f"**Extraowner Reset** — `{pre}extraowner reset`\n"
f"**Extraowner View** — `{pre}extraowner view`"
)
return await ctx.reply(view=CV2("__Extra Owner__", info_text))
if option.lower() == 'set':
if user is None or user.bot:
return await ctx.reply(view=CV2(f"{CROSS} Error", "Please Provide a Valid User Mention or ID to Set as Extra Owner!"))
view = SetConfirmView(ctx, user)
message = await ctx.reply(view=view)
await view.wait()
if view.value is None:
await message.edit(view=CV2("⏰ Timed Out", "Confirmation timed out."))
elif view.value:
await self.db.execute('INSERT OR REPLACE INTO extraowners (guild_id, owner_id) VALUES (?, ?)', (guild_id, user.id))
await self.db.commit()
await message.edit(view=CV2(f"{TICK} Success", f"Added {user.mention} As Extraowner"))
else:
await message.edit(view=CV2(f"{CROSS} Cancelled", "Action cancelled."))
elif option.lower() == 'reset':
async with self.db.execute('SELECT owner_id FROM extraowners WHERE guild_id = ?', (guild_id,)) as cursor:
row = await cursor.fetchone()
if not row:
await ctx.reply(view=CV2(f"{CROSS} Error", "No extra owner has been designated for this guild."))
else:
view = ResetConfirmView(ctx)
message = await ctx.reply(view=view)
await view.wait()
if view.value is None:
await message.edit(view=CV2("⏰ Timed Out", "Confirmation timed out."))
elif view.value:
await self.db.execute('DELETE FROM extraowners WHERE guild_id = ?', (guild_id,))
await self.db.commit()
await message.edit(view=CV2(f"{TICK} Success", "Disabled Extraowner Configuration!"))
else:
await message.edit(view=CV2(f"{CROSS} Cancelled", "Action cancelled."))
elif option.lower() == 'view':
async with self.db.execute('SELECT owner_id FROM extraowners WHERE guild_id = ?', (guild_id,)) as cursor:
row = await cursor.fetchone()
if not row:
await ctx.reply(view=CV2(f"{CROSS} Error", "No extra owner is currently assigned."))
else:
await ctx.reply(view=CV2("Extra Owner", f"Current Extraowner is <@{row[0]}>"))

View File

@@ -0,0 +1,92 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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 sqlite3
import asyncio
import os
DB_PATH = "./db/fastgreet.db"
class FastGreet(commands.Cog):
def __init__(self, bot):
self.bot = bot
os.makedirs("./db", exist_ok=True)
self.init_db()
def init_db(self):
with sqlite3.connect(DB_PATH) as conn:
conn.execute("""
CREATE TABLE IF NOT EXISTS greet_channels (
guild_id INTEGER,
channel_id INTEGER,
PRIMARY KEY (guild_id, channel_id)
)
""")
@commands.command(name="fastgreet_add")
@commands.has_permissions(administrator=True)
async def add_greet_channel(self, ctx, channel: discord.TextChannel):
with sqlite3.connect(DB_PATH) as conn:
conn.execute("""
INSERT OR IGNORE INTO greet_channels (guild_id, channel_id)
VALUES (?, ?)
""", (ctx.guild.id, channel.id))
await ctx.send(f"{channel.mention} added as a greet channel.")
@commands.command(name="fastgreet_remove")
@commands.has_permissions(administrator=True)
async def remove_greet_channel(self, ctx, channel: discord.TextChannel):
with sqlite3.connect(DB_PATH) as conn:
conn.execute("""
DELETE FROM greet_channels WHERE guild_id = ? AND channel_id = ?
""", (ctx.guild.id, channel.id))
await ctx.send(f"{channel.mention} removed from greet channels.")
@commands.command(name="fastgreet_list")
async def list_greet_channels(self, ctx):
with sqlite3.connect(DB_PATH) as conn:
cursor = conn.execute("""
SELECT channel_id FROM greet_channels WHERE guild_id = ?
""", (ctx.guild.id,))
rows = cursor.fetchall()
if not rows:
await ctx.send("⚠️ No greet channels configured.")
return
channels = [f"<#{cid[0]}>" for cid in rows]
await ctx.send("📋 Greet Channels: " + ", ".join(channels))
@commands.Cog.listener()
async def on_member_join(self, member):
with sqlite3.connect(DB_PATH) as conn:
cursor = conn.execute("""
SELECT channel_id FROM greet_channels WHERE guild_id = ?
""", (member.guild.id,))
channels = [row[0] for row in cursor.fetchall()]
for channel_id in channels:
channel = self.bot.get_channel(channel_id)
if channel:
try:
msg = await channel.send(f"{member.mention} Welcome!")
await asyncio.sleep(2)
await msg.delete()
except discord.Forbidden:
continue # Missing permissions
async def setup(bot):
await bot.add_cog(FastGreet(bot))

View 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
from typing import Union
import wavelink
from utils.Tools import *
class FilterCog(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.active_filters = {}
async def apply_filter(self, ctx: commands.Context, filter_name: str):
player: Union[wavelink.Player, None] = ctx.voice_client
if not player or not player.playing:
await ctx.send("I'm not playing anything.")
return
if ctx.author.voice is None or ctx.author.voice.channel != player.channel:
await ctx.send("You need to be in the same voice channel as me.")
return
filters = wavelink.Filters()
if filter_name == "nightcore":
filters.timescale.set(pitch=1.2, speed=1.2, rate=1)
elif filter_name == "bassboost":
filters.equalizer.set(bands=[{"band": 0, "gain": 0.5}, {"band": 1, "gain": 0.5}, {"band": 2, "gain": 0.5}])
elif filter_name == "vaporwave":
filters.timescale.set(rate=0.85, pitch=0.85)
elif filter_name == "karaoke":
filters.karaoke.set(level=1.0, mono_level=1.0, filter_band=220.0, filter_width=100.0)
elif filter_name == "tremolo":
filters.tremolo.set(depth=0.5, frequency=14.0)
elif filter_name == "vibrato":
filters.vibrato.set(depth=0.5, frequency=14.0)
elif filter_name == "rotation":
filters.rotation.set(rotation_hz=5.0)
elif filter_name == "distortion":
filters.distortion.set(
sin_offset=0.0,
sin_scale=1.0,
cos_offset=0.0,
cos_scale=1.0,
tan_offset=0.0,
tan_scale=1.0,
offset=0.0,
scale=1.0
)
elif filter_name == "channelmix":
filters.channel_mix.set(left_to_left=0.5, left_to_right=0.5, right_to_left=0.5, right_to_right=0.5)
await player.set_filters(filters)
self.active_filters[ctx.guild.id] = filter_name
await ctx.send(embed=discord.Embed(description=f"Filter set to **{filter_name}**.", color=discord.Color.green()))
@commands.hybrid_group(invoke_without_command=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def filter(self, ctx: commands.Context):
await ctx.send("Use `filter enable` to enable a filter or `filter disable` to disable the current filter.")
@filter.command(help="Enable a filter.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def enable(self, ctx: commands.Context):
player: Union[wavelink.Player, None] = ctx.voice_client
if not player or not player.playing:
await ctx.send("I'm not connected to a voice channel.")
return
if ctx.author.voice is None or ctx.author.voice.channel != player.channel:
await ctx.send("You need to be in the same voice channel as me.")
return
filter_options = [
discord.SelectOption(label="Vaporwave", description="Apply vaporwave effect"),
discord.SelectOption(label="Nightcore", description="Apply nightcore effect"),
discord.SelectOption(label="Vibrato", description="Apply vibrato effect"),
discord.SelectOption(label="Tremolo", description="Apply tremolo effect"),
discord.SelectOption(label="Bassboost", description="Apply bass boost effect"),
discord.SelectOption(label="Karaoke", description="Apply karaoke effect"),
discord.SelectOption(label="Rotation", description="Apply rotation effect"),
discord.SelectOption(label="Distortion", description="Apply distortion effect"),
discord.SelectOption(label="Channelmix", description="Apply channel mix effect"),
]
class FilterSelect(discord.ui.View):
@discord.ui.select(placeholder="Choose a filter...", options=filter_options)
async def select_filter(self, interaction: discord.Interaction, select: discord.ui.Select):
await interaction.response.defer()
selected_filter = select.values[0].lower()
await self.cog.apply_filter(ctx, selected_filter)
#await interaction.message.delete()
self.disable_all()
@discord.ui.button(label="Cancel", style=discord.ButtonStyle.red)
async def cancel(self, interaction: discord.Interaction, button: discord.ui.Button):
await interaction.message.delete()
self.disable_all()
def disable_all(self):
for child in self.children:
child.disabled = True
self.stop()
view = FilterSelect()
view.cog = self
current_filter = self.active_filters.get(ctx.guild.id, "None")
embed = discord.Embed(title="Enable Filter", description="Choose a filter to apply:", color=discord.Color.blue())
embed.add_field(name="Current Filter", value=current_filter, inline=False)
await ctx.send(embed=embed, view=view)
@filter.command(help="Disable the current filter.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def disable(self, ctx: commands.Context):
player: Union[wavelink.Player, None] = ctx.voice_client
if not player or not player.playing:
await ctx.send("I'm not connected to a voice channel.")
return
if ctx.author.voice is None or ctx.author.voice.channel != player.channel:
await ctx.send("You need to be in the same voice channel as me.")
return
filters = wavelink.Filters()
await player.set_filters(filters)
self.active_filters.pop(ctx.guild.id, None)
await ctx.send(embed=discord.Embed(description="Filter disabled.", color=discord.Color.red()))

188
bot/cogs/commands/fun.py Normal file
View File

@@ -0,0 +1,188 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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
from discord.ui import LayoutView, TextDisplay, Separator, MediaGallery
import random
import aiohttp
from discord import app_commands
from utils.Tools import blacklist_check, ignore_check
from utils.cv2 import CV2, build_container
class Fun(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.giphy_api_key = "y3KcqQTdiS0RYcpNJrWn8hFGglKqX4is"
async def fetch_giphy(self, query):
async with aiohttp.ClientSession() as session:
async with session.get(f"https://api.giphy.com/v1/gifs/search?api_key={self.giphy_api_key}&q={query}&limit=30&rating=pg") as resp:
if resp.status != 200:
return None
data = await resp.json()
if data['data']:
return random.choice(data['data'])['images']['original']['url']
else:
return None
def random_emoji(self):
return random.choice(["😂", "🤣", "😆", "😳", "🥴", "🙃", "😜"])
async def action_command(self, ctx, user: discord.Member, action: str):
gif_url = await self.fetch_giphy(action)
if not gif_url:
await ctx.send(view=CV2("😒 Error", "GIPHY API is sleeping. Try later!"))
return
view = LayoutView(timeout=None)
gallery = MediaGallery()
gallery.add_item(media=gif_url)
view.add_item(build_container(
TextDisplay(f"**{ctx.author.mention} {action}s {user.mention} {self.random_emoji()}**"),
gallery
))
await ctx.send(view=view)
async def meter_command(self, ctx, title, user, text):
await ctx.send(view=CV2(title, text))
@commands.command(name="shipp")
@blacklist_check()
@ignore_check()
async def shipp(self, ctx, user1: discord.Member, user2: discord.Member):
percentage = random.randint(0, 100)
await ctx.send(view=CV2(f"{self.random_emoji()} Ship Result", f"**{user1.mention} x {user2.mention} = {percentage}% Love**"))
@commands.command()
@blacklist_check()
@ignore_check()
async def hug(self, ctx, user: discord.Member):
await self.action_command(ctx, user, "hug")
@commands.command()
@blacklist_check()
@ignore_check()
async def kiss(self, ctx, user: discord.Member):
await self.action_command(ctx, user, "kiss")
@commands.command()
@blacklist_check()
@ignore_check()
async def pat(self, ctx, user: discord.Member):
await self.action_command(ctx, user, "pat")
@commands.command()
@blacklist_check()
@ignore_check()
async def slap(self, ctx, user: discord.Member):
await self.action_command(ctx, user, "slap")
@commands.command()
@blacklist_check()
@ignore_check()
async def tickle(self, ctx, user: discord.Member):
await self.action_command(ctx, user, "tickle")
@commands.command()
@blacklist_check()
@ignore_check()
async def coinflip(self, ctx):
result = random.choice(["Heads", "Tails"])
await ctx.send(view=CV2("🪙 Coin Flip", f"**Result: {result}**"))
@commands.command()
@blacklist_check()
@ignore_check()
async def dice(self, ctx):
result = random.randint(1, 6)
await ctx.send(view=CV2("🎲 Dice Roll", f"**You rolled a {result}!**"))
@commands.command(name="8ball")
@blacklist_check()
@ignore_check()
async def eight_ball(self, ctx, *, question: str):
responses = ["It is certain.", "Without a doubt.", "You may rely on it.",
"Ask again later.", "Better not tell you now.",
"Don't count on it.", "My sources say no.", "Very doubtful."]
await ctx.send(view=CV2("🎱 Magic 8Ball", f"**Q:** {question}\n**A:** {random.choice(responses)}"))
@commands.command()
@blacklist_check()
@ignore_check()
async def roast(self, ctx, user: discord.Member):
roasts = [
f"{user.mention} you're the reason shampoo has instructions!",
f"{user.mention} you have something on your chin... no, the third one down!",
f"{user.mention} your secrets are safe with me. I never even listen when you tell me them."
]
await ctx.send(view=CV2("🔥 Roast Time", random.choice(roasts)))
@commands.command()
@blacklist_check()
@ignore_check()
async def iq(self, ctx, user: discord.Member = None):
user = user or ctx.author
await ctx.send(view=CV2("🧠 IQ Test", f"**{user.mention} has an IQ of {random.randint(50, 200)}!**"))
@commands.command()
@blacklist_check()
@ignore_check()
async def dumb(self, ctx, user: discord.Member = None):
user = user or ctx.author
await ctx.send(view=CV2("🤪 Dumbness Test", f"**{user.mention} is {random.randint(0, 100)}% dumb!**"))
@commands.command()
@blacklist_check()
@ignore_check()
async def simprate(self, ctx, user: discord.Member = None):
user = user or ctx.author
await ctx.send(view=CV2("😳 Simp Rate", f"**{user.mention} is {random.randint(0, 100)}% simp!**"))
@commands.command()
@blacklist_check()
@ignore_check()
async def toxic(self, ctx, user: discord.Member = None):
user = user or ctx.author
await ctx.send(view=CV2("☠️ Toxic Meter", f"**{user.mention} is {random.randint(0, 100)}% toxic!**"))
@commands.command()
@blacklist_check()
@ignore_check()
async def intelligence(self, ctx, user: discord.Member = None):
user = user or ctx.author
await ctx.send(view=CV2("🧠 Intelligence Meter", f"**{user.mention} has {random.randint(0, 200)} IQ Points!**"))
@commands.command()
@blacklist_check()
@ignore_check()
async def genius(self, ctx, user: discord.Member = None):
user = user or ctx.author
await ctx.send(view=CV2("🤓 Genius Rate", f"**{user.mention} is {random.randint(0, 100)}% genius!**"))
@commands.command()
@blacklist_check()
@ignore_check()
async def brainrate(self, ctx, user: discord.Member = None):
user = user or ctx.author
await ctx.send(view=CV2("🧠 Brain Power", f"**{user.mention} is using {random.randint(0, 100)}% of their brain!**"))
@commands.command()
@blacklist_check()
@ignore_check()
async def howhot(self, ctx, user: discord.Member = None):
user = user or ctx.author
await ctx.send(view=CV2("🔥 Hotness Meter", f"**{user.mention} is {random.randint(0, 100)}% hot!**"))
async def setup(bot):
await bot.add_cog(Fun(bot))

View File

@@ -0,0 +1,316 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import asyncio
import discord
from utils.emoji import CROSS, TICK, ZWARNING, ZYROXCONNECTION, ZYROXLINKS
from discord.ext import commands, tasks
from discord.utils import get
import datetime
import random
import requests
import aiohttp
import re
from discord.ext.commands.errors import BadArgument
from discord.ext.commands import Cog
from discord.colour import Color
import hashlib
from utils.Tools import *
from traceback import format_exception
from discord import ButtonStyle
from discord.ui import Button, View, LayoutView, TextDisplay, Separator, MediaGallery, ActionRow
import psutil
import time
from datetime import datetime, timezone, timedelta
import sqlite3
from typing import *
import string
from utils.cv2 import CV2, build_container
class AvatarView(View):
def __init__(self, user, member, author_id, banner_url):
super().__init__()
self.user = user
self.member = member
self.author_id = author_id
self.banner_url = banner_url
if self.user.avatar.is_animated():
self.add_item(Button(label='GIF', url=self.user.avatar.with_format('gif').url, style=discord.ButtonStyle.link))
self.add_item(Button(label='PNG', url=self.user.avatar.with_format('png').url, style=discord.ButtonStyle.link))
self.add_item(Button(label='JPEG', url=self.user.avatar.with_format('jpg').url, style=discord.ButtonStyle.link))
self.add_item(Button(label='WEBP', url=self.user.avatar.with_format('webp').url, style=discord.ButtonStyle.link))
async def interaction_check(self, interaction: discord.Interaction) -> bool:
if interaction.user.id != self.author_id:
await interaction.response.send_message(
"Uh oh! That message doesn't belong to you. You must run this command to interact with it.",
ephemeral=True
)
return False
return True
@discord.ui.button(label='Server Avatar', style=discord.ButtonStyle.success, custom_id='server_avatar_button')
async def server_avatar(self, interaction: discord.Interaction, button: Button):
if not self.member.guild_avatar:
await interaction.response.send_message(
"This user doesn't have a different guild avatar.",
ephemeral=True
)
else:
embed = interaction.message.embeds[0]
embed.set_image(url=self.member.guild_avatar.url)
await interaction.response.edit_message(embed=embed)
@discord.ui.button(label='User Banner', style=discord.ButtonStyle.success, custom_id='banner_button')
async def banner(self, interaction: discord.Interaction, button: Button):
if not self.banner_url:
await interaction.response.send_message(
"This user doesn't have a banner.",
ephemeral=True
)
else:
embed = interaction.message.embeds[0]
embed.set_image(url=self.banner_url)
await interaction.response.edit_message(embed=embed)
from utils.config import BotName
class General(commands.Cog):
def __init__(self, bot, *args, **kwargs):
self.bot = bot
self.aiohttp = aiohttp.ClientSession()
self._URL_REGEX = r'(?P<url><[^: >]+:\/[^ >]+>|(?:https?|steam):\/\/[^\s<]+[^<.,:;"\'\\]\s])'
self.color = 0xFF0000
@commands.hybrid_command(
usage="Avatar <member>",
name='avatar',
aliases=['av'],
help="Get User avater/Guild avatar & Banner of a user."
)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def _user(self, ctx, member: Optional[Union[discord.Member, discord.User]] = None):
try:
if member is None:
member = ctx.author
user = await self.bot.fetch_user(member.id)
banner_url = user.banner.url if user.banner else None
# Avatar still uses embed because AvatarView buttons edit embed images
description = f"[`PNG`]({user.avatar.with_format('png').url}) | [`JPG`]({user.avatar.with_format('jpg').url}) | [`WEBP`]({user.avatar.with_format('webp').url})"
if user.avatar.is_animated():
description += f" | [`GIF`]({user.avatar.with_format('gif').url})"
if banner_url:
description += f" | [`Banner`]({banner_url})"
embed = discord.Embed(
color=self.color,
description=description
)
embed.set_author(name=f"{member}", icon_url=member.avatar.url if member.avatar else member.default_avatar.url)
embed.set_image(url=user.avatar.url)
embed.set_footer(text=f"Requested By {ctx.author}",
icon_url=ctx.author.avatar.url if ctx.author.avatar else ctx.author.default_avatar.url)
view = AvatarView(user, member, ctx.author.id, banner_url)
await ctx.send(embed=embed, view=view)
except Exception as e:
print(f"Error: {e}")
@commands.hybrid_command(
name="servericon",
help="Get the server icon",
usage="Servericon"
)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def servericon(self, ctx: commands.Context):
server = ctx.guild
if server.icon is None:
await ctx.reply(view=CV2("❌ Error", "This server does not have an icon."))
return
webp = server.icon.replace(format='webp')
jpg = server.icon.replace(format='jpg')
png = server.icon.replace(format='png')
links = f"[`PNG`]({png}) | [`JPG`]({jpg}) | [`WEBP`]({webp})"
if server.icon.is_animated():
gif = server.icon.replace(format='gif')
links += f" | [`GIF`]({gif})"
view = LayoutView(timeout=None)
gallery = MediaGallery()
gallery.add_item(media=str(server.icon.url))
dl_btn = Button(label="Download Icon", url=str(server.icon.url), style=ButtonStyle.link)
view.add_item(build_container(
TextDisplay(f"**{server}'s Icon**"),
Separator(visible=True),
TextDisplay(links),
gallery,
ActionRow(dl_btn)
))
await ctx.send(view=view)
@commands.hybrid_command(name="membercount",
help="Get total member count of the server",
usage="membercount",
aliases=["mc"])
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 2, commands.BucketType.user)
async def membercount(self, ctx: commands.Context):
total_members = len(ctx.guild.members)
total_humans = len([m for m in ctx.guild.members if not m.bot])
total_bots = len([m for m in ctx.guild.members if m.bot])
online = len([m for m in ctx.guild.members if m.status == discord.Status.online])
offline = len([m for m in ctx.guild.members if m.status == discord.Status.offline])
idle = len([m for m in ctx.guild.members if m.status == discord.Status.idle])
dnd = len([m for m in ctx.guild.members if m.status == discord.Status.do_not_disturb])
stats_text = (
f"**__Count Stats:__**\n"
f"Total Members: {total_members}\nTotal Humans: {total_humans}\nTotal Bots: {total_bots}\n\n"
f"**__Presence Stats:__**\n"
f"Online: {online} | DND: {dnd} | Idle: {idle} | Offline: {offline}"
)
await ctx.send(view=CV2("Member Statistics", stats_text))
@commands.hybrid_command(name="poll", usage="Poll <message>")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def poll(self, ctx: commands.Context, *, message):
author = ctx.author
msg = await ctx.send(view=CV2(f"**Poll raised by {author}!**", message))
await msg.add_reaction(TICK)
await msg.add_reaction(CROSS)
@commands.command(name="users", help=f"checks total users of {BotName}.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def users(self, ctx: commands.Context):
users = sum(g.member_count for g in self.bot.guilds
if g.member_count != None)
guilds = len(self.bot.guilds)
await ctx.send(view=CV2(f"{BotName} Users", f" Total of __**{users}**__ Users in **{guilds}** Guilds"))
@commands.hybrid_command(
name="urban",
description="Searches for specified phrase on urbandictionary",
help="Get meaning of specified phrase",
usage="Urban <phrase>")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def urban(self, ctx: commands.Context, *, phrase):
async with self.aiohttp.get(
"http://api.urbandictionary.com/v0/define?term={}".format(
phrase)) as urb:
urban = await urb.json()
try:
definition = urban['list'][0]['definition'].replace('[', '').replace(']', '')
example = urban['list'][0]['example'].replace('[', '').replace(']', '')
author = urban['list'][0]['author'].replace('[', '').replace(']', '')
written_on = urban['list'][0]['written_on'].replace('[', '').replace(']', '')
urban_text = (
f"**__Definition:__**\n{definition}\n\n"
f"**__Example:__**\n{example}\n\n"
f"**__Author:__** {author}\n"
f"**__Written On:__** {written_on}"
)
temp = await ctx.reply(view=CV2(f"Meaning of \"{phrase}\"", urban_text), mention_author=True)
await asyncio.sleep(45)
await temp.delete()
await ctx.message.delete()
except:
pass
@commands.command(name="rickroll",
help="Detects if provided url is a rick-roll",
usage="Rickroll <url>")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def rickroll(self, ctx: commands.Context, *, url: str):
if not re.match(self._URL_REGEX, url):
raise BadArgument("Invalid URL")
phrases = [
"rickroll", "rick roll", "rick astley", "never gonna give you up"
]
source = str(await (await self.aiohttp.get(
url, allow_redirects=True)).content.read()).lower()
rickRoll = bool((re.findall('|'.join(phrases), source,
re.MULTILINE | re.IGNORECASE)))
title = "Rick Roll {} in webpage".format("was found" if rickRoll else "was not found")
await ctx.reply(view=CV2(title, "🎵 Never gonna give you up..." if rickRoll else "✅ Safe to click!"), mention_author=True)
@commands.command(name="hash",
help="Hashes provided text with provided algorithm")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def hash(self, ctx: commands.Context, algorithm: str, *, message):
algos: dict[str, str] = {
"md5": hashlib.md5(bytes(message.encode("utf-8"))).hexdigest(),
"sha1": hashlib.sha1(bytes(message.encode("utf-8"))).hexdigest(),
"sha224": hashlib.sha224(bytes(message.encode("utf-8"))).hexdigest(),
"sha3_224": hashlib.sha3_224(bytes(message.encode("utf-8"))).hexdigest(),
"sha256": hashlib.sha256(bytes(message.encode("utf-8"))).hexdigest(),
"sha3_256": hashlib.sha3_256(bytes(message.encode("utf-8"))).hexdigest(),
"sha384": hashlib.sha384(bytes(message.encode("utf-8"))).hexdigest(),
"sha3_384": hashlib.sha3_384(bytes(message.encode("utf-8"))).hexdigest(),
"sha512": hashlib.sha512(bytes(message.encode("utf-8"))).hexdigest(),
"sha3_512": hashlib.sha3_512(bytes(message.encode("utf-8"))).hexdigest(),
"blake2b": hashlib.blake2b(bytes(message.encode("utf-8"))).hexdigest(),
"blake2s": hashlib.blake2s(bytes(message.encode("utf-8"))).hexdigest()
}
if algorithm.lower() not in list(algos.keys()):
hash_lines = "\n".join(f"**{algo}:** `{algos[algo]}`" for algo in algos)
else:
hash_lines = f"**{algorithm}:** `{algos[algorithm.lower()]}`"
await ctx.reply(view=CV2(f"Hashed \"{message}\"", hash_lines), mention_author=True)
@commands.command(
name="invite",
aliases=['invite-bot'],
description="Get Support & Bot invite link!"
)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def invite(self, ctx: commands.Context):
invite_text = (
"```Empower your server with blazing-fast features and 24/7 support!```\n"
f"{ZYROXLINKS} **Quick Actions**\n"
f">>> **[Invite {BotName}](https://discord.com/oauth2/authorize?client_id=1396114795102470196&permissions=8&integration_type=0&scope=bot+applications.commands)**\n"
"**[Support Server](https://discord.gg/codexdev)**"
)
await ctx.send(view=CV2(f"{ZYROXCONNECTION} {BotName} Integration Hub!", invite_text))

View File

@@ -0,0 +1,413 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
from discord.ext import commands, tasks
import datetime, pytz, time as t
from discord.ui import Button, Select, View
import aiosqlite, random, typing
import sqlite3
import asyncio
import discord, logging
from utils.emoji import ARROWRED, TADAA, TICK
from discord.utils import get
from utils.Tools import *
import os
import aiohttp
from utils.cv2 import CV2
db_folder = 'db'
db_file = 'giveaways.db'
db_path = os.path.join(db_folder, db_file)
connection = sqlite3.connect(db_path)
cursor = connection.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS Giveaway (
guild_id INTEGER,
host_id INTEGER,
start_time TIMESTAMP,
ends_at TIMESTAMP,
prize TEXT,
winners INTEGER,
message_id INTEGER,
channel_id INTEGER,
PRIMARY KEY (guild_id, message_id)
)''')
connection.commit()
connection.close()
def convert(time):
pos = ["s","m","h","d"]
time_dict = {"s" : 1, "m" : 60, "h" : 3600 , "d" : 86400 , "f" : 259200}
unit = time[-1]
if unit not in pos:
return
try:
val = int(time[:-1])
except ValueError:
return
return val * time_dict[unit]
def WinnerConverter(winner):
try:
int(winner)
except ValueError:
try:
return int(winner[:-1])
except:
return -4
return winner
class Giveaway(commands.Cog):
def __init__(self, bot):
self.bot = bot
async def cog_load(self) -> None:
self.connection = await aiosqlite.connect(db_path)
self.cursor = await self.connection.cursor()
await self.check_for_ended_giveaways()
self.GiveawayEnd.start()
async def cog_unload(self) -> None:
await self.connection.close()
async def check_for_ended_giveaways(self):
await self.cursor.execute("SELECT ends_at, guild_id, message_id, host_id, winners, prize, channel_id FROM Giveaway WHERE ends_at <= ?", (datetime.datetime.now().timestamp(),))
ended_giveaways = await self.cursor.fetchall()
for giveaway in ended_giveaways:
await self.end_giveaway(giveaway)
async def end_giveaway(self, giveaway):
try:
current_time = datetime.datetime.now().timestamp()
guild = self.bot.get_guild(int(giveaway[1]))
if guild is None:
await self.cursor.execute("DELETE FROM Giveaway WHERE message_id = ? AND guild_id = ?", (giveaway[2], giveaway[1]))
await self.connection.commit()
return
channel = self.bot.get_channel(int(giveaway[6]))
if channel is not None:
try:
retries = 3
for attempt in range(retries):
try:
message = await channel.fetch_message(int(giveaway[2]))
break
except discord.NotFound:
await self.cursor.execute("DELETE FROM Giveaway WHERE message_id = ? AND guild_id = ?", (giveaway[2], giveaway[1]))
await self.connection.commit()
return
except aiohttp.ClientResponseError as e:
if e.status == 503:
if attempt < retries - 1:
await asyncio.sleep(2 ** attempt)
continue
else:
raise
else:
raise
users = [i.id async for i in message.reactions[0].users()]
if self.bot.user.id in users:
users.remove(self.bot.user.id)
if len(users) < 1:
await message.reply(f"No one won the **{giveaway[5]}** giveaway, due to Not enough participants.")
await self.cursor.execute("DELETE FROM Giveaway WHERE message_id = ? AND guild_id = ?", (message.id, message.guild.id))
await self.connection.commit()
return
winners_count = min(len(users), int(giveaway[4]))
winner = ', '.join(f'<@!{i}>' for i in random.sample(users, k=winners_count))
desc = f"Ended at <t:{int(current_time)}:R>\nHosted by <@{int(giveaway[3])}>\nWinner(s): {winner}"
view = CV2(f"{giveaway[5]}", desc)
await message.edit(content=f"{TADAA} **GIVEAWAY ENDED** {TADAA}", view=view)
await message.reply(f"{TADAA} Congrats {winner}, you won **{giveaway[5]}!**, Hosted by <@{int(giveaway[3])}>")
await self.cursor.execute("DELETE FROM Giveaway WHERE message_id = ? AND guild_id = ?", (message.id, message.guild.id))
await self.connection.commit()
except (discord.HTTPException, aiohttp.ClientResponseError) as e:
logging.error(f"Error ending giveaway: {e}")
except IndexError:
logging.error(f"Giveaway data is corrupted or missing: {giveaway}")
await self.cursor.execute("DELETE FROM Giveaway WHERE message_id = ? AND guild_id = ?", (giveaway[2], giveaway[1]))
await self.connection.commit()
@tasks.loop(seconds=5)
async def GiveawayEnd(self):
await self.cursor.execute("SELECT ends_at, guild_id, message_id, host_id, winners, prize, channel_id FROM Giveaway WHERE ends_at <= ?", (datetime.datetime.now().timestamp(),))
ends_raw = await self.cursor.fetchall()
for giveaway in ends_raw:
await self.end_giveaway(giveaway)
@commands.hybrid_command(description="Starts a new giveaway.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_guild_permissions(manage_guild=True)
async def gstart(self, ctx,
time,
winners: int,
*,
prize: str):
await self.cursor.execute("SELECT message_id, channel_id FROM Giveaway WHERE guild_id = ?", (ctx.guild.id,))
re = await self.cursor.fetchall()
if winners >= 15:
message = await ctx.send(view=CV2("⚠️ Access Denied", "Cannot exceed more than 15 winners."))
await asyncio.sleep(5)
await message.delete()
return
g_list = [i[0] for i in re]
if len(g_list) >= 5:
message = await ctx.send(view=CV2("⚠️ Access Denied", "You can only host upto 5 giveaways in this Guild."))
await asyncio.sleep(5)
await message.delete()
return
converted = self.convert(time)
if converted / 60 >= 50400:
message = await ctx.send(view=CV2("⚠️ Access Denied", "Time cannot exceed 31 days!"))
await asyncio.sleep(5)
await message.delete()
return
if converted == -1:
message = await ctx.send(view=CV2("❌ Error", "Invalid time format"))
await asyncio.sleep(5)
await message.delete()
return
if converted == -2:
message = await ctx.send(view=CV2("❌ Error", "Invalid time format. Please provide the time in numbers."))
await asyncio.sleep(5)
await message.delete()
return
ends = (datetime.datetime.now().timestamp() + converted)
desc = (
f"{ARROWRED} Winner(s): **{winners}**\n"
f"{ARROWRED} Hosted by {ctx.author.mention}\n"
f"{ARROWRED} Ends <t:{round(ends)}:R> (<t:{round(ends)}:f>)\n\n"
f"{ARROWRED} React with {TADAA} to participate!"
)
view = CV2(f"{TADAA} {prize}", desc)
message = await ctx.send(f"{TADAA} **GIVEAWAY** {TADAA}", view=view)
try:
await ctx.message.delete()
except:
pass
await self.cursor.execute("INSERT INTO Giveaway(guild_id, host_id, start_time, ends_at, prize, winners, message_id, channel_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?)", (ctx.guild.id, ctx.author.id, datetime.datetime.now(), ends, prize, winners, message.id, ctx.channel.id))
await message.add_reaction(TADAA)
await self.connection.commit()
@commands.Cog.listener("on_message_delete")
async def GiveawayMessageDelete(self, message):
await self.cursor.execute("SELECT message_id FROM Giveaway WHERE guild_id = ?", (message.guild.id,))
re = await self.cursor.fetchone()
if message.author != self.bot.user:
return
if re is not None:
if message.id == int(re[0]):
await self.cursor.execute("DELETE FROM Giveaway WHERE channel_id = ? AND message_id = ? AND guild_id = ?", (message.channel.id, message.id, message.guild.id))
print(f"Giveaway message deleted in {message.guild.name} - {message.guild.id}")
await self.connection.commit()
@commands.hybrid_command(name="gend", description="Ends a giveaway before its ending time.", help="Ends a giveaway before its ending time.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_guild_permissions(manage_guild=True)
async def gend(self, ctx, message_id = None):
if message_id:
try:
int(message_id)
except ValueError:
message = await ctx.send(view=CV2("⚠️ Access Denied", "Invalid message ID provided."))
await asyncio.sleep(5)
await message.delete()
return
if message_id is not None:
current_time = datetime.datetime.now().timestamp()
await self.cursor.execute('SELECT ends_at, guild_id, message_id, host_id, winners, prize, channel_id FROM Giveaway WHERE message_id = ?', (int(message_id),))
re = await self.cursor.fetchone()
if re is None:
message = await ctx.send(view=CV2("❌ Error", "The giveaway was not found."))
await asyncio.sleep(5)
await message.delete()
return
ch = self.bot.get_channel(int(re[6]))
message = await ch.fetch_message(int(message_id))
users = [i.id async for i in message.reactions[0].users()]
users.remove(self.bot.user.id)
if len(users) < 1:
await ctx.send(f"{TICK} Successfully Ended the giveaway in <#{int(re[6])}>")
await message.reply(f"No one won the **{re[5]}** giveaway, due to Not enough participants.")
await self.cursor.execute("DELETE FROM Giveaway WHERE message_id = ? AND guild_id = ?", (message.id, message.guild.id))
return
winner = ', '.join(f'<@!{i}>' for i in random.sample(users, k=int(re[4])))
desc = f"Ended at <t:{int(current_time)}:R>\nHosted by <@{int(re[3])}>\nWinner(s): {winner}"
view = CV2(f"🎁 {re[5]}", desc)
await message.edit(content="🎁 **GIVEAWAY ENDED** 🎁", view=view)
if int(ctx.channel.id) != int(re[6]):
await ctx.send(f"{TADAA} Successfully ended the giveaway in <#{int(re[6])}>")
await message.reply(f" Congrats {winner}, you won **{re[5]}!**, Hosted by <@{int(re[3])}>")
await self.cursor.execute("DELETE FROM Giveaway WHERE message_id = ? AND guild_id = ?", (message.id, message.guild.id))
elif ctx.message.reference:
await self.cursor.execute('SELECT ends_at, guild_id, message_id, host_id, winners, prize, channel_id FROM Giveaway WHERE message_id = ?', (ctx.message.reference.resolved.id,))
re = await self.cursor.fetchone()
if re is None:
return await ctx.send(f"The giveaway was not found.")
current_time = datetime.datetime.now().timestamp()
message = await ctx.fetch_message(ctx.message.reference.message_id)
users = [i.id async for i in message.reactions[0].users()]
try: users.remove(self.bot.user.id)
except: pass
if len(users) < 1:
await message.reply(f"No one won the **{re[5]}** giveaway, due to not enough participants.")
await self.cursor.execute("DELETE FROM Giveaway WHERE message_id = ? AND guild_id = ?", (message.id, message.guild.id))
return
winner = ', '.join(f'<@!{i}>' for i in random.sample(users, k=int(re[4])))
desc = f"Ended <t:{int(current_time)}:R>\nHosted by <@{int(re[3])}>\nWinner(s): {winner}"
view = CV2(f"🎁 {re[5]}", desc)
await message.edit(content="🎁 **GIVEAWAY ENDED** 🎁", view=view)
await message.reply(f"💐 Congrats {winner}, you won **{re[5]}!**, Hosted by <@{int(re[3])}>")
await self.cursor.execute("DELETE FROM Giveaway WHERE message_id = ? AND guild_id = ?", (message.id, message.guild.id))
else:
await ctx.send("Please reply to the giveaway message or provide the giveaway ID.")
await self.connection.commit()
@commands.hybrid_command(description="Rerolls a giveaway on replying the giveaway message.", help="Rerolls a giveaway on replying the giveaway message.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_guild_permissions(manage_guild=True)
async def greroll(self, ctx, message_id: typing.Optional[int] = None):
if not ctx.message.reference:
message = await ctx.reply("Reply this command with the Giveaway Ended message to reroll.")
await asyncio.sleep(5)
await message.delete()
return
if ctx.message.reference:
message_id = ctx.message.reference.resolved.id
message = await ctx.fetch_message(message_id)
if ctx.message.reference.resolved.author.id != self.bot.user.id :
msg = await ctx.send(view=CV2("⚠️ Access Denied", "The giveaway was not found."))
await asyncio.sleep(5)
await msg.delete()
return
await self.cursor.execute(f"SELECT message_id FROM Giveaway WHERE message_id = ?", (message.id,))
re = await self.cursor.fetchone()
if re is not None:
msg = await ctx.send(view=CV2("⚠️ Access Denied", "The giveaway is currently running. Please use the `gend` command instead to end the giveaway."))
await asyncio.sleep(5)
await msg.delete()
return
users = [i.id async for i in message.reactions[0].users()]
users.remove(self.bot.user.id)
if len(users) < 1:
await message.reply(f"No one won the **{re[5]}** giveaway, due to not enough participants.")
return
winners = random.sample(users, k=1)
await message.reply(f" The new winner is "+", ".join(f"<@{i}>" for i in winners)+". Congratulations!")
await self.connection.commit()
def convert(self, time):
pos = ["s", "m", "h", "d"]
time_dict = {"s": 1, "m": 60, "h": 3600, "d": 86400, "f": 259200}
unit = time[-1]
if unit not in pos:
return -1
try:
val = int(time[:-1])
except ValueError:
return -2
return val * time_dict[unit]
@commands.hybrid_command(name="glist", description="Lists all ongoing giveaways.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.has_guild_permissions(manage_guild=True)
async def glist(self, ctx):
await self.cursor.execute("SELECT prize, ends_at, winners, message_id FROM Giveaway WHERE guild_id = ?", (ctx.guild.id,))
giveaways = await self.cursor.fetchall()
if not giveaways:
await ctx.send(view=CV2("Ongoing Giveaways", "No ongoing giveaways."))
return
desc = ""
for giveaway in giveaways:
prize, ends_at, winners, message_id = giveaway
desc += f"**{prize}**\nEnds: <t:{int(ends_at)}:R> (<t:{int(ends_at)}:f>)\nWinners: {winners}\n[Jump to Message](https://discord.com/channels/{ctx.guild.id}/{ctx.channel.id}/{message_id})\n\n"
await ctx.send(view=CV2("Ongoing Giveaways", desc))
async def setup(bot):
await bot.add_cog(Giveaway(bot))

285
bot/cogs/commands/help.py Normal file
View File

@@ -0,0 +1,285 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import ARROWRED, BOOST, CAST, GAMES, LEVEL_UP, LOADINGRED, LOCK, MESSAGE, MINECRAFT, MUSIC, NEW, PIN, SEED, STAR, SWORD, SYSTEM, THUNDER, TICKET, WIFI, ZAI, ZARROW, ZBAN, ZBOT, ZCIRCLE, ZCIRCLE_ALT1, ZCLOUD, ZCOUNTING, ZMODULE, ZPEOPLE, ZROCKET, ZSAFE, ZTADA, ZUNMUTE, ZWRENCH
from discord.ext import commands
from discord import app_commands, Interaction
from difflib import get_close_matches
from contextlib import suppress
from core import Context
from core.zyrox import zyrox
from core.Cog import Cog
from utils.Tools import getConfig
from itertools import chain
import json
from utils import help as vhelp
from utils import Paginator, DescriptionEmbedPaginator, FieldPagePaginator, TextPaginator
import asyncio
from utils.config import serverLink
from utils.Tools import *
from utils.cv2 import CV2, CV2Embed
from utils.config import *
color = 0xFF0000
client = zyrox()
from utils.config import BotName
class HelpCommand(commands.HelpCommand):
async def send_ignore_message(self, ctx, ignore_type: str):
if ignore_type == "channel":
await ctx.reply(f"This channel is ignored.", mention_author=False)
elif ignore_type == "command":
await ctx.reply(f"{ctx.author.mention} This Command, Channel, or You have been ignored here.", delete_after=6)
elif ignore_type == "user":
await ctx.reply(f"You are ignored.", mention_author=False)
async def on_help_command_error(self, ctx, error):
errors = [
commands.CommandOnCooldown, commands.CommandNotFound,
discord.HTTPException, commands.CommandInvokeError
]
if not type(error) in errors:
await self.context.reply(f"Unknown Error Occurred\n{error.original}",
mention_author=False)
else:
if type(error) == commands.CommandOnCooldown:
return
return await super().on_help_command_error(ctx, error)
async def command_not_found(self, string: str) -> None:
ctx = self.context
check_ignore = await ignore_check().predicate(ctx)
check_blacklist = await blacklist_check().predicate(ctx)
if not check_blacklist:
return
if not check_ignore:
await self.send_ignore_message(ctx, "command")
return
cmds = (str(cmd) for cmd in self.context.bot.walk_commands())
matches = get_close_matches(string, cmds)
embed = CV2Embed(
title=f"{BotName} Helper",
description=f">>> **Ops! Command not found with the name** `{string}`.",
color=0xFF0000
)
await ctx.reply(view=embed, mention_author=True)
async def send_bot_help(self, mapping):
ctx = self.context
check_ignore = await ignore_check().predicate(ctx)
check_blacklist = await blacklist_check().predicate(ctx)
if not check_blacklist:
return
if not check_ignore:
await self.send_ignore_message(ctx, "command")
return
# Show loading message
loading_embed = CV2(f"{LOADINGRED} Loading help Menu...")
loading_msg = await ctx.reply(view=loading_embed)
# Wait 2 seconds
await asyncio.sleep(2)
# Delete loading message
with suppress(discord.NotFound):
await loading_msg.delete()
data = await getConfig(self.context.guild.id)
prefix = data["prefix"]
filtered = await self.filter_commands(self.context.bot.walk_commands(), sort=True)
embed = CV2Embed(
description=(
f"**{ARROWRED} __Start {BotName} Today__**\n"
f"**{ZARROW} Type {prefix}antinuke enable**\n"
f"**{ZARROW} Server Prefix:** `{prefix}`\n"
f"**{ZARROW} Total Commands:** `{len(set(self.context.bot.walk_commands()))}`\n"),
color=0xFF0000)
embed.add_field(
name=f"{ZCLOUD} Main Features",
value=f">>> \n {ZSAFE} `»` Security\n"
f" {ZBOT} `»` Automoderation\n"
f" {ZWRENCH} `»` Utility\n"
f" {MUSIC} `»` Music\n"
f" {WIFI} `»` Autoreact & responder\n"
f" {SWORD} `»` Moderation\n"
f" {ZPEOPLE} `»` Autorole & Invc\n"
f" {ZROCKET} `»` Fun\n"
f" {GAMES} `»` Games\n"
f" {ZBAN} `»` Ignore Channels\n"
f" {WIFI} `»` Server\n"
f" {ZUNMUTE} `»` Voice\n"
f" {SEED} `»` Welcomer\n"
f" {ZTADA} `»` Giveaway\n"
f" {TICKET} `»` Ticket {NEW}\n"
f" {ZPEOPLE} `»` Invite Tracker {NEW}\n"
)
embed.add_field(
name=f" {ZMODULE} Extra Features",
value=f">>> \n {CAST} `»` Advance Logging\n"
f" {STAR} `»` Vanityroles\n"
f" {ZCOUNTING} `»` Counting {NEW}\n"
f" {SYSTEM} `»` J2C {NEW}\n"
f" {ZAI} `»` AI {NEW}\n"
f" {BOOST} `»` Boost {NEW}\n"
f" {LEVEL_UP} `»` Leveling {NEW}\n"
f" {PIN} `»` Sticky {NEW}\n"
f" {THUNDER} `»` Verification {NEW}\n"
f" {LOCK} `»` Encryption {NEW}\n"
f" {MINECRAFT} `»` Minecraft {NEW}\n"
f" {MESSAGE} `»` Joindm {NEW}\n"
f" {ZCIRCLE} `»` Birthday {NEW}\n"
f" {ZCIRCLE_ALT1} `»` Customrole\n"
)
embed.set_footer(
text=f"Requested By {self.context.author} | [Support](https://discord.gg/codexdev)",
)
view = vhelp.View(mapping=mapping, ctx=self.context, homeembed=embed, ui=2)
await ctx.reply(view=view)
async def send_command_help(self, command):
ctx = self.context
check_ignore = await ignore_check().predicate(ctx)
check_blacklist = await blacklist_check().predicate(ctx)
if not check_blacklist:
return
if not check_ignore:
await self.send_ignore_message(ctx, "command")
return
zyrox = f">>> {command.help}" if command.help else '>>> No Help Provided...'
embed = CV2Embed(
description=f"""{zyrox}""",
color=color)
alias = ' & '.join(command.aliases)
embed.add_field(name="**Alt cmd**",
value=f"```{alias}```" if command.aliases else "No Alt cmd",
inline=False)
embed.add_field(name="**Usage**",
value=f"```{self.context.prefix}{command.signature}```\n")
embed.set_author(name=f"{command.qualified_name.title()} Command")
embed.set_footer(text="<[] = optional | < > = required • Use Prefix Before Commands.")
await self.context.reply(view=embed, mention_author=False)
def get_command_signature(self, command: commands.Command) -> str:
parent = command.full_parent_name
if len(command.aliases) > 0:
aliases = ' | '.join(command.aliases)
fmt = f'[{command.name} | {aliases}]'
if parent:
fmt = f'{parent}'
alias = f'[{command.name} | {aliases}]'
else:
alias = command.name if not parent else f'{parent} {command.name}'
return f'{alias} {command.signature}'
def common_command_formatting(self, embed_like, command):
embed_like.title = self.get_command_signature(command)
if command.description:
embed_like.description = f'{command.description}\n\n{command.help}'
else:
embed_like.description = command.help or 'No help found...'
async def send_group_help(self, group):
ctx = self.context
check_ignore = await ignore_check().predicate(ctx)
check_blacklist = await blacklist_check().predicate(ctx)
if not check_blacklist:
return
if not check_ignore:
await self.send_ignore_message(ctx, "command")
return
entries = [
(
f"`{self.context.prefix}{cmd.qualified_name}`\n",
f"{cmd.short_doc if cmd.short_doc else ''}\n\u200b"
)
for cmd in group.commands
]
count = len(group.commands)
embeds = FieldPagePaginator(
entries=entries,
title=f"{group.qualified_name.title()} [{count}]",
description="< > Duty | [ ] Optional\n",
per_page=4
).get_pages()
paginator = Paginator(ctx, embeds)
await paginator.paginate()
async def send_cog_help(self, cog):
ctx = self.context
check_ignore = await ignore_check().predicate(ctx)
check_blacklist = await blacklist_check().predicate(ctx)
if not check_blacklist:
return
if not check_ignore:
await self.send_ignore_message(ctx, "command")
return
entries = [(
f"> `{self.context.prefix}{cmd.qualified_name}`",
f"-# Description : {cmd.short_doc if cmd.short_doc else ''}"
f"\n\u200b",
) for cmd in cog.get_commands()]
paginator = Paginator(source=FieldPagePaginator(
entries=entries,
title=f"{BRAND_NAME}'s {cog.qualified_name.title()} ({len(cog.get_commands())})",
description="`<..> Required | [..] Optional`\n\n",
color=0xFF0000,
per_page=4),
ctx=self.context)
await paginator.paginate()
class Help(Cog, name="help"):
def __init__(self, client: zyrox):
self._original_help_command = client.help_command
attributes = {
'name': "help",
'aliases': ['h'],
'cooldown': commands.CooldownMapping.from_cooldown(1, 5, commands.BucketType.user),
'help': 'Shows help about bot, a command, or a category'
}
client.help_command = HelpCommand(command_attrs=attributes)
client.help_command.cog = self
async def cog_unload(self):
self.help_command = self._original_help_command

View File

@@ -0,0 +1,278 @@
import discord
from utils.emoji import ARROWRED, BOOST, CAST, GAMES, LEVEL_UP, LOADINGRED, LOCK, MESSAGE, MINECRAFT, MUSIC, NEW, PIN, SEED, STAR, SWORD, SYSTEM, THUNDER, TICKET, WIFI, ZAI, ZARROW, ZBAN, ZBOT, ZCIRCLE, ZCIRCLE_ALT1, ZCLOUD, ZCOUNTING, ZMODULE, ZPEOPLE, ZROCKET, ZSAFE, ZTADA, ZUNMUTE, ZWRENCH
from discord.ext import commands
from discord import app_commands, Interaction
from difflib import get_close_matches
from contextlib import suppress
from core import Context
from core.zyrox import zyrox
from core.Cog import Cog
from utils.Tools import getConfig
from itertools import chain
import json
from utils import help as vhelp
from utils import Paginator, DescriptionEmbedPaginator, FieldPagePaginator, TextPaginator
import asyncio
from utils.config import serverLink
from utils.Tools import *
color = 0xFF0000
client = zyrox()
class HelpCommand(commands.HelpCommand):
async def send_ignore_message(self, ctx, ignore_type: str):
if ignore_type == "channel":
await ctx.reply(f"This channel is ignored.", mention_author=False)
elif ignore_type == "command":
await ctx.reply(f"{ctx.author.mention} This Command, Channel, or You have been ignored here.", delete_after=6)
elif ignore_type == "user":
await ctx.reply(f"You are ignored.", mention_author=False)
async def on_help_command_error(self, ctx, error):
errors = [
commands.CommandOnCooldown, commands.CommandNotFound,
discord.HTTPException, commands.CommandInvokeError
]
if not type(error) in errors:
await self.context.reply(f"Unknown Error Occurred\n{error.original}",
mention_author=False)
else:
if type(error) == commands.CommandOnCooldown:
return
return await super().on_help_command_error(ctx, error)
async def command_not_found(self, string: str) -> None:
ctx = self.context
check_ignore = await ignore_check().predicate(ctx)
check_blacklist = await blacklist_check().predicate(ctx)
if not check_blacklist:
return
if not check_ignore:
await self.send_ignore_message(ctx, "command")
return
cmds = (str(cmd) for cmd in self.context.bot.walk_commands())
matches = get_close_matches(string, cmds)
embed = discord.Embed(
title="Zyrox Helper",
description=f">>> **Ops! Command not found with the name** `{string}`.",
color=0xFF0000
)
#if matches:
#match_list = "\n".join([f"{index}. `{match}`" for index, match in enumerate(matches, start=1)])
#embed.add_field(name="Did you mean:", value=match_list, inline=True)
await ctx.reply(embed=embed, mention_author=True)
async def send_bot_help(self, mapping):
ctx = self.context
check_ignore = await ignore_check().predicate(ctx)
check_blacklist = await blacklist_check().predicate(ctx)
if not check_blacklist:
return
if not check_ignore:
await self.send_ignore_message(ctx, "command")
return
# Show loading embed
loading_embed = discord.Embed(
description=f"{LOADINGRED} Loading help Menu...",
color=0xFF0000
)
loading_msg = await ctx.reply(embed=loading_embed)
# Wait 2 seconds
await asyncio.sleep(2)
# Delete loading message
with suppress(discord.NotFound):
await loading_msg.delete()
data = await getConfig(self.context.guild.id)
prefix = data["prefix"]
filtered = await self.filter_commands(self.context.bot.walk_commands(), sort=True)
embed = discord.Embed(
description=(
f"**{ARROWRED} __Start Zyrox X Today__**\n"
f"**{ZARROW} Type {prefix}antinuke enable**\n"
f"**{ZARROW} Server Prefix:** `{prefix}`\n"
f"**{ZARROW} Total Commands:** `{len(set(self.context.bot.walk_commands()))}`\n"),
color=0xFF0000)
embed.set_author(name=f"{ctx.author}",
icon_url=ctx.author.display_avatar.url)
embed.set_thumbnail(url=ctx.author.display_avatar.url)
embed.add_field(
name=f"{ZCLOUD} __**Main Features**__",
value=f">>> \n {ZSAFE} `»` Security\n"
f" {ZBOT} `»` Automoderation\n"
f" {ZWRENCH} `»` Utility\n"
f" {MUSIC} `»` Music\n"
f" {WIFI} `»` Autoreact & responder\n"
f" {SWORD} `»` Moderation\n"
f" {ZPEOPLE} `»` Autorole & Invc\n"
f" {ZROCKET} `»` Fun\n"
f" {GAMES} `»` Games\n"
f" {ZBAN} `»` Ignore Channels\n"
f" {WIFI} `»` Server\n"
f" {ZUNMUTE} `»` Voice\n"
f" {SEED} `»` Welcomer\n"
f" {ZTADA} `»` Giveaway\n"
f" {TICKET} `»` Ticket {NEW}\n"
f" {ZPEOPLE} `»` Invite Tracker {NEW}\n"
)
embed.add_field(
name=f" {ZMODULE} __**Extra Features**__",
value=f">>> \n {CAST} `»` Advance Logging\n"
f" {STAR} `»` Vanityroles\n"
f" {ZCOUNTING} `»` Counting {NEW}\n"
f" {SYSTEM} `»` J2C {NEW}\n"
f" {ZAI} `»` AI {NEW}\n"
f" {BOOST} `»` Boost {NEW}\n"
f" {LEVEL_UP} `»` Leveling {NEW}\n"
f" {PIN} `»` Sticky {NEW}\n"
f" {THUNDER} `»` Verification {NEW}\n"
f" {LOCK} `»` Encryption {NEW}\n"
f" {MINECRAFT} `»` Minecraft {NEW}\n"
f" {MESSAGE} `»` Joindm {NEW}\n"
f" {ZCIRCLE} `»` Birthday {NEW}\n"
f" {ZCIRCLE_ALT1} `»` Customrole\n"
)
embed.set_footer(
text=f"Requested By {self.context.author} | [Support](https://discord.gg/codexdev)",
)
view = vhelp.View(mapping=mapping, ctx=self.context, homeembed=embed, ui=2)
await ctx.reply(embed=embed, view=view)
async def send_command_help(self, command):
ctx = self.context
check_ignore = await ignore_check().predicate(ctx)
check_blacklist = await blacklist_check().predicate(ctx)
if not check_blacklist:
return
if not check_ignore:
await self.send_ignore_message(ctx, "command")
return
zyrox = f">>> {command.help}" if command.help else '>>> No Help Provided...'
embed = discord.Embed(
description=f"""{zyrox}""",
color=color)
alias = ' & '.join(command.aliases)
embed.add_field(name="**Alt cmd**",
value=f"```{alias}```" if command.aliases else "No Alt cmd",
inline=False)
embed.add_field(name="**Usage**",
value=f"```{self.context.prefix}{command.signature}```\n")
embed.set_author(name=f"{command.qualified_name.title()} Command")
embed.set_footer(text="<[] = optional | < > = required • Use Prefix Before Commands.")
await self.context.reply(embed=embed, mention_author=False)
def get_command_signature(self, command: commands.Command) -> str:
parent = command.full_parent_name
if len(command.aliases) > 0:
aliases = ' | '.join(command.aliases)
fmt = f'[{command.name} | {aliases}]'
if parent:
fmt = f'{parent}'
alias = f'[{command.name} | {aliases}]'
else:
alias = command.name if not parent else f'{parent} {command.name}'
return f'{alias} {command.signature}'
def common_command_formatting(self, embed_like, command):
embed_like.title = self.get_command_signature(command)
if command.description:
embed_like.description = f'{command.description}\n\n{command.help}'
else:
embed_like.description = command.help or 'No help found...'
async def send_group_help(self, group):
ctx = self.context
check_ignore = await ignore_check().predicate(ctx)
check_blacklist = await blacklist_check().predicate(ctx)
if not check_blacklist:
return
if not check_ignore:
await self.send_ignore_message(ctx, "command")
return
entries = [
(
f"`{self.context.prefix}{cmd.qualified_name}`\n",
f"{cmd.short_doc if cmd.short_doc else ''}\n\u200b"
)
for cmd in group.commands
]
count = len(group.commands)
embeds = FieldPagePaginator(
entries=entries,
title=f"{group.qualified_name.title()} [{count}]",
description="< > Duty | [ ] Optional\n",
per_page=4
).get_pages()
paginator = Paginator(ctx, embeds)
await paginator.paginate()
async def send_cog_help(self, cog):
ctx = self.context
check_ignore = await ignore_check().predicate(ctx)
check_blacklist = await blacklist_check().predicate(ctx)
if not check_blacklist:
return
if not check_ignore:
await self.send_ignore_message(ctx, "command")
return
entries = [(
f"> `{self.context.prefix}{cmd.qualified_name}`",
f"-# Description : {cmd.short_doc if cmd.short_doc else ''}"
f"\n\u200b",
) for cmd in cog.get_commands()]
paginator = Paginator(source=FieldPagePaginator(
entries=entries,
title=f"Zyrox's {cog.qualified_name.title()} ({len(cog.get_commands())})",
description="`<..> Required | [..] Optional`\n\n",
color=0xFF0000,
per_page=4),
ctx=self.context)
await paginator.paginate()
class Help(Cog, name="help"):
def __init__(self, client: zyrox):
self._original_help_command = client.help_command
attributes = {
'name': "help",
'aliases': ['h'],
'cooldown': commands.CooldownMapping.from_cooldown(1, 5, commands.BucketType.user),
'help': 'Shows help about bot, a command, or a category'
}
client.help_command = HelpCommand(command_attrs=attributes)
client.help_command.cog = self
async def cog_unload(self):
self.help_command = self._original_help_command

609
bot/cogs/commands/ignore.py Normal file
View File

@@ -0,0 +1,609 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
from __future__ import annotations
import discord
from utils.emoji import CROSS, TICK, ZWARNING
from discord.ui import LayoutView, TextDisplay, Separator, Container
from discord.ext import commands
from core import *
from utils.Tools import *
from typing import Optional
import aiosqlite
color = 0xFF0000
class SuccessView(LayoutView):
def __init__(self, title, description):
super().__init__(timeout=None)
self.add_item(
Container(
TextDisplay(f"**{TICK} {title}**"),
Separator(visible=True),
TextDisplay(description),
)
)
class ErrorView(LayoutView):
def __init__(self, title, description):
super().__init__(timeout=None)
self.add_item(
Container(
TextDisplay(f"**{CROSS} {title}**"),
Separator(visible=True),
TextDisplay(description),
)
)
class WarningView(LayoutView):
def __init__(self, title, description):
super().__init__(timeout=None)
self.add_item(
Container(
TextDisplay(f"**{ZWARNING} {title}**"),
Separator(visible=True),
TextDisplay(description),
)
)
class ListView(LayoutView):
def __init__(self, title, items, empty_message, guild=None):
super().__init__(timeout=None)
if not items:
self.add_item(
Container(
TextDisplay(f"**{title}**"),
Separator(visible=True),
TextDisplay(empty_message),
)
)
else:
if guild:
mentions = []
for item in items:
if isinstance(item, int):
entity = guild.get_channel(item) or guild.get_member(item)
mentions.append(entity.mention if entity else f"ID {item}")
else:
mentions.append(f"`{item}`")
description = "\n".join(mentions)
else:
description = "\n".join([f"`{item}`" for item in items])
self.add_item(
Container(
TextDisplay(f"**{title}**"),
Separator(visible=True),
TextDisplay(description),
)
)
class Ignore(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.db_path = "db/ignore.db"
self.color = 0xFF0000
bot.loop.create_task(self.initialize_db())
async def initialize_db(self):
async with aiosqlite.connect(self.db_path) as db:
await db.execute(
"CREATE TABLE IF NOT EXISTS ignored_commands (guild_id INTEGER, command_name TEXT)"
)
await db.execute(
"CREATE TABLE IF NOT EXISTS ignored_channels (guild_id INTEGER, channel_id INTEGER)"
)
await db.execute(
"CREATE TABLE IF NOT EXISTS ignored_users (guild_id INTEGER, user_id INTEGER)"
)
await db.execute(
"CREATE TABLE IF NOT EXISTS bypassed_users (guild_id INTEGER, user_id INTEGER)"
)
await db.commit()
@commands.group(
name="ignore",
help="Manage ignored commands, channels, users, and bypassed users.",
invoke_without_command=True,
)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def _ignore(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@_ignore.group(
name="command",
help="Manage ignored commands in this guild.",
invoke_without_command=True,
)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def _command(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@_command.command(name="add", help="Adds a command to the ignore list.")
@commands.has_permissions(administrator=True)
@blacklist_check()
async def command_add(self, ctx: commands.Context, command_name: str):
command_name_normalized = command_name.strip().lower()
command = self.bot.get_command(command_name_normalized)
if not command:
await ctx.reply(
view=ErrorView("Error", f"`{command_name}` is not a valid command.")
)
return
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute(
"SELECT COUNT(*) FROM ignored_commands WHERE guild_id = ?",
(ctx.guild.id,),
)
count = await cursor.fetchone()
if count[0] >= 25:
await ctx.reply(
view=WarningView(
"Access Denied",
"You can only add up to 25 commands to the ignore list.",
)
)
return
cursor = await db.execute(
"SELECT command_name FROM ignored_commands WHERE guild_id = ? AND command_name = ?",
(ctx.guild.id, command_name_normalized),
)
result = await cursor.fetchone()
if result:
await ctx.reply(
view=ErrorView(
"Error",
f"`{command_name}` is already in the ignore commands list.",
)
)
else:
await db.execute(
"INSERT INTO ignored_commands (guild_id, command_name) VALUES (?, ?)",
(ctx.guild.id, command_name_normalized),
)
await db.commit()
await ctx.reply(
view=SuccessView(
"Success",
f"Successfully added `{command_name}` to the ignore commands list.",
)
)
@_command.command(name="remove", help="Removes a command from the ignore list.")
@commands.has_permissions(administrator=True)
@blacklist_check()
async def command_remove(self, ctx: commands.Context, command_name: str):
command_name_normalized = command_name.strip().lower()
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute(
"SELECT command_name FROM ignored_commands WHERE guild_id = ? AND command_name = ?",
(ctx.guild.id, command_name_normalized),
)
result = await cursor.fetchone()
if not result:
await ctx.reply(
view=ErrorView(
"Error", f"`{command_name}` is not in the ignore commands list."
)
)
else:
await db.execute(
"DELETE FROM ignored_commands WHERE guild_id = ? AND command_name = ?",
(ctx.guild.id, command_name_normalized),
)
await db.commit()
await ctx.reply(
view=SuccessView(
"Success",
f"Successfully removed `{command_name}` from the ignore commands list.",
)
)
@_command.command(name="show", help="Displays the list of ignored commands.")
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def command_show(self, ctx: commands.Context):
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute(
"SELECT command_name FROM ignored_commands WHERE guild_id = ?",
(ctx.guild.id,),
)
commands = await cursor.fetchall()
if not commands:
await ctx.reply(
view=ListView(
"Ignored Commands",
[],
"No commands are currently ignored in this server.",
)
)
else:
await ctx.reply(
view=ListView("Ignored Commands", [c[0] for c in commands], "")
)
@_ignore.group(
name="channel",
help="Manage ignored channels in this guild.",
invoke_without_command=True,
)
@blacklist_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def _channel(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@_channel.command(name="add", help="Adds a channel to the ignore list.")
@blacklist_check()
@commands.has_permissions(administrator=True)
async def channel_add(self, ctx: commands.Context, channel: discord.TextChannel):
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute(
"SELECT COUNT(*) FROM ignored_channels WHERE guild_id = ?",
(ctx.guild.id,),
)
count = await cursor.fetchone()
if count[0] >= 30:
await ctx.reply(
view=WarningView(
"Access Denied",
"You can only add up to 30 channels to the ignore list.",
)
)
return
cursor = await db.execute(
"SELECT channel_id FROM ignored_channels WHERE guild_id = ? AND channel_id = ?",
(ctx.guild.id, channel.id),
)
result = await cursor.fetchone()
if result:
await ctx.reply(
view=ErrorView(
"Error",
f"{channel.mention} is already in the ignore channels list.",
)
)
else:
await db.execute(
"INSERT INTO ignored_channels (guild_id, channel_id) VALUES (?, ?)",
(ctx.guild.id, channel.id),
)
await db.commit()
await ctx.reply(
view=SuccessView(
"Success",
f"Successfully added {channel.mention} to the ignore channels list.",
)
)
@_channel.command(name="remove", help="Removes a channel from the ignore list.")
@blacklist_check()
@commands.has_permissions(administrator=True)
async def channel_remove(self, ctx: commands.Context, channel: discord.TextChannel):
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute(
"SELECT channel_id FROM ignored_channels WHERE guild_id = ? AND channel_id = ?",
(ctx.guild.id, channel.id),
)
result = await cursor.fetchone()
if not result:
await ctx.reply(
view=ErrorView(
"Error",
f"{channel.mention} is not in the ignore channels list.",
)
)
else:
await db.execute(
"DELETE FROM ignored_channels WHERE guild_id = ? AND channel_id = ?",
(ctx.guild.id, channel.id),
)
await db.commit()
await ctx.reply(
view=SuccessView(
"Success",
f"Successfully removed {channel.mention} from the ignore channels list.",
)
)
@_channel.command(name="show", help="Displays the list of ignored channels.")
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def channel_show(self, ctx: commands.Context):
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute(
"SELECT channel_id FROM ignored_channels WHERE guild_id = ?",
(ctx.guild.id,),
)
channels = await cursor.fetchall()
if not channels:
await ctx.reply(
view=ListView(
"Ignored Channels",
[],
"No channels are currently ignored in this server.",
)
)
else:
await ctx.reply(
view=ListView(
"Ignored Channels", [c[0] for c in channels], "", ctx.guild
)
)
@_ignore.group(
name="user",
help="Manage ignored users in this guild.",
invoke_without_command=True,
)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def _user(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@_user.command(name="add", help="Adds a user to the ignore list.")
@commands.has_permissions(administrator=True)
@blacklist_check()
async def user_add(self, ctx: commands.Context, user: discord.User):
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute(
"SELECT COUNT(*) FROM ignored_users WHERE guild_id = ?", (ctx.guild.id,)
)
count = await cursor.fetchone()
if count[0] >= 30:
await ctx.reply(
view=WarningView(
"Access Denied",
"You can only add up to 30 users to the ignore list.",
)
)
return
cursor = await db.execute(
"SELECT user_id FROM ignored_users WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, user.id),
)
result = await cursor.fetchone()
if result:
await ctx.reply(
view=ErrorView(
"Error", f"{user.mention} is already in the ignore users list."
)
)
else:
await db.execute(
"INSERT INTO ignored_users (guild_id, user_id) VALUES (?, ?)",
(ctx.guild.id, user.id),
)
await db.commit()
await ctx.reply(
view=SuccessView(
"Success",
f"Successfully added {user.mention} to the ignore users list.",
)
)
@_user.command(name="remove", help="Removes a user from the ignore list.")
@blacklist_check()
@commands.has_permissions(administrator=True)
async def user_remove(self, ctx: commands.Context, user: discord.User):
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute(
"SELECT user_id FROM ignored_users WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, user.id),
)
result = await cursor.fetchone()
if not result:
await ctx.reply(
view=ErrorView(
"Error", f"{user.mention} is not in the ignore users list."
)
)
else:
await db.execute(
"DELETE FROM ignored_users WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, user.id),
)
await db.commit()
await ctx.send(
view=SuccessView(
"Success",
f"Successfully removed {user.mention} from the ignore users list.",
)
)
@_user.command(name="show", help="Displays the list of ignored users.")
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def user_show(self, ctx: commands.Context):
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute(
"SELECT user_id FROM ignored_users WHERE guild_id = ?", (ctx.guild.id,)
)
users = await cursor.fetchall()
if not users:
await ctx.reply(
view=ListView(
"Ignored Users",
[],
"No users are currently ignored in this server.",
)
)
else:
await ctx.reply(
view=ListView("Ignored Users", [u[0] for u in users], "", ctx.guild)
)
@_ignore.group(
name="bypass",
help="Manage bypassed users in this guild.",
invoke_without_command=True,
)
@commands.cooldown(1, 5, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
@commands.has_permissions(administrator=True)
async def _bypass(self, ctx):
if ctx.subcommand_passed is None:
await ctx.send_help(ctx.command)
ctx.command.reset_cooldown(ctx)
@_bypass.command(name="add", help="Adds a user to the bypass list.")
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def bypass_add(self, ctx: commands.Context, user: discord.User):
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute(
"SELECT COUNT(*) FROM bypassed_users WHERE guild_id = ?",
(ctx.guild.id,),
)
count = await cursor.fetchone()
if count[0] >= 30:
await ctx.reply(
view=WarningView(
"Access Denied",
"You can only add up to 30 users to the bypass list.",
)
)
return
cursor = await db.execute(
"SELECT user_id FROM bypassed_users WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, user.id),
)
result = await cursor.fetchone()
if result:
await ctx.reply(
view=ErrorView(
"Error", f"{user.mention} is already in the bypass users list."
)
)
else:
await db.execute(
"INSERT INTO bypassed_users (guild_id, user_id) VALUES (?, ?)",
(ctx.guild.id, user.id),
)
await db.commit()
await ctx.reply(
view=SuccessView(
"Success",
f"Successfully added {user.mention} to the bypass users list.",
)
)
@_bypass.command(name="remove", help="Removes a user from the bypass list.")
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def bypass_remove(self, ctx: commands.Context, user: discord.User):
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute(
"SELECT user_id FROM bypassed_users WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, user.id),
)
result = await cursor.fetchone()
if not result:
await ctx.reply(
view=ErrorView(
"Error", f"{user.mention} is not in the bypass users list."
)
)
else:
await db.execute(
"DELETE FROM bypassed_users WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, user.id),
)
await db.commit()
await ctx.reply(
view=SuccessView(
"Success",
f"Successfully removed {user.mention} from the bypass users list.",
)
)
@_bypass.command(
name="show", aliases=["list"], help="Displays the list of bypassed users."
)
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def bypass_show(self, ctx: commands.Context):
async with aiosqlite.connect(self.db_path) as db:
cursor = await db.execute(
"SELECT user_id FROM bypassed_users WHERE guild_id = ?", (ctx.guild.id,)
)
users = await cursor.fetchall()
if not users:
await ctx.reply(
view=ListView(
"Bypassed Users",
[],
"No users are currently bypassed in this server.",
)
)
else:
await ctx.reply(
view=ListView(
"Bypassed Users", [u[0] for u in users], "", ctx.guild
)
)

View File

@@ -0,0 +1,78 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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
from discord.ui import LayoutView, MediaGallery, TextDisplay
import aiohttp
import os
import random
from utils.cv2 import CV2, build_container
PEXELS_API_KEY = "js24mfV1bCCvgV6KfnEFvo5UnCHnATFarFnAdDrpDbczl7f0yXpjDF8x"
class ImageCommands(commands.Cog):
def __init__(self, bot):
self.bot = bot
async def fetch_pexels_image(self, query):
headers = {
"Authorization": PEXELS_API_KEY
}
async with aiohttp.ClientSession() as session:
async with session.get(f"https://api.pexels.com/v1/search?query={query}&per_page=50", headers=headers) as resp:
data = await resp.json()
if data.get("photos"):
image = random.choice(data["photos"])
return image["src"]["original"]
return None
async def fetch_waifu_image(self, category="waifu"):
async with aiohttp.ClientSession() as session:
async with session.get(f"https://api.waifu.pics/sfw/{category}") as resp:
data = await resp.json()
return data["url"]
async def send_image_view(self, ctx, title, url):
if url:
view = LayoutView(timeout=None)
gallery = MediaGallery()
gallery.add_item(media=url)
view.add_item(build_container(TextDisplay(f"**{title}**"), gallery))
await ctx.send(view=view)
else:
await ctx.send(view=CV2("❌ Error", f"No image found for {title.lower()}."))
@commands.command(name="boy")
async def boy_image(self, ctx):
url = await self.fetch_pexels_image("handsome boy")
await self.send_image_view(ctx, "👦 Boy Pic", url)
# @commands.command(name="girl")
# async def girl_image(self, ctx):
# url = await self.fetch_pexels_image("beautiful girl")
# await self.send_image_view(ctx, "👧 Girl Pic", url)
@commands.command(name="couple")
async def couple_image(self, ctx):
url = await self.fetch_pexels_image("romantic couple")
await self.send_image_view(ctx, "💑 Couple Pic", url)
@commands.command(name="anime")
async def anime_image(self, ctx):
url = await self.fetch_waifu_image("waifu")
await self.send_image_view(ctx, "🧚 Anime Waifu", url)
async def setup(bot):
await bot.add_cog(ImageCommands(bot))

View File

@@ -0,0 +1,168 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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
from discord import app_commands
import aiohttp
import asyncio
import random
import time
from utils.ai_utils import poly_image_gen, generate_image_prodia
from prodia.constants import Model
from utils.Tools import *
from utils.cv2 import CV2
blacklisted_words = [
"naked", "nude", "nudes", "teen", "gay", "lesbian", "porn", "xnxx",
"bitch", "loli", "hentai", "explicit", "pornography", "adult", "XXX",
"sex", "erotic", "dick", "vagina", "pussy", "gay", "lick", "creampie", "nsfw",
"hardcore", "ass", "anal", "anus", "boobs", "tits", "cum", "cunnilingus", "squirt", "penis", "lick", "masturbate", "masturbation ", "orgasm", "orgy", "fap", "fapping", "fuck", "fucking", "handjob", "cowgirl", "doggystyle", "blowjob", "boobjob", "boobies", "horny", "nudity"
]
blocked=["minor", "minors", "kid", "kids", "child", "children", "baby", "babies", "toddler", "childporn", "todd", "underage"]
class CooldownManager:
def __init__(self, rate: int, per: float):
self.rate = rate
self.per = per
self.cooldowns = {}
def check_cooldown(self, user_id: int):
now = time.time()
if user_id not in self.cooldowns:
self.cooldowns[user_id] = [now]
return None
self.cooldowns[user_id] = [timestamp for timestamp in self.cooldowns[user_id] if now - timestamp < self.per]
if len(self.cooldowns[user_id]) >= self.rate:
retry_after = self.per - (now - self.cooldowns[user_id][0])
return retry_after
self.cooldowns[user_id].append(now)
return None
cooldown_manager = CooldownManager(rate=1, per=60.0)
async def cooldown_check(interaction: discord.Interaction):
retry_after = cooldown_manager.check_cooldown(interaction.user.id)
if retry_after:
await interaction.response.send_message(f"You are on cooldown. Try again in {retry_after:.2f} seconds.", ephemeral=True)
return False
return True
class AiStuffCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.guild_only()
@app_commands.command(name="imagine", description="Generate an image using AI")
@discord.app_commands.choices(
model=[
discord.app_commands.Choice(name='✨ Elldreth vivid mix (Landscapes, Stylized characters, nsfw)', value='ELLDRETHVIVIDMIX'),
discord.app_commands.Choice(name='💪 Deliberate v2 (Anything you want, nsfw)', value='DELIBERATE'),
discord.app_commands.Choice(name='🔮 Dreamshaper (HOLYSHIT this so good)', value='DREAMSHAPER_6'),
discord.app_commands.Choice(name='🎼 Lyriel', value='LYRIEL_V16'),
discord.app_commands.Choice(name='💥 Anything diffusion (Good for anime)', value='ANYTHING_V4'),
discord.app_commands.Choice(name='🌅 Openjourney (Midjourney alternative)', value='OPENJOURNEY'),
discord.app_commands.Choice(name='🏞️ Realistic (Lifelike pictures)', value='REALISTICVS_V20'),
discord.app_commands.Choice(name='👨‍🎨 Portrait (For headshots I guess)', value='PORTRAIT'),
discord.app_commands.Choice(name='🌟 Rev animated (Illustration, Anime)', value='REV_ANIMATED'),
discord.app_commands.Choice(name='🤖 Analog', value='ANALOG'),
discord.app_commands.Choice(name='🌌 AbyssOrangeMix', value='ABYSSORANGEMIX'),
discord.app_commands.Choice(name='🌌 Dreamlike v1', value='DREAMLIKE_V1'),
discord.app_commands.Choice(name='🌌 Dreamlike v2', value='DREAMLIKE_V2'),
discord.app_commands.Choice(name='🌌 Dreamshaper 5', value='DREAMSHAPER_5'),
discord.app_commands.Choice(name='🌌 MechaMix', value='MECHAMIX'),
discord.app_commands.Choice(name='🌌 MeinaMix', value='MEINAMIX'),
discord.app_commands.Choice(name='🌌 Stable Diffusion v14', value='SD_V14'),
discord.app_commands.Choice(name='🌌 Stable Diffusion v15', value='SD_V15'),
discord.app_commands.Choice(name="🌌 Shonin's Beautiful People", value='SBP'),
discord.app_commands.Choice(name="🌌 TheAlly's Mix II", value='THEALLYSMIX'),
discord.app_commands.Choice(name='🌌 Timeless', value='TIMELESS')
],
sampler=[
discord.app_commands.Choice(name='📏 Euler (Recommended)', value='Euler'),
discord.app_commands.Choice(name='📏 Euler a', value='Euler a'),
discord.app_commands.Choice(name='📐 Heun', value='Heun'),
discord.app_commands.Choice(name='💥 DPM++ 2M Karras', value='DPM++ 2M Karras'),
discord.app_commands.Choice(name='💥 DPM++ SDE Karras', value='DPM++ SDE Karras'),
discord.app_commands.Choice(name='🔍 DDIM', value='DDIM')
]
)
@discord.app_commands.describe(
prompt="Write an amazing prompt for an image",
model="Model to generate image",
sampler="Sampler for denoising",
negative="Prompt that specifies what you do not want the model to generate",
)
async def imagine(self, interaction: discord.Interaction, prompt: str, model: discord.app_commands.Choice[str], sampler: discord.app_commands.Choice[str], negative: str = None, seed: int = None):
retry_after = cooldown_manager.check_cooldown(interaction.user.id)
if retry_after:
await interaction.response.send_message(f"You are on cooldown. Try again in {retry_after:.2f} seconds.", ephemeral=True)
return
await interaction.response.defer()
is_nsfw = any(word in prompt.lower() for word in blacklisted_words)
is_child = any(word in prompt.lower() for word in blocked)
if is_child:
await interaction.followup.send("Child porn is not allowed as it violates Discord ToS. Please try again with a different peompt.")
return
if is_nsfw and not interaction.channel.nsfw:
await interaction.followup.send("You can create NSFW images in NSFW channels only. Please try in an appropriate channel.", ephemeral=True)
return
model_uid = Model[model.value].value[0]
try:
imagefileobj = await generate_image_prodia(prompt, model_uid, sampler.value, seed, negative)
except aiohttp.ClientPayloadError:
await interaction.followup.send("An error occurred while generating the image. Please try again later.", ephemeral=True)
return
except Exception as e:
await interaction.followup.send(f"An unexpected error occurred: {e}", ephemeral=True)
return
if is_nsfw:
img_file = discord.File(imagefileobj, filename="image.png", spoiler=True, description=prompt)
prompt = f"||{prompt}||"
else:
img_file = discord.File(imagefileobj, filename="image.png", description=prompt)
desc = (
f"**Prompt:** {prompt}\n"
f"**Model:** {model.value}\n"
f"**Sampler:** {sampler.value}\n"
f"**Seed:** {seed}"
)
if negative:
desc += f"\n**Negative Prompt:** {negative}"
if is_nsfw:
desc += f"\n**NSFW:** {str(is_nsfw)}"
view = CV2(f"Generated Image by {interaction.user.display_name}", desc)
await interaction.followup.send(view=view, file=img_file, ephemeral=True)
async def setup(bot):
await bot.add_cog(AiStuffCog(bot))

726
bot/cogs/commands/j2c.py Normal file
View File

@@ -0,0 +1,726 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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
from discord import ui, SelectOption
from discord.ui import LayoutView, TextDisplay, Separator, ActionRow
import aiosqlite
import asyncio
from typing import Dict, List, Optional
from utils.cv2 import CV2, build_container
class JoinToCreate(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.private_channels: Dict[int, Dict] = {}
self.category_name = "J2C"
self.setup_data: Dict[int, Dict] = {}
self.db_path = "j2c_data.db"
self.blocked_users: Dict[int, List[int]] = {} # {vc_id: [user_ids]}
self.creating_vc = set()
async def init_db(self):
async with aiosqlite.connect(self.db_path) as db:
await db.execute("""
CREATE TABLE IF NOT EXISTS guild_setup (
guild_id INTEGER PRIMARY KEY,
join_channel_id INTEGER,
control_channel_id INTEGER,
control_message_id INTEGER,
category_id INTEGER
)
""")
try:
await db.execute("ALTER TABLE guild_setup ADD COLUMN category_id INTEGER")
except aiosqlite.OperationalError:
pass
await db.execute("""
CREATE TABLE IF NOT EXISTS private_channels (
vc_id INTEGER PRIMARY KEY,
guild_id INTEGER,
owner_id INTEGER,
member_limit INTEGER DEFAULT 2,
region TEXT DEFAULT '',
is_locked BOOLEAN DEFAULT FALSE,
has_waiting_room BOOLEAN DEFAULT FALSE,
has_thread BOOLEAN DEFAULT FALSE
)
""")
await db.execute("""
CREATE TABLE IF NOT EXISTS blocked_users (
vc_id INTEGER,
user_id INTEGER,
PRIMARY KEY (vc_id, user_id)
)
""")
await db.commit()
async def load_data(self):
async with aiosqlite.connect(self.db_path) as db:
# Load guild setups
async with db.execute("SELECT guild_id, join_channel_id, control_channel_id, control_message_id, category_id FROM guild_setup") as cursor:
async for row in cursor:
guild_id, join_channel_id, control_channel_id, control_message_id, category_id = row
self.setup_data[guild_id] = {
"join_channel_id": join_channel_id,
"control_channel_id": control_channel_id,
"control_message_id": control_message_id,
"category_id": category_id
}
# Load private channels
async with db.execute("SELECT * FROM private_channels") as cursor:
async for row in cursor:
vc_id, guild_id, owner_id, member_limit, region, is_locked, has_waiting_room, has_thread = row
self.private_channels[vc_id] = {
"owner": owner_id,
"limit": member_limit,
"region": region,
"is_locked": bool(is_locked),
"has_waiting_room": bool(has_waiting_room),
"has_thread": bool(has_thread),
"guild_id": guild_id
}
# Load blocked users
async with db.execute("SELECT * FROM blocked_users") as cursor:
async for row in cursor:
vc_id, user_id = row
if vc_id not in self.blocked_users:
self.blocked_users[vc_id] = []
self.blocked_users[vc_id].append(user_id)
async def save_guild_setup(self, guild_id: int, data: Dict):
async with aiosqlite.connect(self.db_path) as db:
await db.execute("""
INSERT OR REPLACE INTO guild_setup (guild_id, join_channel_id, control_channel_id, control_message_id, category_id)
VALUES (?, ?, ?, ?, ?)
""", (guild_id, data["join_channel_id"], data["control_channel_id"], data["control_message_id"], data.get("category_id")))
await db.commit()
async def save_private_channel(self, vc_id: int, guild_id: int, data: Dict):
try:
if vc_id not in self.private_channels:
self.private_channels[vc_id] = data
async with aiosqlite.connect(self.db_path) as db:
await db.execute("""
INSERT OR REPLACE INTO private_channels
(vc_id, guild_id, owner_id, member_limit, region, is_locked, has_waiting_room, has_thread)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""", (
vc_id, guild_id,
data["owner"],
data.get("limit", 2),
data.get("region", ""),
data.get("is_locked", False),
data.get("has_waiting_room", False),
data.get("has_thread", False)
))
await db.commit()
except Exception as e:
print(f"Error saving private channel: {e}")
async def delete_private_channel(self, vc_id: int):
async with aiosqlite.connect(self.db_path) as db:
await db.execute("DELETE FROM private_channels WHERE vc_id = ?", (vc_id,))
await db.execute("DELETE FROM blocked_users WHERE vc_id = ?", (vc_id,))
await db.commit()
async def delete_guild_setup(self, guild_id: int):
async with aiosqlite.connect(self.db_path) as db:
await db.execute("DELETE FROM guild_setup WHERE guild_id = ?", (guild_id,))
await db.execute("DELETE FROM private_channels WHERE guild_id = ?", (guild_id,))
await db.execute("DELETE FROM blocked_users WHERE vc_id IN (SELECT vc_id FROM private_channels WHERE guild_id = ?)", (guild_id,))
await db.commit()
async def block_user(self, vc_id: int, user_id: int):
async with aiosqlite.connect(self.db_path) as db:
await db.execute("INSERT OR IGNORE INTO blocked_users (vc_id, user_id) VALUES (?, ?)", (vc_id, user_id))
await db.commit()
if vc_id not in self.blocked_users:
self.blocked_users[vc_id] = []
if user_id not in self.blocked_users[vc_id]:
self.blocked_users[vc_id].append(user_id)
async def unblock_user(self, vc_id: int, user_id: int):
async with aiosqlite.connect(self.db_path) as db:
await db.execute("DELETE FROM blocked_users WHERE vc_id = ? AND user_id = ?", (vc_id, user_id))
await db.commit()
if vc_id in self.blocked_users and user_id in self.blocked_users[vc_id]:
self.blocked_users[vc_id].remove(user_id)
@commands.Cog.listener()
async def on_ready(self):
await self.init_db()
await self.load_data()
for guild_id, data in self.setup_data.items():
guild = self.bot.get_guild(guild_id)
if guild:
try:
control_channel = guild.get_channel(data["control_channel_id"])
if control_channel:
msg = None
if data["control_message_id"]:
try:
msg = await control_channel.fetch_message(data["control_message_id"])
except:
pass
if msg:
view = ControlPanelView(self, guild)
await msg.edit(view=view, embed=None, content=None)
else:
view = ControlPanelView(self, guild)
msg = await control_channel.send(view=view)
self.setup_data[guild_id]["control_message_id"] = msg.id
await self.save_guild_setup(guild_id, self.setup_data[guild_id])
except Exception as e:
print(f"Error in J2C on_ready: {e}")
continue
@commands.command(name='j2csetup')
@commands.has_permissions(administrator=True)
async def setup_private_channels(self, ctx):
if ctx.guild.id in self.setup_data:
await ctx.send(view=CV2("❌ Error", "J2C system is already setup in this server!"))
return
category = discord.utils.get(ctx.guild.categories, name=self.category_name)
if not category:
category = await ctx.guild.create_category(self.category_name)
join_channel = await ctx.guild.create_voice_channel(
" Join to Create",
category=category,
reason="J2C System Setup"
)
control_channel = await ctx.guild.create_text_channel(
"ctrl-panel",
category=category,
reason="J2C System Setup"
)
view = ControlPanelView(self, ctx.guild)
control_message = await control_channel.send(view=view)
self.setup_data[ctx.guild.id] = {
"join_channel_id": join_channel.id,
"control_channel_id": control_channel.id,
"control_message_id": control_message.id
}
await self.save_guild_setup(ctx.guild.id, self.setup_data[ctx.guild.id])
await ctx.send(view=CV2("✅ Success", f"J2C system setup complete! Join {join_channel.mention} to create a private VC."))
@commands.command(name='j2creset')
@commands.has_permissions(administrator=True)
async def reset_private_channels(self, ctx):
if ctx.guild.id not in self.setup_data:
await ctx.send(view=CV2("❌ Error", "J2C system is not setup in this server!"))
return
category = discord.utils.get(ctx.guild.categories, name=self.category_name)
if category:
for channel in category.channels:
try:
await channel.delete(reason="J2C System Reset")
except:
continue
if category:
try:
await category.delete(reason="J2C System Reset")
except:
pass
vc_ids = [vc_id for vc_id, data in self.private_channels.items()
if data.get("guild_id") == ctx.guild.id]
for vc_id in vc_ids:
del self.private_channels[vc_id]
del self.setup_data[ctx.guild.id]
await self.delete_guild_setup(ctx.guild.id)
await ctx.send(view=CV2("✅ Success", "J2C system has been completely reset in this server!"))
@commands.Cog.listener()
async def on_voice_state_update(self, member, before, after):
if member.guild.id not in self.setup_data:
return
guild_data = self.setup_data[member.guild.id]
# User joined the join channel
if after.channel and after.channel.id == guild_data["join_channel_id"]:
if member.id in self.creating_vc:
return
self.creating_vc.add(member.id)
try:
category_id = guild_data.get("category_id")
category = None
if category_id:
try:
category = member.guild.get_channel(int(category_id))
except:
pass
# Fallback 1: Use the parent category of the join channel
if not category and after.channel.category:
category = after.channel.category
# Fallback 2: J2C category by name
if not category:
category = discord.utils.get(member.guild.categories, name=self.category_name)
vc = await member.guild.create_voice_channel(
f"{member.name}'s VC",
category=category,
reason="Private VC Creation",
user_limit=2
)
await member.move_to(vc)
self.private_channels[vc.id] = {
"owner": member.id,
"limit": 2,
"region": "",
"is_locked": False,
"has_waiting_room": False,
"has_thread": False,
"guild_id": member.guild.id
}
await self.save_private_channel(vc.id, member.guild.id, self.private_channels[vc.id])
await self.update_control_panel(member.guild)
finally:
self.creating_vc.discard(member.id)
# User left a private channel
if before.channel and before.channel.id in self.private_channels:
# Check if user was blocked
if (before.channel.id in self.blocked_users and
member.id in self.blocked_users[before.channel.id]):
await member.move_to(None)
return
# Check if channel is empty
if len(before.channel.members) == 0:
try:
await before.channel.delete()
except:
pass
if before.channel.id in self.private_channels:
del self.private_channels[before.channel.id]
await self.delete_private_channel(before.channel.id)
await self.update_control_panel(member.guild)
async def update_control_panel(self, guild: discord.Guild):
if guild.id not in self.setup_data:
return
guild_data = self.setup_data[guild.id]
control_channel = guild.get_channel(guild_data["control_channel_id"])
if not control_channel or not guild_data["control_message_id"]:
return
try:
control_message = await control_channel.fetch_message(guild_data["control_message_id"])
view = ControlPanelView(self, guild)
await control_message.edit(view=view, embed=None, content=None)
except:
pass
class ControlPanelView(LayoutView):
def __init__(self, cog, guild):
super().__init__(timeout=None)
self.cog = cog
desc = ("Join the 'Join to Create VC' voice channel to create your own private voice channel.\n\n"
"Use the buttons below to manage your private VC.")
active_vcs = []
for vc_id, data in self.cog.private_channels.items():
if guild.get_channel(vc_id):
owner = guild.get_member(data["owner"])
if owner:
status = []
if data["is_locked"]:
status.append("🔒 Locked")
if data["has_thread"]:
status.append("💬 Thread")
vc_info = f"<#{vc_id}> (👑 {owner.mention})"
if status:
vc_info += f" [{' '.join(status)}]"
active_vcs.append(vc_info)
if active_vcs:
desc += "\n\n**Active Private VCs**\n" + "\n".join(active_vcs)
container = build_container(
TextDisplay("**J2C System**"),
Separator(visible=True),
TextDisplay(desc)
)
self.add_item(container)
b_limit = ui.Button(label="LIMIT", style=discord.ButtonStyle.blurple, custom_id="j2c:limit", emoji="")
b_limit.callback = self.set_limit
b_privacy = ui.Button(label="PRIVACY", style=discord.ButtonStyle.blurple, custom_id="j2c:privacy", emoji="🔒")
b_privacy.callback = self.toggle_privacy
b_thread = ui.Button(label="THREAD", style=discord.ButtonStyle.blurple, custom_id="j2c:thread", emoji="💬")
b_thread.callback = self.create_thread
b_untrust = ui.Button(label="UNTRUST", style=discord.ButtonStyle.green, custom_id="j2c:untrust", emoji="")
b_untrust.callback = self.untrust
b_invite = ui.Button(label="INVITE", style=discord.ButtonStyle.green, custom_id="j2c:invite", emoji="✉️")
b_invite.callback = self.invite_user
b_kick = ui.Button(label="KICK", style=discord.ButtonStyle.green, custom_id="j2c:kick", emoji="👢")
b_kick.callback = self.kick_user
b_region = ui.Button(label="REGION", style=discord.ButtonStyle.green, custom_id="j2c:region", emoji="🌍")
b_region.callback = self.set_region
b_unblock = ui.Button(label="UNBLOCK", style=discord.ButtonStyle.red, custom_id="j2c:unblock", emoji="🔓")
b_unblock.callback = self.unblock
b_claim = ui.Button(label="CLAIM", style=discord.ButtonStyle.red, custom_id="j2c:claim", emoji="")
b_claim.callback = self.claim
b_transfer = ui.Button(label="TRANSFER", style=discord.ButtonStyle.red, custom_id="j2c:transfer", emoji="🔄")
b_transfer.callback = self.transfer
b_delete = ui.Button(label="DELETE", style=discord.ButtonStyle.red, custom_id="j2c:delete", emoji="🗑️")
b_delete.callback = self.delete_vc
b_block = ui.Button(label="BLOCK", style=discord.ButtonStyle.danger, custom_id="j2c:block", emoji="🚫")
b_block.callback = self.block
self.add_item(ActionRow(b_limit, b_privacy, b_thread))
self.add_item(ActionRow(b_untrust, b_invite, b_kick, b_region))
self.add_item(ActionRow(b_unblock, b_claim, b_transfer, b_delete))
self.add_item(ActionRow(b_block))
async def get_owned_vc(self, interaction: discord.Interaction) -> Optional[discord.VoiceChannel]:
for vc_id, data in self.cog.private_channels.items():
if data["owner"] == interaction.user.id:
vc = interaction.guild.get_channel(vc_id)
if vc:
return vc
return None
async def set_limit(self, interaction: discord.Interaction):
vc = await self.get_owned_vc(interaction)
if not vc:
await interaction.response.send_message("You don't own any private VC!", ephemeral=True)
return
modal = SetLimitModal(vc)
await interaction.response.send_modal(modal)
async def toggle_privacy(self, interaction: discord.Interaction):
await interaction.response.defer(ephemeral=True)
vc = await self.get_owned_vc(interaction)
if not vc:
await interaction.followup.send("You don't own any private VC!", ephemeral=True)
return
is_locked = not self.cog.private_channels[vc.id]["is_locked"]
await vc.set_permissions(interaction.guild.default_role, connect=not is_locked)
self.cog.private_channels[vc.id]["is_locked"] = is_locked
await self.cog.save_private_channel(vc.id, interaction.guild.id, self.cog.private_channels[vc.id])
await interaction.followup.send(f"VC is now {'🔒 locked' if is_locked else '🔓 unlocked'}!", ephemeral=True)
await self.cog.update_control_panel(interaction.guild)
async def create_thread(self, interaction: discord.Interaction):
await interaction.response.defer(ephemeral=True)
vc = await self.get_owned_vc(interaction)
if not vc:
await interaction.followup.send("You don't own any private VC!", ephemeral=True)
return
has_thread = not self.cog.private_channels[vc.id]["has_thread"]
self.cog.private_channels[vc.id]["has_thread"] = has_thread
await self.cog.save_private_channel(vc.id, interaction.guild.id, self.cog.private_channels[vc.id])
if has_thread:
thread = await interaction.channel.create_thread(name=f"{vc.name} Discussion", auto_archive_duration=60)
await interaction.followup.send(f"Created thread: {thread.mention}", ephemeral=True)
else:
await interaction.followup.send("Thread feature disabled for your VC", ephemeral=True)
await self.cog.update_control_panel(interaction.guild)
async def untrust(self, interaction: discord.Interaction):
await interaction.response.defer(ephemeral=True)
vc = await self.get_owned_vc(interaction)
if not vc:
await interaction.followup.send("You don't own any private VC!", ephemeral=True)
return
await interaction.followup.send("Untrust feature would be implemented here", ephemeral=True)
async def invite_user(self, interaction: discord.Interaction):
vc = await self.get_owned_vc(interaction)
if not vc:
await interaction.response.send_message("You don't own any private VC!", ephemeral=True)
return
options = []
for member in interaction.guild.members:
if (member not in vc.members and not member.bot and member != interaction.user):
options.append(SelectOption(label=member.name, value=str(member.id)))
if not options:
await interaction.response.send_message("No members available to invite!", ephemeral=True)
return
dropdown = UserSelectDropdown(options, "Select members to invite", self.invite_selected)
view = ui.View()
view.add_item(dropdown)
await interaction.response.send_message("Select members to invite:", view=view, ephemeral=True)
async def invite_selected(self, interaction: discord.Interaction, selected: List[str]):
await interaction.response.defer(ephemeral=True)
vc = await self.get_owned_vc(interaction)
if not vc: return
for user_id in selected:
member = interaction.guild.get_member(int(user_id))
if member:
try: await member.send(f"You've been invited to join {vc.mention} by {interaction.user.mention}!")
except: pass
await interaction.followup.send("Invites sent!", ephemeral=True)
async def kick_user(self, interaction: discord.Interaction):
vc = await self.get_owned_vc(interaction)
if not vc:
await interaction.response.send_message("You don't own any private VC!", ephemeral=True)
return
options = []
for member in vc.members:
if member.id != interaction.user.id:
options.append(SelectOption(label=member.name, value=str(member.id)))
if not options:
await interaction.response.send_message("No users to kick in your VC!", ephemeral=True)
return
dropdown = UserSelectDropdown(options, "Select members to kick", self.kick_selected)
view = ui.View()
view.add_item(dropdown)
await interaction.response.send_message("Select members to kick:", view=view, ephemeral=True)
async def kick_selected(self, interaction: discord.Interaction, selected: List[str]):
await interaction.response.defer(ephemeral=True)
vc = await self.get_owned_vc(interaction)
if not vc: return
for user_id in selected:
member = interaction.guild.get_member(int(user_id))
if member and member in vc.members:
try: await member.move_to(None)
except: pass
await interaction.followup.send("Selected members kicked!", ephemeral=True)
async def set_region(self, interaction: discord.Interaction):
vc = await self.get_owned_vc(interaction)
if not vc:
await interaction.response.send_message("You don't own any private VC!", ephemeral=True)
return
regions = [
SelectOption(label="Automatic", value="auto"), SelectOption(label="US West", value="us-west"),
SelectOption(label="US East", value="us-east"), SelectOption(label="Europe", value="europe"),
SelectOption(label="Singapore", value="singapore"), SelectOption(label="Japan", value="japan"),
SelectOption(label="Brazil", value="brazil"), SelectOption(label="Australia", value="australia")
]
dropdown = RegionSelectDropdown(regions, vc)
view = ui.View()
view.add_item(dropdown)
await interaction.response.send_message("Select a region:", view=view, ephemeral=True)
async def unblock(self, interaction: discord.Interaction):
vc = await self.get_owned_vc(interaction)
if not vc:
await interaction.response.send_message("You don't own any private VC!", ephemeral=True)
return
if vc.id not in self.cog.blocked_users or not self.cog.blocked_users[vc.id]:
await interaction.response.send_message("No blocked users!", ephemeral=True)
return
options = []
for user_id in self.cog.blocked_users[vc.id]:
member = interaction.guild.get_member(user_id)
if member:
options.append(SelectOption(label=member.name, value=str(user_id)))
dropdown = UserSelectDropdown(options, "Select users to unblock", self.unblock_selected)
view = ui.View()
view.add_item(dropdown)
await interaction.response.send_message("Select users to unblock:", view=view, ephemeral=True)
async def unblock_selected(self, interaction: discord.Interaction, selected: List[str]):
await interaction.response.defer(ephemeral=True)
vc = await self.get_owned_vc(interaction)
if not vc: return
for user_id in selected:
await self.cog.unblock_user(vc.id, int(user_id))
await interaction.followup.send("Selected users unblocked!", ephemeral=True)
await self.cog.update_control_panel(interaction.guild)
async def claim(self, interaction: discord.Interaction):
available_vcs = []
for vc_id, data in self.cog.private_channels.items():
if data["guild_id"] == interaction.guild.id:
vc = interaction.guild.get_channel(vc_id)
if vc:
owner = interaction.guild.get_member(data["owner"])
if not owner or owner not in vc.members:
available_vcs.append((vc, data))
if not available_vcs:
await interaction.response.send_message("No VCs available to claim!", ephemeral=True)
return
options = []
for vc, data in available_vcs:
owner_mention = f"<{data['owner']}>" if data['owner'] else "Unknown"
options.append(SelectOption(label=f"{vc.name} (prev: {owner_mention})", value=str(vc.id)))
dropdown = VCSelectDropdown(options, "Select VC to claim", self.claim_selected)
view = ui.View()
view.add_item(dropdown)
await interaction.response.send_message("Select VC to claim:", view=view, ephemeral=True)
async def claim_selected(self, interaction: discord.Interaction, selected: List[str]):
await interaction.response.defer(ephemeral=True)
vc_id = int(selected[0])
vc = interaction.guild.get_channel(vc_id)
if not vc:
await interaction.followup.send("VC no longer exists!", ephemeral=True)
return
self.cog.private_channels[vc.id]["owner"] = interaction.user.id
await self.cog.save_private_channel(vc.id, interaction.guild.id, self.cog.private_channels[vc.id])
await interaction.followup.send(f"You've claimed {vc.mention}!", ephemeral=True)
await self.cog.update_control_panel(interaction.guild)
async def transfer(self, interaction: discord.Interaction):
vc = await self.get_owned_vc(interaction)
if not vc:
await interaction.response.send_message("You don't own any private VC!", ephemeral=True)
return
options = []
for member in vc.members:
if member.id != interaction.user.id:
options.append(SelectOption(label=member.name, value=str(member.id)))
if not options:
await interaction.response.send_message("No users to transfer to in your VC!", ephemeral=True)
return
dropdown = UserSelectDropdown(options, "Select new owner", self.transfer_selected)
view = ui.View()
view.add_item(dropdown)
await interaction.response.send_message("Select new owner:", view=view, ephemeral=True)
async def transfer_selected(self, interaction: discord.Interaction, selected: List[str]):
await interaction.response.defer(ephemeral=True)
vc = await self.get_owned_vc(interaction)
if not vc: return
new_owner_id = int(selected[0])
new_owner = interaction.guild.get_member(new_owner_id)
if not new_owner:
await interaction.followup.send("User not found!", ephemeral=True)
return
self.cog.private_channels[vc.id]["owner"] = new_owner_id
await self.cog.save_private_channel(vc.id, interaction.guild.id, self.cog.private_channels[vc.id])
await interaction.followup.send(f"Transferred ownership of {vc.mention} to {new_owner.mention}!", ephemeral=True)
await self.cog.update_control_panel(interaction.guild)
async def delete_vc(self, interaction: discord.Interaction):
await interaction.response.defer(ephemeral=True)
vc = await self.get_owned_vc(interaction)
if not vc:
await interaction.followup.send("You don't own any private VC!", ephemeral=True)
return
for member in vc.members:
try: await member.move_to(None)
except: pass
await vc.delete()
if vc.id in self.cog.private_channels:
del self.cog.private_channels[vc.id]
await self.cog.delete_private_channel(vc.id)
await interaction.followup.send("Your private VC has been deleted!", ephemeral=True)
await self.cog.update_control_panel(interaction.guild)
async def block(self, interaction: discord.Interaction):
vc = await self.get_owned_vc(interaction)
if not vc:
await interaction.response.send_message("You don't own any private VC!", ephemeral=True)
return
options = []
for member in interaction.guild.members:
if (member not in vc.members and not member.bot and member != interaction.user):
options.append(SelectOption(label=member.name, value=str(member.id)))
if not options:
await interaction.response.send_message("No members available to block!", ephemeral=True)
return
dropdown = UserSelectDropdown(options, "Select members to block", self.block_selected)
view = ui.View()
view.add_item(dropdown)
await interaction.response.send_message("Select members to block:", view=view, ephemeral=True)
async def block_selected(self, interaction: discord.Interaction, selected: List[str]):
await interaction.response.defer(ephemeral=True)
vc = await self.get_owned_vc(interaction)
if not vc: return
for user_id in selected:
await self.cog.block_user(vc.id, int(user_id))
await interaction.followup.send("Selected members blocked from joining!", ephemeral=True)
await self.cog.update_control_panel(interaction.guild)
class UserSelectDropdown(ui.Select):
def __init__(self, options: List[SelectOption], placeholder: str, callback):
super().__init__(placeholder=placeholder, options=options, min_values=1, max_values=len(options))
self.callback_func = callback
async def callback(self, interaction: discord.Interaction):
await self.callback_func(interaction, self.values)
class RegionSelectDropdown(ui.Select):
def __init__(self, options: List[SelectOption], vc: discord.VoiceChannel):
super().__init__(placeholder="Select a region", options=options)
self.vc = vc
async def callback(self, interaction: discord.Interaction):
region = self.values[0]
try:
await self.vc.edit(rtc_region=region if region != "auto" else None)
await interaction.response.send_message(f"Region set to {self.values[0]}!", ephemeral=True)
except Exception as e:
await interaction.response.send_message(f"Failed to set region: {e}", ephemeral=True)
class VCSelectDropdown(ui.Select):
def __init__(self, options: List[SelectOption], placeholder: str, callback):
super().__init__(placeholder=placeholder, options=options, min_values=1, max_values=1)
self.callback_func = callback
async def callback(self, interaction: discord.Interaction):
await self.callback_func(interaction, self.values)
class SetLimitModal(ui.Modal, title="Set VC User Limit"):
def __init__(self, vc: discord.VoiceChannel):
super().__init__()
self.vc = vc
self.limit = ui.TextInput(
label="User Limit (0 for no limit)",
placeholder="Enter a number between 0 and 99",
default=str(vc.user_limit) if vc.user_limit else "0",
max_length=2
)
self.add_item(self.limit)
async def on_submit(self, interaction: discord.Interaction):
try:
limit = int(self.limit.value)
if limit < 0 or limit > 99:
raise ValueError
await self.vc.edit(user_limit=limit if limit != 0 else None)
cog = interaction.client.get_cog("JoinToCreate")
if cog and self.vc.id in cog.private_channels:
cog.private_channels[self.vc.id]["limit"] = limit
await cog.save_private_channel(self.vc.id, interaction.guild.id, cog.private_channels[self.vc.id])
await interaction.response.send_message(f"User limit set to {limit if limit != 0 else 'no limit'}!", ephemeral=True)
await cog.update_control_panel(interaction.guild)
except:
await interaction.response.send_message("Invalid limit! Please enter a number between 0 and 99.", ephemeral=True)
async def setup(bot):
await bot.add_cog(JoinToCreate(bot))

215
bot/cogs/commands/jail.py Normal file
View File

@@ -0,0 +1,215 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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, tasks
import sqlite3
from datetime import datetime, timedelta
import re
from utils.cv2 import CV2
DB_FILE = "db/jail.db"
class Jail(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.conn = sqlite3.connect(DB_FILE)
self.conn.execute("""
CREATE TABLE IF NOT EXISTS jailed (
guild_id TEXT,
user_id TEXT,
mod_id TEXT,
reason TEXT,
jailed_at TEXT,
duration INTEGER,
roles TEXT,
PRIMARY KEY (guild_id, user_id)
);
""")
self.conn.execute("""
CREATE TABLE IF NOT EXISTS jail_settings (
guild_id TEXT PRIMARY KEY,
jail_role TEXT,
jail_channel TEXT,
mod_role TEXT,
log_channel TEXT
);
""")
# Ensure roles column exists (safe migration)
try:
self.conn.execute("SELECT roles FROM jailed LIMIT 1;")
except sqlite3.OperationalError:
self.conn.execute("ALTER TABLE jailed ADD COLUMN roles TEXT;")
self.conn.commit()
self.jail_check_loop.start()
def cog_unload(self):
self.jail_check_loop.cancel()
self.conn.close()
def get_setting(self, guild_id, field):
cursor = self.conn.execute(f"SELECT {field} FROM jail_settings WHERE guild_id = ?", (str(guild_id),))
row = cursor.fetchone()
return row[0] if row else None
def set_setting(self, guild_id, field, value):
self.conn.execute(f"""
INSERT INTO jail_settings (guild_id, {field})
VALUES (?, ?)
ON CONFLICT(guild_id) DO UPDATE SET {field} = excluded.{field}
""", (str(guild_id), str(value)))
self.conn.commit()
def parse_duration(self, duration_str: str):
pattern = re.compile(r'((?P<hours>\d+)h)?((?P<minutes>\d+)m)?')
match = pattern.fullmatch(duration_str.lower())
if not match:
return None
hours = int(match.group('hours') or 0)
minutes = int(match.group('minutes') or 0)
return (hours * 60 + minutes) * 60 if (hours or minutes) else None
@tasks.loop(minutes=1)
async def jail_check_loop(self):
now = datetime.utcnow()
cursor = self.conn.execute("SELECT guild_id, user_id, duration, jailed_at, roles FROM jailed")
for guild_id, user_id, duration, jailed_at, roles in cursor.fetchall():
if not duration:
continue
jailed_time = datetime.fromisoformat(jailed_at)
if (now - jailed_time).total_seconds() >= duration:
guild = self.bot.get_guild(int(guild_id))
if guild:
member = guild.get_member(int(user_id))
if member:
await self.unjail_member(guild, member)
async def unjail_member(self, guild, member):
jail_role_id = self.get_setting(guild.id, "jail_role")
if jail_role_id:
jail_role = guild.get_role(int(jail_role_id))
if jail_role in member.roles:
await member.remove_roles(jail_role, reason="Unjailed")
# Restore old roles
cursor = self.conn.execute("SELECT roles FROM jailed WHERE guild_id = ? AND user_id = ?", (str(guild.id), str(member.id)))
row = cursor.fetchone()
if row and row[0]:
role_ids = map(int, row[0].split(","))
roles = [guild.get_role(rid) for rid in role_ids if guild.get_role(rid)]
await member.add_roles(*roles, reason="Restored previous roles after jail")
self.conn.execute("DELETE FROM jailed WHERE guild_id = ? AND user_id = ?", (str(guild.id), str(member.id)))
self.conn.commit()
try:
await member.send(f"🔓 You have been unjailed in **{guild.name}**.")
except:
pass
log_channel_id = self.get_setting(guild.id, "log_channel")
if log_channel_id:
log_channel = guild.get_channel(int(log_channel_id))
if log_channel:
desc = (
f"**User:** {member.mention}\n"
f"**Time:** <t:{int(datetime.utcnow().timestamp())}:f>"
)
await log_channel.send(view=CV2("🔓 Member Unjailed", desc))
@commands.command(name="jail")
@commands.has_permissions(manage_roles=True)
async def jail(self, ctx, member: discord.Member, duration: str = None, *, reason="No reason provided"):
jail_role_id = self.get_setting(ctx.guild.id, "jail_role")
jail_channel_id = self.get_setting(ctx.guild.id, "jail_channel")
log_channel_id = self.get_setting(ctx.guild.id, "log_channel")
if not jail_role_id or not jail_channel_id:
return await ctx.send(view=CV2("⚠️ Configuration Error", "Jail system not fully configured."))
jail_role = ctx.guild.get_role(int(jail_role_id))
if not jail_role:
return await ctx.send(view=CV2("⚠️ Configuration Error", "Jail role does not exist."))
duration_secs = self.parse_duration(duration) if duration else None
jailed_at = datetime.utcnow().isoformat()
roles_str = ",".join(str(r.id) for r in member.roles if r != ctx.guild.default_role)
self.conn.execute("DELETE FROM jailed WHERE guild_id = ? AND user_id = ?", (str(ctx.guild.id), str(member.id)))
self.conn.execute("""
INSERT INTO jailed (guild_id, user_id, mod_id, reason, jailed_at, duration, roles)
VALUES (?, ?, ?, ?, ?, ?, ?)
""", (str(ctx.guild.id), str(member.id), str(ctx.author.id), reason, jailed_at, duration_secs, roles_str))
self.conn.commit()
try:
await member.edit(roles=[jail_role], reason="Jailed")
except discord.Forbidden:
return await ctx.send(view=CV2("❌ Permission Error", "I don't have permission to change roles."))
jail_channel = ctx.guild.get_channel(int(jail_channel_id))
if jail_channel:
await jail_channel.set_permissions(member, view_channel=True, send_messages=True, read_message_history=True)
try:
await member.send(f"🔒 You were jailed in **{ctx.guild.name}**.\n📝 Reason: {reason}\n⏰ Duration: {duration or 'Permanent'}")
except:
pass
await ctx.send(view=CV2("✅ Success", f"🔒 {member.mention} has been jailed {'for ' + duration if duration else 'permanently'}."))
if log_channel_id:
log_channel = ctx.guild.get_channel(int(log_channel_id))
if log_channel:
desc = (
f"**User:** {member.mention}\n"
f"**Moderator:** {ctx.author.mention}\n"
f"**Reason:** {reason}\n"
f"**Duration:** {duration or 'Permanent'}\n"
f"**Time:** <t:{int(datetime.utcnow().timestamp())}:f>"
)
await log_channel.send(view=CV2("🔒 Member Jailed", desc))
@commands.command(name="unjail")
@commands.has_permissions(manage_roles=True)
async def unjail(self, ctx, member: discord.Member):
await self.unjail_member(ctx.guild, member)
await ctx.send(view=CV2("✅ Success", f"{member.mention} has been unjailed."))
@commands.command(name="jailhistory")
async def jailhistory(self, ctx, member: discord.Member):
cursor = self.conn.execute("""
SELECT reason, jailed_at, duration, mod_id FROM jailed
WHERE guild_id = ? AND user_id = ?
""", (str(ctx.guild.id), str(member.id)))
row = cursor.fetchone()
if row:
reason, jailed_at, duration, mod_id = row
mod = ctx.guild.get_member(int(mod_id))
jailed_time = datetime.fromisoformat(jailed_at)
desc = (
f"**User:** {member.mention}\n"
f"**Reason:** {reason}\n"
f"**Jailed At:** <t:{int(jailed_time.timestamp())}:f>\n"
f"**Duration:** {f'{duration // 60} minutes' if duration else 'Permanent'}\n"
f"**Jailed By:** {mod.mention if mod else 'Unknown'}"
)
await ctx.send(view=CV2("📄 Jail Record", desc))
else:
await ctx.send(view=CV2("❌ Error", f"No jail record found for {member.mention}"))
async def setup(bot):
await bot.add_cog(Jail(bot))

100
bot/cogs/commands/joindm.py Normal file
View File

@@ -0,0 +1,100 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import BLOBPART
from discord.ext import commands
import json
from utils.cv2 import CV2
class joindm(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.joindm_messages = {}
self.load_joindm_messages()
def load_joindm_messages(self):
# Load the join DM messages from file
try:
with open('jsondb/joindm_messages.json', 'r') as f:
self.joindm_messages = json.load(f)
except FileNotFoundError:
self.joindm_messages = {}
def save_joindm_messages(self):
# Save the join DM messages to file
with open('jsondb/joindm_messages.json', 'w') as f:
json.dump(self.joindm_messages, f)
@commands.group(invoke_without_command=True)
@commands.has_permissions(administrator=True)
async def joindm(self, ctx):
# Display the current join DM message
guild_id = str(ctx.guild.id)
if guild_id in self.joindm_messages:
await ctx.send(view=CV2("✅ Join DM Status", f"The current join DM message is:\n`{self.joindm_messages[guild_id]}`"))
else:
await ctx.send(view=CV2("❌ Error", "No custom join DM message has been set for this server."))
@joindm.command()
@commands.has_permissions(administrator=True)
async def message(self, ctx, *, message=None):
# Set the custom join DM message
if message is None:
await ctx.send(view=CV2("❌ Error", "Please provide a custom join DM message."))
else:
self.joindm_messages[str(ctx.guild.id)] = message
self.save_joindm_messages()
await ctx.send(view=CV2("✅ Success", "Custom join DM message set successfully."))
@joindm.command()
@commands.has_permissions(administrator=True)
async def enable(self, ctx):
# Enable the join DM module
self.bot.add_listener(self.on_member_join, 'on_member_join')
await ctx.send(view=CV2("✅ Success", "Join DM module enabled. Custom DM will be sent to new members."))
@joindm.command()
@commands.has_permissions(administrator=True)
async def disable(self, ctx):
# Disable the join DM module
self.bot.remove_listener(self.on_member_join)
await ctx.send(view=CV2("✅ Success", "Join DM module disabled. Custom DM will not be sent to new members."))
@joindm.command()
async def test(self, ctx):
# Send a test join DM to the author of the command
guild_id = str(ctx.guild.id)
if guild_id in self.joindm_messages:
message = self.joindm_messages[guild_id]
server_name = ctx.guild.name
join_dm_message = f"{message}\n\n ``Sent from {server_name} `` "
await ctx.send(view=CV2("✅ Test Sent", "Test Join DM Sent To Your Dm"))
await ctx.message.add_reaction(BLOBPART)
await ctx.author.send(view=CV2("👋 Welcome", join_dm_message))
else:
await ctx.send(view=CV2("❌ Error", "No custom join DM message has been set for this server."))
async def on_member_join(self, member):
guild_id = str(member.guild.id)
if guild_id in self.joindm_messages:
message = self.joindm_messages[guild_id]
dm_channel = await member.create_dm()
server_name = member.guild.name
join_dm_message = f"{message}\n\n``Sent from {server_name} ``"
await dm_channel.send(view=CV2("👋 Welcome", join_dm_message))
async def setup(bot):
await bot.add_cog(joindm(bot))

File diff suppressed because it is too large Load Diff

Binary file not shown.

2999
bot/cogs/commands/logging.py Normal file

File diff suppressed because it is too large Load Diff

274
bot/cogs/commands/map.py Normal file
View File

@@ -0,0 +1,274 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import DELETE
from discord.ext import commands
from discord import ui, ButtonStyle, SelectOption
from discord.ui import LayoutView, TextDisplay, Separator, ActionRow, MediaGallery
import requests
import asyncio
from utils.Tools import *
from utils.cv2 import CV2, build_container
from utils.config import *
class MapView(LayoutView):
def __init__(self, bot, location, ctx):
super().__init__(timeout=None)
self.bot = bot
self.location = location
self.ctx = ctx
self.zoom_level = 14
self.map_style = 'map'
self.map_size = '1200,900'
self.coordinates = self.get_coordinates(location)
self.latitude, self.longitude = None, None
if self.coordinates != (None, None):
self.latitude, self.longitude = float(self.coordinates[0]), float(self.coordinates[1])
self.update_map()
b_left = ui.Button(label="", emoji="⬅️", style=ButtonStyle.secondary)
b_left.callback = self.move_left
b_up = ui.Button(label="", emoji="⬆️", style=ButtonStyle.secondary)
b_up.callback = self.move_up
b_delete = ui.Button(label="", emoji=DELETE, style=ButtonStyle.danger)
b_delete.callback = self.delete_embed
b_down = ui.Button(label="", emoji="⬇️", style=ButtonStyle.secondary)
b_down.callback = self.move_down
b_right = ui.Button(label="", emoji="➡️", style=ButtonStyle.secondary)
b_right.callback = self.move_right
self.add_item(ActionRow(b_left, b_up, b_delete, b_down, b_right))
b_zin = ui.Button(label="Zoom In", style=ButtonStyle.primary)
b_zin.callback = self.zoom_in
b_zout = ui.Button(label="Zoom Out", style=ButtonStyle.primary)
b_zout.callback = self.zoom_out
b_coords = ui.Button(label="Enter Coordinates", style=ButtonStyle.primary)
b_coords.callback = self.enter_coordinates
b_addr = ui.Button(label="Enter Address", style=ButtonStyle.success)
b_addr.callback = self.enter_address
self.add_item(ActionRow(b_zin, b_zout, b_coords, b_addr))
self.add_item(ActionRow(MapStyleSelect(self)))
self.add_item(ActionRow(MapSizeSelect(self)))
self.build_ui()
def build_ui(self):
container = build_container(
TextDisplay(f"**Map of {self.location}**"),
Separator(visible=True),
TextDisplay(
f"🌐 **[Open in Webpage](https://www.openstreetmap.org/?mlat={self.latitude}&mlon={self.longitude}&zoom={self.zoom_level})**\n"
f"🔍 **Current Zoom Level:** {str(self.zoom_level)}\n"
f"🗺️ **Map Style:** {self.map_style}\n"
f"📏 **Map Size:** {self.map_size}\n"
f"📍 **Current Coordinates:** {self.latitude}, {self.longitude}"
)
)
gallery = MediaGallery()
gallery.add_item(media=self.map_url)
container.add_item(gallery)
self.children = [c for c in self.children if not isinstance(c, type(container))]
self.add_item(container)
def get_coordinates(self, location):
try:
headers = {'User-Agent': f'{BRAND_NAME} Bot (https://codexdevs.in)'}
response = requests.get(f'https://nominatim.openstreetmap.org/search?q={location}&format=json', headers=headers)
response.raise_for_status()
data = response.json()[0]
return data['lat'], data['lon']
except (requests.RequestException, IndexError) as e:
print(f"Failed to get coordinates: {e}")
return None, None
def update_map(self):
if self.latitude is None or self.longitude is None:
return
self.map_url = f'https://www.mapquestapi.com/staticmap/v5/map?key=E2SaL3qiTpXQ43nxZFBp0wzEnBI6pqbG&center={self.latitude},{self.longitude}&zoom={self.zoom_level}&size={self.map_size}&type={self.map_style}'
self.build_ui()
async def update_embed(self, interaction: discord.Interaction):
if self.latitude is None or self.longitude is None:
await interaction.response.send_message("Failed to retrieve map data. Please try again.", ephemeral=True)
return
try:
await interaction.message.edit(view=self)
except Exception as e:
await interaction.response.send_message(f"Error updating message: {e}", ephemeral=True)
async def interaction_check(self, interaction: discord.Interaction) -> bool:
if interaction.user != self.ctx.author:
await interaction.response.send_message(
view=CV2("⚠️ Access Denied", "Sorry only the requested author can control this"),
ephemeral=True
)
return False
return True
async def move_left(self, interaction: discord.Interaction):
if self.longitude is not None:
self.longitude -= 0.01
self.update_map()
await self.update_embed(interaction)
await interaction.response.send_message(view=CV2("✅ Map Updated", "Moved left."), ephemeral=True)
async def move_up(self, interaction: discord.Interaction):
if self.latitude is not None:
self.latitude += 0.01
self.update_map()
await self.update_embed(interaction)
await interaction.response.send_message(view=CV2("✅ Map Updated", "Moved up."), ephemeral=True)
async def delete_embed(self, interaction: discord.Interaction):
try:
await interaction.message.delete()
except Exception as e:
await interaction.response.send_message(f"Error deleting message: {e}", ephemeral=True)
async def move_down(self, interaction: discord.Interaction):
if self.latitude is not None:
self.latitude -= 0.01
self.update_map()
await self.update_embed(interaction)
await interaction.response.send_message(view=CV2("✅ Map Updated", "Moved down."), ephemeral=True)
async def move_right(self, interaction: discord.Interaction):
if self.longitude is not None:
self.longitude += 0.01
self.update_map()
await self.update_embed(interaction)
await interaction.response.send_message(view=CV2("✅ Map Updated", "Moved right."), ephemeral=True)
async def zoom_in(self, interaction: discord.Interaction):
print("Zooming in")
self.zoom_level = min(self.zoom_level + 1, 18)
self.update_map()
await self.update_embed(interaction)
await interaction.response.send_message(view=CV2("✅ Map Updated", "Zoomed in."), ephemeral=True)
async def zoom_out(self, interaction: discord.Interaction):
print("Zooming out")
self.zoom_level = max(self.zoom_level - 1, 0)
self.update_map()
await self.update_embed(interaction)
await interaction.response.send_message(view=CV2("✅ Map Updated", "Zoomed Out."), ephemeral=True)
async def enter_coordinates(self, interaction: discord.Interaction):
await interaction.response.send_message("Please enter the coordinates (latitude, longitude):", ephemeral=True)
def check(message):
return message.author == interaction.user and message.channel == interaction.channel
try:
coords_msg = await self.bot.wait_for('message', check=check, timeout=60)
coords = coords_msg.content.split(',')
if len(coords) == 2:
self.latitude, self.longitude = float(coords[0].strip()), float(coords[1].strip())
self.update_map()
await self.update_embed(interaction)
await interaction.followup.send(view=CV2("✅ Map Updated", "Coordinates updated."), ephemeral=True)
else:
await interaction.followup.send("Invalid coordinates format. Please enter in the format 'latitude, longitude'.", ephemeral=True)
except asyncio.TimeoutError:
await interaction.followup.send("You took too long to respond. Please try again.", ephemeral=True)
async def enter_address(self, interaction: discord.Interaction):
await interaction.response.send_message("Please enter the address:", ephemeral=True)
def check(message):
return message.author == interaction.user and message.channel == interaction.channel
try:
address_msg = await self.bot.wait_for('message', check=check, timeout=60)
address = address_msg.content
self.coordinates = self.get_coordinates(address)
if self.coordinates == (None, None):
await interaction.followup.send("Failed to retrieve coordinates for the address. Please try again.", ephemeral=True)
else:
self.latitude, self.longitude = float(self.coordinates[0]), float(self.coordinates[1])
self.location = address
self.update_map()
await self.update_embed(interaction)
await interaction.followup.send(view=CV2("✅ Map Updated", "Address updated."), ephemeral=True)
except asyncio.TimeoutError:
await interaction.followup.send("You took too long to respond. Please try again.", ephemeral=True)
class MapStyleSelect(ui.Select):
def __init__(self, map_view):
super().__init__(placeholder='Select Map Style')
self.map_view = map_view
options = [
SelectOption(label='Map', value='map'),
SelectOption(label='Satellite', value='sat'),
SelectOption(label='Hybrid', value='hyb'),
SelectOption(label='Light', value='light'),
SelectOption(label='Dark', value='dark'),
]
self.options = options
async def callback(self, interaction: discord.Interaction):
print(f"Changing map style to {self.values[0]}")
self.map_view.map_style = self.values[0]
self.map_view.update_map()
await self.map_view.update_embed(interaction)
await interaction.response.send_message(view=CV2("✅ Map Updated", "Map style updated successfully."), ephemeral=True)
class MapSizeSelect(ui.Select):
def __init__(self, map_view):
super().__init__(placeholder='Select Map Size')
self.map_view = map_view
options = [
SelectOption(label='400x300', value='400,300'),
SelectOption(label='800x600', value='800,600'),
SelectOption(label='1200x900', value='1200,900')
]
self.options = options
async def callback(self, interaction: discord.Interaction):
print(f"Changing map size to {self.values[0]}")
self.map_view.map_size = self.values[0]
self.map_view.update_map()
await self.map_view.update_embed(interaction)
await interaction.response.send_message(view=CV2("✅ Map Updated", "Map size updated successfully."), ephemeral=True)
class Map(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.hybrid_command(name="map", help="Shows a map of a location", usage="<location>", description="Shows a map of a location")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 5, commands.BucketType.user)
async def map(self, ctx, *, location: str):
view = MapView(self.bot, location, ctx)
if view.coordinates == (None, None):
await ctx.send(view=CV2("❌ Error", "Failed to retrieve coordinates for the location. Please try again."))
return
await ctx.send(view=view)
async def setup(bot):
await bot.add_cog(Map(bot))

View File

@@ -0,0 +1,108 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import discord
from utils.emoji import ARROWRED
from discord.ui import LayoutView, TextDisplay, Separator, Container
from discord.ext import commands
import sqlite3
from datetime import datetime
from utils.config import *
class MessagesView(LayoutView):
def __init__(self, member, total, today_count, daily_average, author):
super().__init__(timeout=None)
self.add_item(
Container(
TextDisplay(f"**Messages Stats for {member.display_name}**"),
Separator(visible=True),
TextDisplay(
f"**User**: {member.mention}\n\n"
f"**Daily Messages**: {daily_average}\n"
f"**Today Messages**: {today_count}\n"
f"**Total Messages**: {total}\n\n"
f"**{ARROWRED}Upgrade Your Experience With [{BRAND_NAME} Noprefix](https://discord.gg/codexdev)**"
),
)
)
class Messages(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_message(self, message):
if message.author.bot or not message.guild:
return
conn = sqlite3.connect("db/messages.db")
c = conn.cursor()
c.execute("""
CREATE TABLE IF NOT EXISTS messages (
guild_id INTEGER,
user_id INTEGER,
date TEXT,
count INTEGER
)
""")
today = datetime.utcnow().strftime("%Y-%m-%d")
c.execute(
"SELECT count FROM messages WHERE guild_id = ? AND user_id = ? AND date = ?",
(message.guild.id, message.author.id, today),
)
result = c.fetchone()
if result:
c.execute(
"UPDATE messages SET count = count + 1 WHERE guild_id = ? AND user_id = ? AND date = ?",
(message.guild.id, message.author.id, today),
)
else:
c.execute(
"INSERT INTO messages (guild_id, user_id, date, count) VALUES (?, ?, ?, 1)",
(message.guild.id, message.author.id, today),
)
conn.commit()
conn.close()
@commands.command(name="messages", aliases=["msg"])
async def messages(self, ctx, member: discord.Member = None):
member = member or ctx.author
today = datetime.utcnow().strftime("%Y-%m-%d")
conn = sqlite3.connect("db/messages.db")
c = conn.cursor()
c.execute(
"SELECT date, count FROM messages WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, member.id),
)
data = c.fetchall()
conn.close()
total = sum(row[1] for row in data)
today_count = sum(row[1] for row in data if row[0] == today)
unique_days = set(row[0] for row in data)
daily_average = round(total / len(unique_days), 2) if unique_days else 0
view = MessagesView(member, total, today_count, daily_average, ctx.author)
await ctx.send(view=view)
async def setup(client):
await client.add_cog(Messages(client))

View File

@@ -0,0 +1,283 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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, tasks
from discord import app_commands, ui, File
from mcstatus import JavaServer, BedrockServer
import aiosqlite
import os
import re
from datetime import datetime
from PIL import Image, ImageDraw, ImageFont
import io
import asyncio
import base64
from utils.emoji import SUCCESS, ERROR, WARNING_UNICODE, CLOCK, REFRESH, JAVA_COFFEE
# --- Updated Asset Paths ---
ASSETS_DIR = "assets"
FONT_PATH = os.path.join(ASSETS_DIR, "fonts", "minecraft.ttf")
BACKGROUND_PATH = os.path.join(ASSETS_DIR, "background", "background.png")
DB_PATH = "db/minecraft.db"
# --- Other Constants ---
REFRESH_COOLDOWN_SECONDS = 30
CANVAS_WIDTH = 800
CANVAS_HEIGHT = 125
# --- Emojis (imported from utils.emoji) ---
EMOJI_STATUS_ONLINE = "🟢"
EMOJI_STATUS_OFFLINE = "🔴"
EMOJI_PLAYERS = "👥"
EMOJI_INFO = "💻"
EMOJI_SUCCESS = SUCCESS
EMOJI_ERROR = ERROR
EMOJI_WARNING = WARNING_UNICODE
EMOJI_CLOCK = CLOCK
EMOJI_REFRESH = REFRESH
EMOJI_JAVA = JAVA_COFFEE
EMOJI_BEDROCK = "📱"
EMOJI_PROXY = "🔌"
class SetupModal(ui.Modal, title="Minecraft Server Setup"):
server_ip = ui.TextInput(label="Enter Server IP Address", placeholder="e.g., play.hypixel.net", required=True)
server_port = ui.TextInput(label="Enter Server Port (Optional)", placeholder="Leave blank for default ports", required=False)
def __init__(self, cog):
super().__init__(timeout=None)
self.cog = cog
async def on_submit(self, interaction: discord.Interaction):
await interaction.response.defer(ephemeral=True)
ip, port_str = self.server_ip.value.strip(), self.server_port.value.strip()
port = int(port_str) if port_str.isdigit() else None
detected_type, status, _ = await self.cog.auto_detect_server(ip, port)
if not detected_type or not status or not status['online']:
await interaction.followup.send(f"{EMOJI_ERROR} Could not reach or identify the server. Check IP/Port and try again.", ephemeral=True)
return
embed, file, view = await self.cog.generate_response(interaction.guild, detected_type, ip, port, interaction.user.id)
sent_message = await interaction.channel.send(embed=embed, file=file, view=view)
await self.cog.save_status_message(interaction.guild.id, interaction.user.id, interaction.channel.id, sent_message.id, detected_type, ip, port)
await interaction.followup.send(f"{EMOJI_SUCCESS} Auto-updating status for `{ip}` set up!", ephemeral=True)
class MinecraftView(ui.View):
def __init__(self, bot, server_type, ip, port, user_id):
super().__init__(timeout=None)
self.bot, self.server_type, self.ip, self.port, self.user_id = bot, server_type, ip, port, user_id
self.last_refresh = None
@ui.button(label="Refresh", style=discord.ButtonStyle.secondary, custom_id="refresh_button", emoji=EMOJI_REFRESH)
async def refresh_button(self, interaction: discord.Interaction, button: discord.ui.Button):
if interaction.user.id != self.user_id:
return await interaction.response.send_message(f"{EMOJI_ERROR} You can't refresh this panel.", ephemeral=True)
now = datetime.utcnow()
if self.last_refresh and (now - self.last_refresh).total_seconds() < REFRESH_COOLDOWN_SECONDS:
return await interaction.response.send_message(f"{EMOJI_CLOCK} On cooldown. Wait `{REFRESH_COOLDOWN_SECONDS}` seconds.", ephemeral=True)
await interaction.response.defer(ephemeral=True)
cog = self.bot.get_cog("Minecraft")
embed, file, view = await cog.generate_response(interaction.guild, self.server_type, self.ip, self.port, self.user_id)
await interaction.message.edit(embed=embed, attachments=[file] if file else [], view=view)
await interaction.followup.send(f"{EMOJI_SUCCESS} Status refreshed.", ephemeral=True)
self.last_refresh = now
class Minecraft(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
os.makedirs(os.path.dirname(FONT_PATH), exist_ok=True)
os.makedirs(os.path.dirname(BACKGROUND_PATH), exist_ok=True)
self.bot.loop.create_task(self.init_db())
self.refresh_all_statuses.start()
async def init_db(self):
async with aiosqlite.connect(DB_PATH) as db:
await db.execute("""
CREATE TABLE IF NOT EXISTS mc_status_messages (
guild_id INTEGER PRIMARY KEY, user_id INTEGER, channel_id INTEGER,
message_id INTEGER, server_type TEXT, server_ip TEXT, server_port INTEGER
)""")
await db.commit()
def clean_motd(self, motd: str) -> str:
return re.sub(r'§.', '', motd).strip()
async def auto_detect_server(self, ip: str, port: int = None):
try:
java_port = port or 25565
server = JavaServer(ip, java_port)
status = await asyncio.wait_for(server.async_status(tries=1), timeout=5)
version_name = status.version.name.lower()
detected_type = 'velocity' if 'velocity' in version_name else 'bungeecord' if 'bungee' in version_name else 'java'
favicon = getattr(status, 'favicon', None)
motd_raw = status.description
full_text = "".join(part.get('text', '') for part in motd_raw.get('extra', [])) or motd_raw.get('text', '') if isinstance(motd_raw, dict) else str(motd_raw)
status_data = {
"motd": self.clean_motd(full_text) or "A Minecraft Server",
"players_online": status.players.online, "players_max": status.players.max,
"players_sample": status.players.sample, "version": status.version.name, "online": True}
return detected_type, status_data, favicon
except Exception:
pass
try:
bedrock_port = port or 19132
server = BedrockServer(ip, bedrock_port)
status = await asyncio.wait_for(server.async_status(tries=1), timeout=5)
status_data = {
"motd": self.clean_motd(status.motd) or "A Minecraft Server",
"players_online": status.players.online, "players_max": status.players.max,
"players_sample": None, "version": status.version.name, "online": True}
return 'bedrock', status_data, None
except Exception:
pass
return None, {"online": False}, None
async def create_status_image(self, status_data, ip, port, server_type, server_icon_b64):
try:
bg = Image.open(BACKGROUND_PATH).convert("RGBA")
img = Image.new("RGBA", (CANVAS_WIDTH, CANVAS_HEIGHT))
for i in range(0, img.width, bg.width):
for j in range(0, img.height, bg.height): img.paste(bg, (i, j))
draw = ImageDraw.Draw(img)
font_large, font_medium, font_small = ImageFont.truetype(FONT_PATH, 24), ImageFont.truetype(FONT_PATH, 20), ImageFont.truetype(FONT_PATH, 16)
if server_icon_b64:
icon_data = base64.b64decode(server_icon_b64.split(',')[-1])
icon_img = Image.open(io.BytesIO(icon_data)).convert("RGBA").resize((80, 80), Image.Resampling.LANCZOS)
img.paste(icon_img, (20, (CANVAS_HEIGHT - 80) // 2), icon_img)
default_port = 25565 if server_type != 'bedrock' else 19132
full_ip = f"{ip}:{port}" if port and port != default_port else ip
draw.text((120, 15), f"IP: {full_ip}", font=font_medium, fill=(255, 255, 255))
player_text = f"{status_data.get('players_online', 0)}/{status_data.get('players_max', 0)}"
bbox = draw.textbbox((0, 0), player_text, font=font_medium)
draw.text((CANVAS_WIDTH - (bbox[2] - bbox[0]) - 20, 15), player_text, font=font_medium, fill=(255, 255, 255))
motd = (status_data.get('motd', 'Offline') or "A Minecraft Server").split('')[0]
bbox = draw.textbbox((0,0), motd, font=font_large)
draw.text(((CANVAS_WIDTH - (bbox[2] - bbox[0])) // 2, 60), motd, font=font_large, fill=(0, 255, 255))
power_text = "Powered by STACY"
bbox = draw.textbbox((0,0), power_text, font=font_small)
draw.text((CANVAS_WIDTH - (bbox[2] - bbox[0]) - 15, CANVAS_HEIGHT - 25), power_text, font=font_small, fill=(170, 170, 170))
buffer = io.BytesIO()
img.save(buffer, "PNG")
buffer.seek(0)
return File(buffer, filename="status.png")
except FileNotFoundError: return None
except Exception: return None
async def generate_response(self, guild, server_type, ip, port, user_id):
_, status, favicon = await self.auto_detect_server(ip, port)
if not status: status = {'online': False}
file = await self.create_status_image(status, ip, port, server_type, favicon)
is_online = status.get("online", False)
embed = discord.Embed(title=f"{EMOJI_STATUS_ONLINE if is_online else EMOJI_STATUS_OFFLINE} Minecraft Server Status", color=discord.Color.dark_green() if is_online else discord.Color.red())
default_port = 25565 if server_type != 'bedrock' else 19132
full_ip = f"{ip}:{port}" if port and port != default_port else ip
type_emoji_map = {'java': EMOJI_JAVA, 'bedrock': EMOJI_BEDROCK, 'velocity': EMOJI_PROXY, 'bungeecord': EMOJI_PROXY}
type_emoji = type_emoji_map.get(server_type, EMOJI_INFO)
info_value = (f"**IP:** `{full_ip}`\n"
f"**Type:** {type_emoji} {server_type.capitalize()}\n"
f"**Version:** `{status.get('version', 'Unknown')}`\n")
embed.add_field(name=f"{EMOJI_INFO} Server Information", value=info_value, inline=False)
players_online = status.get('players_online', 0)
players_max = status.get('players_max', 0)
player_list_str = f"**Online:** `{players_online}/{players_max}`\n"
player_sample = status.get('players_sample')
if player_sample:
player_names = [player.name for player in player_sample]
player_list_str += "\n".join(f"`{i+1}.` {name}" for i, name in enumerate(player_names[:10]))
if len(player_names) > 10:
player_list_str += f"*...and {len(player_names) - 10} more*"
elif is_online:
player_list_str += "*Player list is hidden or unavailable.*"
embed.add_field(name=f"{EMOJI_PLAYERS} Players", value=player_list_str, inline=False)
if file:
embed.set_image(url="attachment://status.png")
embed.set_footer(text="Last updated")
embed.timestamp = datetime.utcnow()
view = MinecraftView(self.bot, server_type, ip, port, user_id)
return embed, file, view
async def save_status_message(self, guild_id, user_id, channel_id, message_id, server_type, ip, port):
async with aiosqlite.connect(DB_PATH) as db:
await db.execute("""
INSERT INTO mc_status_messages (guild_id, user_id, channel_id, message_id, server_type, server_ip, server_port)
VALUES (?, ?, ?, ?, ?, ?, ?) ON CONFLICT(guild_id) DO UPDATE SET
user_id=excluded.user_id, channel_id=excluded.channel_id, message_id=excluded.message_id,
server_type=excluded.server_type, server_ip=excluded.server_ip, server_port=excluded.server_port
""", (guild_id, user_id, channel_id, message_id, server_type, ip, port))
await db.commit()
async def delete_status_message(self, guild_id):
async with aiosqlite.connect(DB_PATH) as db:
cursor = await db.execute("SELECT channel_id, message_id FROM mc_status_messages WHERE guild_id = ?", (guild_id,))
if row := await cursor.fetchone():
try:
channel = await self.bot.fetch_channel(row[0]); msg = await channel.fetch_message(row[1]); await msg.delete()
except (discord.NotFound, discord.Forbidden): pass
await db.execute("DELETE FROM mc_status_messages WHERE guild_id = ?", (guild_id,)); await db.commit()
return True
return False
@tasks.loop(minutes=2)
async def refresh_all_statuses(self):
await self.bot.wait_until_ready()
async with aiosqlite.connect(DB_PATH) as db:
async with db.execute("SELECT guild_id, user_id, channel_id, message_id, server_type, server_ip, server_port FROM mc_status_messages") as cursor:
async for row in cursor:
try:
guild = self.bot.get_guild(row[0])
if not guild: continue
channel = guild.get_channel(row[2])
if not channel: continue
message = await channel.fetch_message(row[3])
embed, file, view = await self.generate_response(guild, row[4], row[5], row[6], row[1])
await message.edit(embed=embed, attachments=[file] if file else [], view=view)
await asyncio.sleep(2)
except discord.NotFound: await self.delete_status_message(row[0])
except Exception as e: print(f"Auto-refresh error for guild {row[0]}: {e}")
minecraft = app_commands.Group(name="minecraft", description="Commands for Minecraft server status.")
@minecraft.command(name="setup", description="Set up the auto-updating Minecraft server status.")
@app_commands.checks.has_permissions(manage_guild=True)
async def setup_slash(self, interaction: discord.Interaction):
async with aiosqlite.connect(DB_PATH) as db:
if await (await db.execute("SELECT 1 FROM mc_status_messages WHERE guild_id = ?", (interaction.guild.id,))).fetchone():
return await interaction.response.send_message(f"{EMOJI_WARNING} Setup already exists. Use `/minecraft reset`.", ephemeral=True)
await interaction.response.send_modal(SetupModal(self))
@minecraft.command(name="reset", description="Remove the Minecraft server status setup.")
@app_commands.checks.has_permissions(manage_guild=True)
async def reset_slash(self, interaction: discord.Interaction):
await interaction.response.defer(ephemeral=True)
removed = await self.delete_status_message(interaction.guild.id)
await interaction.followup.send(f"{EMOJI_SUCCESS} Minecraft status panel removed." if removed else f"{EMOJI_WARNING} No setup found.", ephemeral=True)
@minecraft.command(name="status", description="Get a one-time status of the configured server.")
async def status_slash(self, interaction: discord.Interaction):
await interaction.response.defer(ephemeral=False)
async with aiosqlite.connect(DB_PATH) as db:
row = await (await db.execute("SELECT server_type, server_ip, server_port, user_id FROM mc_status_messages WHERE guild_id = ?", (interaction.guild.id,))).fetchone()
if not row:
return await interaction.followup.send(f"{EMOJI_WARNING} No server configured. Use `/minecraft setup`.", ephemeral=True)
embed, file, _ = await self.generate_response(interaction.guild, row[0], row[1], row[2], row[3])
await interaction.followup.send(embed=embed, file=file, ephemeral=False)
async def setup(bot: commands.Bot):
await bot.add_cog(Minecraft(bot))

View File

@@ -0,0 +1,82 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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 sqlite3
from datetime import datetime
class Messagespack(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.command(name="addmessages", aliases=["addmsg"])
@commands.has_permissions(manage_messages=True)
async def addmessages(self, ctx, member: discord.Member, amount: int):
if amount <= 0:
return await ctx.send("Amount must be greater than 0.")
today = datetime.utcnow().strftime("%Y-%m-%d")
conn = sqlite3.connect("db/messages.db")
c = conn.cursor()
c.execute("SELECT count FROM messages WHERE guild_id = ? AND user_id = ? AND date = ?",
(ctx.guild.id, member.id, today))
result = c.fetchone()
if result:
c.execute("UPDATE messages SET count = count + ? WHERE guild_id = ? AND user_id = ? AND date = ?",
(amount, ctx.guild.id, member.id, today))
else:
c.execute("INSERT INTO messages (guild_id, user_id, date, count) VALUES (?, ?, ?, ?)",
(ctx.guild.id, member.id, today, amount))
conn.commit()
conn.close()
await ctx.send(f"Added {amount} messages to {member.mention} for today.")
@commands.command(name="removemessages", aliases=["removemsg"])
@commands.has_permissions(manage_messages=True)
async def removemessages(self, ctx, member: discord.Member, amount: int):
if amount <= 0:
return await ctx.send("Amount must be greater than 0.")
today = datetime.utcnow().strftime("%Y-%m-%d")
conn = sqlite3.connect("db/messages.db")
c = conn.cursor()
c.execute("SELECT count FROM messages WHERE guild_id = ? AND user_id = ? AND date = ?",
(ctx.guild.id, member.id, today))
result = c.fetchone()
if result:
new_count = max(0, result[0] - amount)
c.execute("UPDATE messages SET count = ? WHERE guild_id = ? AND user_id = ? AND date = ?",
(new_count, ctx.guild.id, member.id, today))
conn.commit()
await ctx.send(f"Removed {amount} messages from {member.mention} for today.")
else:
await ctx.send(f"{member.mention} has no messages recorded for today.")
conn.close()
@commands.command(name="clearmessage", aliases=["clearmsg"])
@commands.has_permissions(manage_messages=True)
async def clearmessage(self, ctx, member: discord.Member):
conn = sqlite3.connect("db/messages.db")
c = conn.cursor()
c.execute("DELETE FROM messages WHERE guild_id = ? AND user_id = ?",
(ctx.guild.id, member.id))
conn.commit()
conn.close()
await ctx.send(f"All messages cleared for {member.mention}.")

988
bot/cogs/commands/music.py Normal file
View File

@@ -0,0 +1,988 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
import os
import random
import discord
from utils.emoji import FORWARD, ICONLOAD, ICONS_MUSIC, ICONS_PAUSE, ICONS_WARNING_ALT1, MUSICSTOP_ICONS, MUSIC_ALT1, MUTE, REWIND, REWIND_ALT1, SHUFFLE, SKIP, TICK, WARNING, ZMUSICPAUSE, ZPLUS, ZUNMUTE
from discord.ext import commands, tasks
import datetime
from discord.ui import Button, View, LayoutView, TextDisplay, Separator, Container, ActionRow
import wavelink
from wavelink.enums import TrackSource
from utils import Paginator, DescriptionEmbedPaginator
from core import Cog, zyrox, Context
from PIL import Image, ImageDraw, ImageFont, ImageOps
import io
import aiohttp
from typing import cast
import asyncio
from utils.Tools import *
from utils.cv2 import CV2, build_container, CV2Embed
track_histories = {}
import base64
import re
from utils.config import *
SPOTIFY_TRACK_REGEX = r"https?://open\.spotify\.com/track/([a-zA-Z0-9]+)"
SPOTIFY_PLAYLIST_REGEX = r"https?://open\.spotify\.com/playlist/([a-zA-Z0-9]+)"
SPOTIFY_ALBUM_REGEX = r"https?://open\.spotify\.com/album/([a-zA-Z0-9]+)"
class SpotifyAPI:
BASE_URL = "https://api.spotify.com/v1"
def __init__(self, client_id, client_secret):
self.client_id = client_id
self.client_secret = client_secret
self.token = None
async def get_token(self):
auth_url = "https://accounts.spotify.com/api/token"
auth_value = base64.b64encode(f"{self.client_id}:{self.client_secret}".encode('utf-8')).decode('utf-8')
headers = {"Authorization": f"Basic {auth_value}"}
data = {"grant_type": "client_credentials"}
async with aiohttp.ClientSession() as session:
async with session.post(auth_url, headers=headers, data=data) as response:
text = await response.text()
if response.status != 200:
raise Exception(f"Failed to fetch token: {response.status}, response: {text}")
self.token = (await response.json()).get("access_token")
async def get(self, endpoint, params=None):
retries = 2
for attempt in range(retries):
if not self.token or attempt > 0:
await self.get_token()
url = f"{self.BASE_URL}/{endpoint}"
headers = {"Authorization": f"Bearer {self.token}"}
async with aiohttp.ClientSession() as session:
async with session.get(url, headers=headers, params=params) as response:
if response.status == 401 and attempt < retries - 1:
continue
elif response.status != 200:
raise Exception(f"Failed to fetch data from Spotify: {response.status}")
return await response.json()
raise Exception("Exceeded max retries to fetch Spotify data")
async def get_track(self, track_id):
return await self.get(f"tracks/{track_id}")
async def get_playlist(self, playlist_id):
return await self.get(f"playlists/{playlist_id}")
spotify_api = SpotifyAPI(client_id="ac2b614ca5ce46a18dfd1d3475fd6fd9", client_secret="df7bec95ae88438e8286db597bac8621")
class PlatformSelectView(LayoutView):
def __init__(self, ctx, query):
super().__init__(timeout=60)
self.ctx = ctx
self.query = query
platforms = [
("YouTube", "ytsearch", discord.ButtonStyle.red),
("JioSaavn", "jssearch", discord.ButtonStyle.green),
("SoundCloud", "scsearch", discord.ButtonStyle.grey),
]
buttons = []
for name, source, style in platforms:
btn = Button(label=name, style=style)
btn.callback = self.create_callback(source)
buttons.append(btn)
container = build_container(
TextDisplay("**Select a platform to search from:**"),
Separator(visible=True),
TextDisplay("Click a button below to choose."),
Separator(visible=True),
ActionRow(*buttons),
)
self.add_item(container)
def create_callback(self, source):
async def callback(interaction: discord.Interaction):
if interaction.user != self.ctx.author:
await interaction.response.send_message("Only the command author can select a platform.", ephemeral=True)
return
await interaction.response.send_message(f"Searching...", ephemeral=True)
await self.perform_search(source)
await interaction.message.delete()
return callback
async def perform_search(self, source):
results = await wavelink.Playable.search(self.query, source=source)
if not results:
return await self.ctx.send(view=CV2("No results found."))
top_results = results[:5]
await self.ctx.send(view=SearchResultView(self.ctx, top_results, self.query, source))
class SearchResultView(LayoutView):
def __init__(self, ctx, results, query="", source=""):
super().__init__(timeout=60)
self.ctx = ctx
self.results = results
lines = [f"**Top 5 Results for '{query}'**", ""]
for i, track in enumerate(results, start=1):
dur = f"{track.length // 1000 // 60}:{track.length // 1000 % 60:02d}"
lines.append(f"`{i}.` **{track.title}** • `{dur}`")
buttons = []
for i in range(min(5, len(results))):
btn = Button(label=str(i + 1), style=discord.ButtonStyle.primary)
btn.callback = self.create_callback(i)
buttons.append(btn)
container = build_container(
TextDisplay("\n".join(lines)),
Separator(visible=True),
ActionRow(*buttons),
)
self.add_item(container)
def create_callback(self, index):
async def callback(interaction: discord.Interaction):
if interaction.user != self.ctx.author:
await interaction.response.send_message("Only the command author can select a track.", ephemeral=True)
return
track = self.results[index]
vc = self.ctx.voice_client or await self.ctx.author.voice.channel.connect(cls=wavelink.Player)
vc.ctx = self.ctx
if not vc.playing:
await vc.play(track)
await interaction.response.send_message(f"Started playing `{track.title}`.")
await self.ctx.cog.display_player_embed(vc, track, self.ctx)
else:
await vc.queue.put_wait(track)
await interaction.response.send_message(f"Added `{track.title}` to the queue.")
return callback
class MusicControlView(LayoutView):
def __init__(self, player, ctx, track=None, autoplay=False):
super().__init__(timeout=None)
self.player = player
self.ctx = ctx
self._build_ui(track, autoplay)
def _build_ui(self, track=None, autoplay=False):
from discord.ui import Section, Thumbnail, TextDisplay
items = []
if track:
sec = track.length // 1000
duration = f"{sec // 60:02d}:{sec % 60:02d}"
requester = self.ctx.author.display_name
if autoplay: requester += " (Autoplay)"
title_text = f"**Now Playing [{track.title}]({track.uri})**"
items.append(TextDisplay(title_text))
bullet_text = (
f"• **Author:** `{track.author}`\n"
f"• **Duration:** `{duration}`\n"
f"• **Requester:** {requester}"
)
if getattr(track, 'artwork', None):
accessory = Thumbnail(media=track.artwork)
items.append(Section(TextDisplay(bullet_text), accessory=accessory))
else:
items.append(TextDisplay(bullet_text))
# Row 1 buttons (Main 5 from screenshot with exact styles)
btn_pause = Button(emoji=ICONS_PAUSE, label="Pause", style=discord.ButtonStyle.primary)
btn_skip = Button(emoji=SKIP, label="Skip", style=discord.ButtonStyle.secondary)
btn_stop = Button(emoji=MUSICSTOP_ICONS, label="Stop", style=discord.ButtonStyle.danger)
btn_loop = Button(emoji=ICONLOAD, label="Loop", style=discord.ButtonStyle.secondary)
btn_autoplay = Button(emoji=ZUNMUTE, label="Autoplay", style=discord.ButtonStyle.secondary)
# Row 2 buttons (Remaining controls)
btn_prev = Button(emoji=REWIND, style=discord.ButtonStyle.secondary)
btn_shuffle = Button(emoji=SHUFFLE, style=discord.ButtonStyle.secondary)
btn_rewind = Button(emoji=REWIND_ALT1, style=discord.ButtonStyle.secondary)
btn_forward = Button(emoji=FORWARD, style=discord.ButtonStyle.secondary)
btn_replay = Button(emoji=ICONS_MUSIC, style=discord.ButtonStyle.secondary)
btn_pause.callback = self._cb_pause
btn_skip.callback = self._cb_skip
btn_stop.callback = self._cb_stop
btn_loop.callback = self._cb_loop
btn_autoplay.callback = self._cb_autoplay
btn_prev.callback = self._cb_previous
btn_shuffle.callback = self._cb_shuffle
btn_rewind.callback = self._cb_rewind
btn_forward.callback = self._cb_forward
btn_replay.callback = self._cb_replay
items.append(ActionRow(btn_pause, btn_skip, btn_stop, btn_loop, btn_autoplay))
items.append(ActionRow(btn_prev, btn_shuffle, btn_rewind, btn_forward, btn_replay))
container = build_container(*items)
self.add_item(container)
async def interaction_check(self, interaction: discord.Interaction) -> bool:
if not self.ctx.voice_client or not self.player.playing:
await interaction.response.send_message("I'm not currently playing this anymore.", ephemeral=True)
return False
if interaction.user in self.ctx.voice_client.channel.members:
return True
await interaction.response.send_message("Only members in the same voice channel can control the player.", ephemeral=True)
return False
async def _cb_autoplay(self, interaction):
self.player.autoplay = (
wavelink.AutoPlayMode.enabled if self.player.autoplay != wavelink.AutoPlayMode.enabled else wavelink.AutoPlayMode.disabled
)
await interaction.response.send_message(f"Autoplay {'enabled' if self.player.autoplay == wavelink.AutoPlayMode.enabled else 'disabled'} by **{interaction.user.display_name}**.")
async def _cb_previous(self, interaction):
guild_id = interaction.guild.id
if guild_id in track_histories and len(track_histories[guild_id]) > 1:
track_histories[guild_id].pop()
previous_track = track_histories[guild_id][-1]
if self.player.playing:
await self.player.stop()
await self.ctx.voice_client.queue.put_wait(previous_track)
await interaction.response.send_message(f"Playing previous track: `{previous_track.title}`.")
else:
await interaction.response.send_message("No previous track available.", ephemeral=True)
async def _cb_pause(self, interaction):
if self.player.paused:
await self.player.pause(False)
await self.player.channel.edit(status=f"{ICONS_PAUSE} Playing: {self.player.current.title}")
await interaction.response.send_message(f"Resumed by **{interaction.user.display_name}**.")
elif self.player.playing:
await self.player.pause(True)
await self.player.channel.edit(status=f"{ICONS_PAUSE} Paused: {self.player.current.title}")
await interaction.response.send_message(f"Paused by **{interaction.user.display_name}**.")
async def _cb_skip(self, interaction):
if self.player.autoplay == wavelink.AutoPlayMode.enabled:
await self.player.stop()
return await interaction.response.send_message(f"Skipped by **{interaction.user.display_name}**.")
if self.player and self.player.playing and not self.player.queue.is_empty:
await self.player.stop()
await interaction.response.send_message(f"Skipped by **{interaction.user.display_name}**.")
else:
await interaction.response.send_message("No song in queue to skip.", ephemeral=True)
async def _cb_loop(self, interaction):
self.player.queue.mode = wavelink.QueueMode.loop if self.player.queue.mode != wavelink.QueueMode.loop else wavelink.QueueMode.normal
await interaction.response.send_message(f"Loop {'enabled' if self.player.queue.mode == wavelink.QueueMode.loop else 'disabled'} by **{interaction.user.display_name}**.")
async def _cb_shuffle(self, interaction):
if self.player.queue:
random.shuffle(self.player.queue)
await interaction.response.send_message(f"Queue shuffled by **{interaction.user.display_name}**.")
else:
await interaction.response.send_message("Queue is empty.", ephemeral=True)
async def _cb_rewind(self, interaction):
if self.player.playing:
new_position = max(self.player.position - 10000, 0)
await self.player.seek(new_position)
await interaction.response.send_message("Rewinded 10 seconds.", ephemeral=True)
else:
await interaction.response.send_message("No track is currently playing.", ephemeral=True)
async def _cb_stop(self, interaction):
if self.player:
voice_channel = self.player.channel
if voice_channel:
await voice_channel.edit(status=None)
await self.player.disconnect()
await interaction.response.send_message(f"Stopped and disconnected by **{interaction.user.display_name}**.")
else:
await interaction.response.send_message("Not connected.", ephemeral=True)
async def _cb_forward(self, interaction):
if self.player.playing:
new_position = min(self.player.position + 10000, self.player.current.length)
await self.player.seek(new_position)
await interaction.response.send_message("Forwarded 10 seconds.", ephemeral=True)
else:
await interaction.response.send_message("No track is currently playing.", ephemeral=True)
async def _cb_replay(self, interaction):
if self.player.playing:
await self.player.seek(0)
await interaction.response.send_message("Replaying the current track.", ephemeral=True)
else:
await interaction.response.send_message("No track is currently playing.", ephemeral=True)
class Music(commands.Cog):
def __init__(self, client: zyrox):
self.client = client
self.client.loop.create_task(self.connect_nodes())
self.client.loop.create_task(self.monitor_inactivity())
self.inactivity_timeout = 120
self.player_inactivity = {}
async def monitor_inactivity(self):
while True:
for guild in self.client.guilds:
await self.check_inactivity(guild.id)
await asyncio.sleep(60)
async def check_inactivity(self, guild_id):
guild = self.client.get_guild(guild_id)
if not guild:
return
player = None
for vc in self.client.voice_clients:
if vc.guild.id == guild.id:
player = vc
break
if player and player.playing and len(player.channel.members) == 1:
await self.inactivity_timer(guild)
async def inactivity_timer(self, guild):
await asyncio.sleep(self.inactivity_timeout)
if len(guild.voice_channels[0].members) == 1:
player = None
for vc in self.client.voice_clients:
if vc.guild.id == guild.id:
player = vc
break
if player:
await player.disconnect(force=True)
try:
support = Button(label='Support', style=discord.ButtonStyle.link, url='https://discord.gg/codexdev')
vote = Button(label='Vote', style=discord.ButtonStyle.link, url='https://top.gg/bot//vote')
view = LayoutView(timeout=None)
container = build_container(
TextDisplay("**Inactive Timeout**"),
Separator(visible=True),
TextDisplay("Bot has been disconnected due to inactivity (being idle in Voice Channel) for more than 2 minutes."),
Separator(visible=True),
ActionRow(support, vote),
Separator(visible=True),
TextDisplay(f"*Thanks for choosing {BRAND_NAME}!*"),
)
view.add_item(container)
await player.ctx.channel.send(view=view)
except:
pass
async def connect_nodes(self) -> None:
host = os.getenv("LAVALINK_HOST", "lava-v4.ajieblogs.eu.org")
password = os.getenv("LAVALINK_PASSWORD", "https://dsc.gg/ajidevserver")
secure = os.getenv("LAVALINK_SECURE", "true").strip().lower() == "true"
port = os.getenv("LAVALINK_PORT", "").strip()
if secure:
uri = f"https://{host}"
else:
uri = f"http://{host}:{port}" if port else f"http://{host}"
nodes = [wavelink.Node(uri=uri, password=password)]
await wavelink.Pool.connect(nodes=nodes, client=self.client, cache_capacity=None)
async def display_player_embed(self, player, track, ctx, autoplay=False):
await ctx.send(view=MusicControlView(player, ctx, track, autoplay))
async def on_track_end(self, payload: wavelink.TrackEndEventPayload):
player = payload.player
if not player.queue:
if player.queue.mode == wavelink.QueueMode.loop:
await player.play(payload.track)
elif player.autoplay == wavelink.AutoPlayMode.enabled:
await asyncio.sleep(5)
if player.current:
await self.display_player_embed(player, player.current, player.ctx, autoplay=True)
else:
await player.ctx.send(view=CV2("No suitable track found for autoplay."))
else:
await player.disconnect()
support = Button(label='Support', style=discord.ButtonStyle.link, url='https://discord.gg/codexdev')
vote = Button(label='Vote', style=discord.ButtonStyle.link, url='https://top.gg/bot//vote')
view = LayoutView(timeout=None)
container = build_container(
TextDisplay("**Queue Ended**"),
Separator(visible=True),
TextDisplay("All tracks have been played, leaving the voice channel."),
Separator(visible=True),
ActionRow(support, vote),
)
view.add_item(container)
await player.ctx.send(view=view)
else:
next_track = await player.queue.get_wait()
await player.play(next_track)
await self.display_player_embed(player, next_track, player.ctx)
async def play_source(self, ctx, query):
if not ctx.author.voice:
await ctx.send(view=CV2(f"{WARNING} you need to be in a voice channel to use this command."))
return
vc = ctx.voice_client or await ctx.author.voice.channel.connect(cls=wavelink.Player)
vc.ctx = ctx
if vc.playing:
if ctx.voice_client and ctx.voice_client.channel != ctx.author.voice.channel:
await ctx.send(view=CV2(f"You must be connected to {ctx.voice_client.channel.mention} to play."))
return
vc.autoplay = wavelink.AutoPlayMode.disabled
"""if re.match(SPOTIFY_TRACK_REGEX, query):
await self.handle_spotify_link(ctx, vc, query, "track")
elif re.match(SPOTIFY_PLAYLIST_REGEX, query):
await self.handle_spotify_link(ctx, vc, query, "playlist")
elif re.match(SPOTIFY_ALBUM_REGEX, query):
await self.handle_spotify_link(ctx, vc, query, "album")
return"""
tracks = await wavelink.Playable.search(query)
if not tracks:
await ctx.send(view=CV2("No results found."))
return
if isinstance(tracks, wavelink.Playlist):
await vc.queue.put_wait(tracks.tracks)
await ctx.send(view=CV2(f"{ZPLUS} Added playlist [{tracks.name}](https://discord.gg/codexdev) with **{len(tracks.tracks)} songs** to the queue."))
if not vc.playing:
track = await vc.queue.get_wait()
await vc.play(track)
await self.display_player_embed(vc, track, ctx)
else:
track = tracks[0]
await vc.queue.put_wait(track)
await ctx.send(view=CV2(f"{ZPLUS} Added [{track.title}](https://discord.gg/codexdev) to the queue."))
if not vc.playing:
await vc.play(await vc.queue.get_wait())
await self.display_player_embed(vc, track, ctx)
self.client.loop.create_task(self.check_inactivity(ctx.guild.id))
# await interaction.response.defer()
async def handle_spotify_link(self, ctx, vc, link, type_):
try:
if type_ == "track":
track_id = re.search(SPOTIFY_TRACK_REGEX, link).group(1)
track_info = await spotify_api.get_track(track_id)
title = track_info['name']
author = ', '.join(artist['name'] for artist in track_info['artists'])
search_query = f"{title} by {author}"
search_results = await wavelink.Playable.search(search_query, source=wavelink.enums.TrackSource.YouTube)
if not search_results:
await ctx.send("Can't play this track from Spotify, please try with another track.")
return
track = search_results[0]
await vc.queue.put_wait(track)
await ctx.send(view=CV2(f"{ZPLUS} Added [{track.title}](https://discord.gg/codexdev) to the queue."))
if not vc.playing:
await vc.play(track)
await self.display_player_embed(vc, track, ctx)
#await self.display_player_embed(vc, track, ctx)
elif type_ == "playlist":
lmao = await ctx.send("⏳ Processing to add tracks from the playlist, this may take a while...")
playlist_id = re.search(SPOTIFY_PLAYLIST_REGEX, link).group(1)
playlist_info = await spotify_api.get(f"playlists/{playlist_id}")
tracks = playlist_info.get("tracks", {}).get("items", [])
playlist_length = len(tracks)
if not tracks:
await ctx.send("No tracks found in the playlist.")
return
c = 0
for track in tracks:
title = track['track']['name']
author = ', '.join(artist['name'] for artist in track['track']['artists'])
search_query = f"{title} {author}"
track_results = await wavelink.Playable.search(search_query, source=wavelink.enums.TrackSource.YouTube)
if track_results:
await vc.queue.put_wait(track_results[0])
c += 1
await ctx.message.add_reaction("")
await ctx.send(view=CV2(f"{ZPLUS} Added **{c}** of **{playlist_length}** tracks from **playlist** **[{playlist_info['name']}](https://discord.gg/codexdev)** to the queue."))
await lmao.delete()
if not vc.playing:
next_track = await vc.queue.get_wait()
await vc.play(next_track)
await self.display_player_embed(vc, next_track, ctx)
elif type_ == "album":
await ctx.message.add_reaction("")
album_id = re.search(SPOTIFY_ALBUM_REGEX, link).group(1)
album_info = await spotify_api.get(f"albums/{album_id}")
tracks = album_info.get("tracks", {}).get("items", [])
if not tracks:
await ctx.send("No tracks found in the album.")
return
for track in tracks:
title = track['name']
author = ', '.join(artist['name'] for artist in track['artists'])
search_query = f"{title} {author}"
track_results = await wavelink.Playable.search(search_query, source=wavelink.enums.TrackSource.YouTube)
if track_results:
await vc.queue.put_wait(track_results[0])
await ctx.send(view=CV2(f"{ZPLUS} Added all tracks from album **[{album_info['name']}](https://discord.gg/codexdev)** to the queue."))
if not vc.playing:
next_track = await vc.queue.get_wait()
await vc.play(next_track)
await self.display_player_embed(vc, next_track, ctx)
except Exception as e:
await ctx.send(f"An error occurred while processing the Spotify link: {e}")
def create_progress_bar(self, completed, total, length=10):
filled_length = int(length * (completed / total))
bar = '' * filled_length + '' * (length - filled_length)
return bar
@commands.command(name="play", aliases=['p'], usage="play <query>", help="Plays a song or playlist.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def play(self, ctx: commands.Context, *, query: str):
await self.play_source(ctx, query)
@commands.command(name="search", usage="search <query>", help="Searches music from multiple platforms.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def search2(self, ctx: commands.Context, *, query: str):
if not ctx.author.voice:
await ctx.send(view=CV2(f"{WARNING} You need to be in a voice channel to use this command."))
return
await ctx.send(view=PlatformSelectView(ctx, query))
@commands.command(name="nowplaying", aliases=["nop"], usage="nowplaying", help="Shows the info about current playing song.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def nowplaying(self, ctx: commands.Context):
vc = ctx.voice_client
if not vc or not vc.playing:
await ctx.send(view=CV2("No song is currently playing."))
return
if not ctx.author.voice or ctx.author.voice.channel.id != vc.channel.id:
await ctx.send(view=CV2("You need to be in the same voice channel as me to use this command."))
return
track = vc.current
position = vc.position / 1000
length = track.length / 1000
progress_bar = self.create_progress_bar(position, length, length=10)
position_str = f"{int(position // 60)}:{int(position % 60):02}"
length_str = f"{int(length // 60)}:{int(length % 60):02}"
queue_length = len(vc.queue) if vc.queue else 0
if "spotify" in track.uri:
source_name = "Spotify"
elif "youtube" in track.uri:
source_name = "YouTube"
elif "soundcloud" in track.uri:
source_name = "SoundCloud"
elif "jiosaavn" in track.uri:
source_name = "JioSaavn"
else:
source_name = "Unknown Source"
view = CV2Embed(
title="🎶 Now Playing",
color=0x1DB954 if source_name == "Spotify" else 0xFF0000
)
view.add_field(name="Track", value=f"[{track.title}]({track.uri})", inline=False)
view.add_field(name="Song By", value=track.author, inline=False)
view.add_field(name="Progress", value=f"{position_str} [{progress_bar}] {length_str}", inline=False)
view.add_field(name="Duration", value=length_str, inline=False)
view.add_field(name="Queue Length", value=str(queue_length), inline=False)
view.add_field(name="Source", value=f"{source_name} - [Link]({track.uri})", inline=False)
view.set_thumbnail(url=track.artwork if track.artwork else "")
view.set_footer(text=f"Requested by {ctx.author.display_name}", icon_url=ctx.author.avatar.url if ctx.author.avatar else ctx.author.default_avatar.url)
await ctx.send(view=view)
@commands.command(name="autoplay", usage="autoplay", help="Toggles autoplay mode.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def autoplay(self, ctx: commands.Context):
vc = ctx.voice_client
if not vc or not vc.playing:
await ctx.send(view=CV2(f"{WARNING} No song is currently playing."))
return
if not ctx.author.voice or ctx.author.voice.channel.id != vc.channel.id:
await ctx.send(view=CV2(f"{WARNING} You need to be in the same voice channel as me to use this command."))
return
if vc:
vc.autoplay = (
wavelink.AutoPlayMode.enabled if vc.autoplay != wavelink.AutoPlayMode.enabled else wavelink.AutoPlayMode.disabled
)
await ctx.send(view=CV2(f"{TICK} Autoplay {'enabled' if vc.autoplay == wavelink.AutoPlayMode.enabled else 'disabled'} by {ctx.author.mention}."))
@commands.command(name="loop", usage="loop", help="Toggles loop mode.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def loop(self, ctx: commands.Context):
vc = ctx.voice_client
if not vc or not vc.playing:
await ctx.send(view=CV2(f"{WARNING} No song is currently playing."))
return
if not ctx.author.voice or ctx.author.voice.channel.id != vc.channel.id:
await ctx.send(view=CV2(f"{WARNING} You need to be in the same voice channel as me to use this command."))
return
if vc:
vc.queue.mode = wavelink.QueueMode.loop if vc.queue.mode != wavelink.QueueMode.loop else wavelink.QueueMode.normal
await ctx.send(view=CV2(f"{TICK} Loop {'enabled' if vc.queue.mode == wavelink.QueueMode.loop else 'disabled'} by {ctx.author.mention}."))
else:
await ctx.send(view=CV2("I'm not connected to a voice channel."))
@commands.command(name="pause", usage="pause", help="Pauses the current song.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def pause(self, ctx: commands.Context):
vc = ctx.voice_client
if not vc or not vc.playing:
await ctx.send(view=CV2(f"{WARNING} No song is currently playing."))
return
if not ctx.author.voice or ctx.author.voice.channel.id != vc.channel.id:
await ctx.send(view=CV2(f"{WARNING} You need to be in the same voice channel as me to use this command."))
return
if vc and vc.playing and not vc.paused:
await vc.pause(True)
await vc.channel.edit(status=f"{ZMUSICPAUSE} Paused: {vc.current.title}")
await ctx.send(view=CV2(f"Paused by {ctx.author.mention}."))
else:
await ctx.send(view=CV2(f"{WARNING} Nothing is playing or already paused."))
@commands.command(name="resume", usage="resume", help="Resumes the paused song.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def resume(self, ctx: commands.Context):
vc = ctx.voice_client
if not vc or not vc.playing:
await ctx.send(view=CV2(f"{WARNING} No song is currently playing."))
return
if not ctx.author.voice or ctx.author.voice.channel.id != vc.channel.id:
await ctx.send(view=CV2(f"{ICONS_WARNING_ALT1} You need to be in the same voice channel as me to use this command."))
return
if vc and vc.paused:
await vc.pause(False)
await vc.channel.edit(status=f"{MUSIC_ALT1} Playing: {vc.current.title}")
await ctx.send(view=CV2(f"Resumed by {ctx.author.mention}."))
else:
await ctx.send(view=CV2("Player is not paused."))
@commands.command(name="skip", usage="skip", help="Skips the current song.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def skip(self, ctx: commands.Context):
vc = ctx.voice_client
if not vc or not vc.playing:
await ctx.send(view=CV2("No song is currently playing."))
return
if not ctx.author.voice or ctx.author.voice.channel.id != vc.channel.id:
await ctx.send(view=CV2(f"{WARNING} You need to be in the same voice channel as me to use this command."))
return
if vc.autoplay == wavelink.AutoPlayMode.enabled:
await vc.stop()
return await ctx.send(view=CV2(f"Skipped by {ctx.author.mention}."))
if vc and vc.playing and not vc.queue.is_empty:
await vc.stop()
await ctx.send(view=CV2(f"Skipped by {ctx.author.mention}."))
else:
await ctx.send(view=CV2(f"{WARNING} No song is playing or in the queue to skip."))
@commands.command(name="shuffle", usage="shuffle", help="Shuffles the queue.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def shuffle(self, ctx: commands.Context):
vc = ctx.voice_client
if not vc or not vc.playing:
await ctx.send(view=CV2(f"{WARNING} No song is currently playing."))
return
if not ctx.author.voice or ctx.author.voice.channel.id != vc.channel.id:
await ctx.send(view=CV2(f"{WARNING} You need to be in the same voice channel as me to use this command."))
return
if vc and vc.queue:
random.shuffle(vc.queue)
await ctx.send(view=CV2(f"Queue shuffled by {ctx.author.mention}."))
else:
await ctx.send(view=CV2("Queue is empty."))
@commands.command(name="stop", usage="stop", help="Stops the current song and clears the queue.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def stop(self, ctx: commands.Context):
player: wavelink.Player = cast(wavelink.Player, ctx.voice_client)
vc = ctx.voice_client
if not vc or not vc.playing:
await ctx.send(view=CV2(f"{WARNING} No song is currently playing."))
return
if not ctx.author.voice or ctx.author.voice.channel.id != vc.channel.id:
await ctx.send(view=CV2(f"{WARNING} You need to be in the same voice channel as me to use this command."))
return
if vc and player:
await vc.channel.edit(status=None)
vc.queue.clear()
await vc.disconnect(force=True)
await ctx.send(view=CV2(f"Stopped and queue cleared by {ctx.author.mention}."))
else:
await ctx.send(view=CV2("Nothing is playing to stop."))
@commands.command(name="volume", aliases=["vol"], usage="volume <level>", help="Sets the volume of the player.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def volume(self, ctx: commands.Context, level: int):
vc = ctx.voice_client
if not vc:
await ctx.send(view=CV2(f"{WARNING} I'm not connected to a voice channel."))
return
if not ctx.author.voice or ctx.author.voice.channel.id != vc.channel.id:
await ctx.send(view=CV2(f"{WARNING} You need to be in the same voice channel as me to use this command."))
return
if vc:
if 1 <= level <= 150:
await vc.set_volume(level)
await ctx.send(view=CV2(f"{MUTE} Volume set to {level}% by {ctx.author.mention}."))
else:
await ctx.send(view=CV2(f"{WARNING} Volume must be between 1 and 150."))
else:
await ctx.send(view=CV2("Bot is not connected to a voice channel."))
@commands.command(name="queue", usage="queue", help="Shows the current queue.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def queue(self, ctx: commands.Context):
vc = ctx.voice_client
if not vc or not vc.queue or vc.queue.is_empty:
await ctx.send(view=CV2(f"{WARNING} The queue is currently empty."))
return
if not ctx.author.voice or ctx.author.voice.channel.id != vc.channel.id:
await ctx.send(view=CV2(f"{WARNING} you need to be in the same voice channel as me to use this command."))
return
entries = [f"{index + 1}. [{track.title} - {track.author}]({track.uri})" for index, track in enumerate(vc.queue)]
paginator = Paginator(source=DescriptionEmbedPaginator(
entries=entries,
title="Current Queue",
description="List of upcoming songs.",
per_page=10,
color=0xFF0000),
ctx=ctx)
await paginator.paginate()
@commands.command(name="clearqueue", usage="clearqueue", help="Clears the queue.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def clearqueue(self, ctx: commands.Context):
vc = ctx.voice_client
if not vc or not vc.queue or vc.queue.is_empty:
await ctx.send(view=CV2(f"{WARNING} No Queue to clear."))
return
if not ctx.author.voice or ctx.author.voice.channel.id != vc.channel.id:
await ctx.send(view=CV2(f"{WARNING} You need to be in the same voice channel as me to use this command."))
return
if vc and vc.queue:
vc.queue.clear()
await ctx.send(view=CV2("Queue has been cleared."))
else:
await ctx.send(view=CV2("No queue to clear."))
@commands.command(name="replay", usage="replay", help="Replays the current song.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def replay(self, ctx: commands.Context):
vc = ctx.voice_client
if not vc or not vc.playing:
await ctx.send(view=CV2(f"{WARNING} I'm not connected to any voice channel."))
return
if not ctx.author.voice or ctx.author.voice.channel.id != vc.channel.id:
await ctx.send(view=CV2(f"{WARNING} You need to be in the same voice channel as me to use this command."))
return
if vc and vc.playing:
await vc.seek(0)
await ctx.send(view=CV2("Replaying the current track."))
else:
await ctx.send(view=CV2("No track is currently playing."))
@commands.command(name="join", aliases=["connect"], usage="join", help="Joins the voice channel.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def join(self, ctx: commands.Context):
if ctx.author.voice:
await ctx.author.voice.channel.connect(cls=wavelink.Player)
await ctx.send(view=CV2("Joined the voice channel."))
else:
await ctx.send(view=CV2("You need to join a voice channel first."))
@commands.hybrid_command(name="disconnect", aliases=["dc", "leave"], usage="disconnect", help="Disconnects the bot from the voice channel.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def disconnect(self, ctx: commands.Context):
vc = ctx.voice_client
if not vc:
await ctx.send(view=CV2(f"{ICONS_WARNING_ALT1} I'm not connected to any voice channel."))
return
if not ctx.author.voice or ctx.author.voice.channel.id != vc.channel.id:
await ctx.send(view=CV2(f"{WARNING} You need to be in the same voice channel as me to use this command."))
return
if vc:
await vc.disconnect()
await ctx.send(view=CV2("Disconnected from the voice channel."))
else:
await ctx.send(view=CV2("Bot is not connected to any voice channel."))
@commands.command(name="seek", usage="seek <percentage>", help="Seeks to a specific percentage of the song.")
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 3, commands.BucketType.user)
async def seek(self, ctx: commands.Context, percentage: int):
if not 1 <= percentage <= 100:
await ctx.send(view=CV2("Please provide a percentage between 1 and 100."))
return
vc = ctx.voice_client
if not vc or not vc.playing:
await ctx.send(view=CV2("No song is currently playing."))
return
if not ctx.author.voice or ctx.author.voice.channel.id != vc.channel.id:
await ctx.send(view=CV2("You need to be in the same voice channel as me to use this command."))
return
track = vc.current
target_position = int(track.length * (percentage / 100))
await vc.seek(target_position)
await ctx.send(view=CV2(f"Seeked to {percentage}% of the current track."))
@commands.Cog.listener()
async def on_wavelink_track_start(self, payload: wavelink.TrackStartEventPayload):
player = payload.player
track = player.current
guild_id = player.guild.id
voice_channel = player.channel
if voice_channel:
await voice_channel.edit(status=f"{MUSIC_ALT1} Playing: {track.title}") # type: ignore
if guild_id not in track_histories:
track_histories[guild_id] = []
if not track_histories[guild_id] or track_histories[guild_id][-1] != track:
track_histories[guild_id].append(track)
if len(track_histories[guild_id]) > 10:
track_histories[guild_id].pop(0)
@commands.Cog.listener()
async def on_wavelink_track_end(self, payload: wavelink.TrackEndEventPayload):
player = payload.player
voice_channel = player.channel
if voice_channel:
await voice_channel.edit(status=None) # type: ignore
await self.on_track_end(payload)

View File

@@ -0,0 +1,228 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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 os
from utils.Tools import *
from utils.cv2 import CV2
from discord.ui import TextDisplay, Separator, ActionRow, LayoutView, Container
from utils.config import OWNER_IDS_STR
# Database setup
db_folder = "db"
db_file = "anti.db"
db_path = os.path.join(db_folder, db_file)
class Nightmode(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.bot.loop.create_task(self.initialize_db())
self.ricky = OWNER_IDS_STR
self.color = 0xFF0000
async def initialize_db(self):
self.db = await aiosqlite.connect(db_path)
await self.db.execute("""
CREATE TABLE IF NOT EXISTS Nightmode (
guildId TEXT,
roleId TEXT,
adminPermissions INTEGER
)
""")
await self.db.commit()
async def is_extra_owner(self, user, guild):
async with self.db.execute(
"""
SELECT owner_id FROM extraowners WHERE guild_id = ? AND owner_id = ?
""",
(guild.id, user.id),
) as cursor:
extra_owner = await cursor.fetchone()
return extra_owner is not None
@commands.hybrid_group(
name="nightmode",
aliases=[],
help="Manages Nightmode feature",
invoke_without_command=True,
)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 10, commands.BucketType.user)
@commands.max_concurrency(1, per=commands.BucketType.default, wait=False)
@commands.guild_only()
async def nightmode(self, ctx):
view = CV2(
"__**Nightmode**__",
"Nightmode swiftly disables dangerous permissions for roles, like stripping `ADMINISTRATION` rights, while preserving original settings for seamless restoration.\n\n**Make sure to keep my ROLE above all roles you want to protect.**",
"**Usage**\n `nightmode enable`\n `nightmode disable`",
)
await ctx.send(view=view)
@nightmode.command(name="enable", help="Enable nightmode")
@commands.has_permissions(administrator=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 10, commands.BucketType.user)
async def enable_nightmode(self, ctx):
if ctx.guild.member_count < 50:
view = CV2(
"Access Denied",
"Your Server Doesn't Meet My 50 Member Criteria",
)
return await ctx.send(view=view)
own = ctx.author.id == ctx.guild.owner_id
check = await self.is_extra_owner(ctx.author, ctx.guild)
if not own and not check and ctx.author.id not in self.ricky:
view = CV2(
"Access Denied",
"Only Server Owner Or Extraowner Can Run This Command.!",
)
return await ctx.send(view=view)
if (
not own
and not (ctx.guild.me.top_role.position <= ctx.author.top_role.position)
and ctx.author.id not in self.ricky
):
view = CV2(
"Access Denied",
"Only Server Owner or Extraowner Having **Higher role than me can run this command**",
)
return await ctx.send(view=view)
bot_highest_role = ctx.guild.me.top_role
manageable_roles = [
role
for role in ctx.guild.roles
if role.position < bot_highest_role.position
and role.name != "@everyone"
and role.permissions.administrator
and not role.managed
]
if not manageable_roles:
view = CV2(
"Error",
"No Roles Found With Admin Permissions",
)
return await ctx.send(view=view)
async with self.db.execute(
"SELECT guildId FROM Nightmode WHERE guildId = ?", (str(ctx.guild.id),)
) as cursor:
if await cursor.fetchone():
view = CV2(
"Error",
"Nightmode is already enabled.",
)
return await ctx.send(view=view)
async with self.db.cursor() as cursor:
for role in manageable_roles:
admin_permissions = discord.Permissions(administrator=True)
if role.permissions.administrator:
permissions = role.permissions
permissions.administrator = False
await role.edit(permissions=permissions, reason="Nightmode ENABLED")
await cursor.execute(
"""
INSERT OR REPLACE INTO Nightmode (guildId, roleId, adminPermissions)
VALUES (?, ?, ?)
""",
(str(ctx.guild.id), str(role.id), int(admin_permissions.value)),
)
await self.db.commit()
view = CV2(
"Success",
"Nightmode enabled! Dangerous Permissions Disabled For Manageable Roles.",
)
await ctx.send(view=view)
@nightmode.command(name="disable", help="Disable nightmode")
@commands.has_permissions(administrator=True)
@blacklist_check()
@ignore_check()
@commands.cooldown(1, 10, commands.BucketType.user)
async def disable_nightmode(self, ctx):
if ctx.guild.member_count < 50:
view = CV2(
"Access Denied",
"Your Server Doesn't Meet My 50 Member Criteria",
)
return await ctx.send(view=view)
own = ctx.author.id == ctx.guild.owner_id
check = await self.is_extra_owner(ctx.author, ctx.guild)
if not own and not check and ctx.author.id not in self.ricky:
view = CV2(
"Access Denied",
"Only Server Owner Or Extraowner Can Run This Command.!",
)
return await ctx.send(view=view)
if (
not own
and not (ctx.guild.me.top_role.position <= ctx.author.top_role.position)
and ctx.author.id not in self.ricky
):
view = CV2(
"Access Denied",
"Only Server Owner or Extraowner Having **Higher role than me can run this command**",
)
return await ctx.send(view=view)
async with self.db.execute(
"SELECT roleId, adminPermissions FROM Nightmode WHERE guildId = ?",
(str(ctx.guild.id),),
) as cursor:
stored_roles = await cursor.fetchall()
if not stored_roles:
view = CV2(
"Error",
"Nightmode is not enabled.",
)
return await ctx.send(view=view)
async with self.db.cursor() as cursor:
for role_id, admin_permissions in stored_roles:
role = ctx.guild.get_role(int(role_id))
if role:
permissions = discord.Permissions(
administrator=bool(admin_permissions)
)
await role.edit(
permissions=permissions, reason="Nightmode DISABLED"
)
await cursor.execute(
"DELETE FROM Nightmode WHERE guildId = ? AND roleId = ?",
(str(ctx.guild.id), role_id),
)
await self.db.commit()
view = CV2(
"Success",
"Nightmode disabled! Restored Permissions For Manageable Roles.",
)
await ctx.send(view=view)

View File

@@ -0,0 +1,54 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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
from discord.ui import Button, View
class Nitro(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_message(self, message):
if self.bot.user in message.mentions and (
"nitro" in message.content.lower() or "$nitro" in message.content.lower()
):
ctx = await self.bot.get_context(message)
await self.bot.invoke(ctx)
@commands.command(name="nitro")
async def nitro(self, ctx):
embed = discord.Embed(color=0x2B2D31)
embed.add_field(
name="A WILD NITRO GIFT APPEARS?",
value="Expires in 12 hours\n\nClick the claim button for claiming Nitro",
inline=False,
)
embed.set_image(
url="https://media.tenor.com/ltVe8iMhgXcAAAAS/nitro-discord.gif"
)
claim_button = Button(
style=discord.ButtonStyle.primary,
label="Click me!",
url="https://discord.gg/codexdev",
disabled=False,
)
view = View()
view.add_item(claim_button)
await ctx.send(embed=embed, view=view)

195
bot/cogs/commands/notify.py Normal file
View File

@@ -0,0 +1,195 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 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
from utils.Tools import *
from utils.cv2 import CV2
class NotifCommands(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.db_path = "db/notify.db"
self.loop_task = self.bot.loop.create_task(self.setup_db())
async def setup_db(self):
async with aiosqlite.connect(self.db_path) as db:
await db.execute("""CREATE TABLE IF NOT EXISTS notifications (
id INTEGER PRIMARY KEY AUTOINCREMENT,
type TEXT NOT NULL UNIQUE,
role_id INTEGER NOT NULL,
channel_id INTEGER NOT NULL)""")
await db.commit()
@commands.group(invoke_without_command=True)
async def setnotif(self, ctx):
view = CV2(
"Notification Commands",
"Subcommands: twitch, youtube, list, reset",
)
await ctx.send(view=view)
@setnotif.command()
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def twitch(self, ctx, role: discord.Role, channel: discord.TextChannel):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT * FROM notifications WHERE type = ?", ("twitch",)
) as existing:
row = await existing.fetchone()
if row:
view = CV2(
"Access Denied",
"Twitch notification already set. Remove it first.",
)
await ctx.reply(view=view)
return
await db.execute(
"INSERT INTO notifications (type, role_id, channel_id) VALUES (?, ?, ?)",
("twitch", role.id, channel.id),
)
await db.commit()
view = CV2(
"Success",
f"Twitch notifications set for {role.mention} in {channel.mention}.",
)
await ctx.reply(view=view)
@setnotif.command()
@blacklist_check()
@ignore_check()
@commands.has_permissions(administrator=True)
async def youtube(self, ctx, role: discord.Role, channel: discord.TextChannel):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT * FROM notifications WHERE type = ?", ("youtube",)
) as existing:
row = await existing.fetchone()
if row:
view = CV2(
"Access Denied",
"YouTube notification already set. Remove it first.",
)
await ctx.reply(view=view)
return
await db.execute(
"INSERT INTO notifications (type, role_id, channel_id) VALUES (?, ?, ?)",
("youtube", role.id, channel.id),
)
await db.commit()
view = CV2(
"Success",
f"YouTube notifications set for {role.mention} in {channel.mention}.",
)
await ctx.reply(view=view)
@setnotif.command()
async def list(self, ctx):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute("SELECT * FROM notifications") as cursor:
rows = await cursor.fetchall()
if not rows:
view = CV2(
"Notification Settings",
"No Twitch and YouTube notification channels set.",
)
await ctx.reply(view=view)
return
lines = []
for row in rows:
notif_type = row[1].capitalize()
role = ctx.guild.get_role(row[2])
channel = ctx.guild.get_channel(row[3])
if role and channel:
lines.append(
f"**{notif_type} Notifications**\nRole: {role.mention} | Channel: {channel.mention}"
)
else:
lines.append(
f"**{notif_type} Notifications**\nRole or Channel not found"
)
view = CV2(
"Current Notification Settings",
*lines,
)
await ctx.reply(view=view)
@setnotif.command()
async def reset(self, ctx):
async with aiosqlite.connect(self.db_path) as db:
await db.execute(
"DELETE FROM notifications WHERE type IN (?, ?)", ("twitch", "youtube")
)
await db.commit()
view = CV2(
"Success",
"Twitch and YouTube notifications have been reset.",
)
await ctx.send(view=view)
@commands.Cog.listener()
async def on_presence_update(self, before, after):
streaming = next(
(
activity
for activity in after.activities
if isinstance(activity, discord.Streaming)
),
None,
)
if streaming:
stream_type = (
"twitch"
if "twitch" in streaming.url.lower()
else "youtube"
if "youtube" in streaming.url.lower()
else None
)
if stream_type:
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT role_id, channel_id FROM notifications WHERE type = ?",
(stream_type,),
) as cursor:
row = await cursor.fetchone()
if row:
role_id, channel_id = row
role = after.guild.get_role(role_id)
channel = after.guild.get_channel(channel_id)
if role and channel:
embed = discord.Embed(
title=f"{after.display_name} is now live!",
description=f"{after.mention} is now streaming on {stream_type.capitalize()}.",
color=0xFF0000,
)
embed.add_field(
name="Stream Title",
value=streaming.name,
inline=False,
)
embed.add_field(
name="Watch here", value=streaming.url, inline=False
)
await channel.send(content=role.mention, embed=embed)

722
bot/cogs/commands/np.py Normal file
View File

@@ -0,0 +1,722 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ ║
# ║ ░█▀▀░█▀█░█▀▄░█▀▀░█░█ ░█▀▄░█▀▀░█░█░█▀▀ ║
# ║ ░█░░░█░█░█░█░█▀▀░▄▀▄ ░█░█░█▀▀░▀▄▀░▀▀█ ║
# ║ ░▀▀▀░▀▀▀░▀▀░░▀▀▀░▀░▀ ░▀▀░░▀▀▀░░▀░░▀▀▀ ║
# ║ ║
# ║ © 2026 CodeX Devs — All Rights Reserved ║
# ║ ║
# ║ discord ── https://discord.gg/codexdev ║
# ║ youtube ── https://youtube.com/@CodeXDevs ║
# ║ github ── https://github.com/RayExo ║
# ║ ║
# ╚══════════════════════════════════════════════════════════════════╝
from discord.ext import commands, tasks
from discord import *
import discord
from utils.emoji import BOOST, ICONS_WARNING, INFO, MENTION, PREMIUM, TICK, TIME, TIMER_ALT1, U_ADMIN, ZDIL, ZHUMAN, ZYROXHAMMER, ZYROXSYS
import aiosqlite
from typing import Optional
from datetime import datetime, timedelta
from discord.ui import View, Button, Select
from utils.config import OWNER_IDS
from utils import Paginator, DescriptionEmbedPaginator
from utils.cv2 import CV2Embed, add_action_rows
from utils.config import *
def load_owner_ids():
return OWNER_IDS
async def is_staff(user, staff_ids):
return user.id in staff_ids
async def is_owner_or_staff(ctx):
return await is_staff(ctx.author, ctx.cog.staff) or ctx.author.id in OWNER_IDS
class TimeSelect(Select):
def __init__(self, user, db_path, author):
super().__init__(placeholder="Select the duration")
self.user = user
self.db_path = db_path
self.author = author
self.options = [
SelectOption(
label="10 Minutes", description="Trial for 10 minutes", value="10m"
),
SelectOption(
label="1 Week", description="No prefix for 1 week", value="1w"
),
SelectOption(
label="3 Weeks", description="No prefix for 3 weeks", value="3w"
),
SelectOption(
label="1 Month", description="No prefix for 1 Month", value="1m"
),
SelectOption(
label="3 Months", description="No prefix for 3 Months.", value="3m"
),
SelectOption(
label="6 Months", description="No prefix for 6 Months.", value="6m"
),
SelectOption(
label="1 Year", description="No prefix for 1 Year.", value="1y"
),
SelectOption(
label="3 Years", description="No prefix for 3 Years.", value="3y"
),
SelectOption(
label="Lifetime", description="No prefix Permanently.", value="lifetime"
),
]
async def callback(self, interaction: discord.Interaction):
if interaction.user != self.author:
return await interaction.response.send_message(
"You can't select this option.", ephemeral=True
)
duration_mapping = {
"10m": timedelta(minutes=10),
"1w": timedelta(weeks=1),
"3w": timedelta(weeks=3),
"1m": timedelta(days=30),
"3m": timedelta(days=90),
"6m": timedelta(days=180),
"1y": timedelta(days=365),
"3y": timedelta(days=365 * 3),
"lifetime": None,
}
selected_duration = self.values[0]
expiry_time = None
if selected_duration != "lifetime":
expiry_time = datetime.utcnow() + duration_mapping[selected_duration]
expiry_str = expiry_time.isoformat()
else:
expiry_str = None
async with aiosqlite.connect(self.db_path) as db:
await db.execute(
"INSERT INTO np (id, expiry_time) VALUES (?, ?)",
(self.user.id, expiry_str),
)
await db.commit()
expiry_text = (
"**Lifetime**"
if selected_duration == "lifetime"
else f"{expiry_time.strftime('%Y-%m-%d %H:%M:%S')} UTC"
)
expiry_timestamp = (
"None (Permanent)"
if selected_duration == "lifetime"
else f"<t:{int(expiry_time.timestamp())}:f>"
)
guild = interaction.client.get_guild(1401125905677553716)
if guild:
member = guild.get_member(self.user.id)
if member:
role = guild.get_role(1401134167873290311)
if role:
await member.add_roles(role, reason="No prefix added")
log_channel = interaction.client.get_channel(LOG_CHANNEL_ID) if LOG_CHANNEL_ID else None
if log_channel:
embed = CV2Embed(
title="User Added to No Prefix",
description=f"**User**: [{self.user}](https://discord.com/users/{self.user.id})\n**User Mention**: {self.user.mention}\n** ID**: {self.user.id}\n\n** Added By**: [{self.author.display_name}](https://discord.com/users/{self.author.id})\n{TIMER_ALT1}**Expiry Time**: {expiry_text}\n{ZDIL} **Timestamp**: {expiry_timestamp}\n\n{PREMIUM} **Tier**: **{self.values[0].upper()}**",
color=0xFF0000,
)
embed.set_thumbnail(
url=self.user.avatar.url
if self.user.avatar
else self.user.default_avatar.url
)
await log_channel.send(view=embed)
embed = CV2Embed(
description=f"**Added Global No Prefix**:\n{ZHUMAN} User: **{self.user.mention}**\n{MENTION} User Mention: {self.user.mention}\n{ZYROXSYS} User ID: {self.user.id}\n\n__**Additional Info**__:\n{ZYROXHAMMER} Added By: **{self.author.display_name}**\n{TIME} Expiry Time: {expiry_text}\n{BOOST} Timestamp: {expiry_timestamp}",
color=0xFF0000,
)
embed.set_author(
name="Added No Prefix",
icon_url="https://cdn.discordapp.com/icons/1166303696263585852/eeb00b2cf541438e88cdf842394c5b30.png?size=1024",
)
embed.set_footer(
text="DM will be sent to the user in case No prefix is expired."
)
await interaction.response.edit_message(view=embed)
class TimeSelectView(View):
def __init__(self, user, db_path, author):
super().__init__()
self.user = user
self.db_path = db_path
self.author = author
self.add_item(TimeSelect(user, db_path, author))
from utils.config import BotName
class NoPrefix(commands.Cog):
def __init__(self, client):
self.client = client
self.staff = set()
self.db_path = "db/np.db"
self.client.loop.create_task(self.load_staff())
self.client.loop.create_task(self.setup_database())
self.expiry_check.start()
async def setup_database(self):
async with aiosqlite.connect(self.db_path) as db:
await db.execute("""
CREATE TABLE IF NOT EXISTS np (
id INTEGER PRIMARY KEY
)
""")
async with db.execute("PRAGMA table_info(np);") as cursor:
columns = [info[1] for info in await cursor.fetchall()]
if "expiry_time" not in columns:
await db.execute("""
ALTER TABLE np ADD COLUMN expiry_time TEXT NULL;
""")
await db.execute("""
UPDATE np
SET expiry_time = NULL
WHERE expiry_time IS NULL;
""")
await db.execute("""
CREATE TABLE IF NOT EXISTS autonp (
guild_id INTEGER PRIMARY KEY
)
""")
await db.commit()
async def load_staff(self):
await self.client.wait_until_ready()
async with aiosqlite.connect(self.db_path) as db:
async with db.execute("SELECT id FROM staff") as cursor:
self.staff = {row[0] for row in await cursor.fetchall()}
@tasks.loop(minutes=10)
async def expiry_check(self):
async with aiosqlite.connect(self.db_path) as db:
now = datetime.utcnow().isoformat()
async with db.execute(
"SELECT id FROM np WHERE expiry_time IS NOT NULL AND expiry_time <= ?",
(now,),
) as cursor:
expired_users = [row[0] for row in await cursor.fetchall()]
if expired_users:
async with db.execute(
"DELETE FROM np WHERE id IN ({})".format(
",".join("?" * len(expired_users))
),
expired_users,
):
await db.commit()
for user_id in expired_users:
user = self.client.get_user(user_id)
if user:
log_channel = self.client.get_channel(LOG_CHANNEL_ID) if LOG_CHANNEL_ID else None
if log_channel:
embed_log = CV2Embed(
title="No Prefix Expired",
description=(
f"**User**: [{user}](https://discord.com/users/{user.id})\n"
f"**User Mention**: {user.mention}\n"
f"**ID**: {user.id}\n\n"
f"**Removed By**: **{BotName}**\n"
),
color=0xFF0000,
)
embed_log.set_thumbnail(
url=user.display_avatar.url
if user.avatar
else user.default_avatar.url
)
embed_log.set_footer(text="No Prefix Removal Log")
await log_channel.send(view=embed_log)
bot = self.client
guild = bot.get_guild(1401125905677553716)
if guild:
member = guild.get_member(user.id)
if member:
role = guild.get_role(1401134167873290311)
if role in member.roles:
await member.remove_roles(role)
embed = CV2Embed(
description=f"{ICONS_WARNING} Your No Prefix status has **Expired**. You will now require the prefix to use commands.",
color=0xFF0000,
)
embed.set_author(
name="No Prefix Expired",
icon_url=user.avatar.url
if user.avatar
else user.default_avatar.url,
)
embed.set_footer(
text=f"{BRAND_NAME} - No Prefix, Join support to regain access."
)
support = Button(
label="Support",
style=discord.ButtonStyle.link,
url=f"https://discord.gg/codexdev",
)
view = View()
view.add_item(support)
try:
add_action_rows(embed, view.children)
await user.send(f"{user.mention}", view=embed)
except discord.Forbidden:
pass
except discord.HTTPException:
pass
@expiry_check.before_loop
async def before_expiry_check(self):
await self.client.wait_until_ready()
@commands.group(
name="np",
help="Allows you to add someone to the no-prefix list (owner-only command)",
)
@commands.check(is_owner_or_staff)
async def _np(self, ctx):
if ctx.invoked_subcommand is None:
await ctx.send_help(ctx.command)
@_np.command(name="list", help="List of no-prefix users")
@commands.check(is_owner_or_staff)
async def np_list(self, ctx):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute("SELECT id FROM np") as cursor:
ids = [row[0] for row in await cursor.fetchall()]
if not ids:
await ctx.reply(
f"No users in the no-prefix list.", mention_author=False
)
return
entries = [
f"`#{no + 1}` [Profile URL](https://discord.com/users/{mem}) (ID: {mem})"
for no, mem in enumerate(ids, start=0)
]
paginator = Paginator(
source=DescriptionEmbedPaginator(
entries=entries,
title=f"No Prefix Users [{len(ids)}]",
description="",
per_page=10,
color=0xFF0000,
),
ctx=ctx,
)
await paginator.paginate()
@_np.command(name="add", help="Add user to no-prefix with time options")
@commands.check(is_owner_or_staff)
async def np_add(self, ctx, user: discord.User):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT id FROM np WHERE id = ?", (user.id,)
) as cursor:
result = await cursor.fetchone()
if result:
embed = CV2Embed(
description=f"**{user}** is Already in No prefix list\n\n **Requested By**: [{ctx.author.display_name}](https://discord.com/users/{ctx.author.id})\n",
color=0xFF0000,
)
embed.set_author(name="Error")
await ctx.reply(view=embed)
return
view = TimeSelectView(user, self.db_path, ctx.author)
from discord.ui import ActionRow
embed = CV2Embed(
title="Select No Prefix Duration",
description="**Choose the duration for how long no-prefix should be enabled for this user:**",
color=0xFF0000,
)
for item in view.children:
embed.children[0].add_item(ActionRow(item))
await ctx.reply(view=embed)
@_np.command(name="remove", help="Remove user from no-prefix")
@commands.check(is_owner_or_staff)
async def np_remove(self, ctx, user: discord.User):
async with aiosqlite.connect("db/np.db") as db:
async with db.execute(
"SELECT id FROM np WHERE id = ?", (user.id,)
) as cursor:
result = await cursor.fetchone()
if not result:
embed = CV2Embed(
description=f"**{user}** is Not in the No Prefix list\n\n{U_ADMIN} **Requested By**: [{ctx.author.display_name}](https://discord.com/users/{ctx.author.id})\n",
color=0xFF0000,
)
embed.set_author(name="Error")
await ctx.reply(view=embed)
return
await db.execute("DELETE FROM np WHERE id = ?", (user.id,))
await db.commit()
guild = ctx.bot.get_guild(1401125905677553716)
if guild:
member = guild.get_member(user.id)
if member:
role = guild.get_role(1401134167873290311)
if role in member.roles:
await member.remove_roles(role)
embed = CV2Embed(
description=(
f"**User**: [{user}](https://discord.com/users/{user.id})\n"
f"**User Mention**: {user.mention}\n"
f"** ID**: {user.id}\n\n"
f"** Removed By**: **{BotName}**\n"
),
color=0xFF0000,
)
embed.set_author(name="Removed No Prefix")
await ctx.reply(view=embed)
log_channel = ctx.bot.get_channel(LOG_CHANNEL_ID) if LOG_CHANNEL_ID else None
if log_channel:
embed_log = CV2Embed(
title="No Prefix Removed",
description=(
f"**User**: [{user}](https://discord.com/users/{user.id})\n"
f"**User Mention**: {user.mention}\n"
f"** ID**: {user.id}\n\n"
f"**Removed By**: **{BotName}**\n"
),
color=0xFF0000,
)
embed_log.set_thumbnail(
url=user.display_avatar.url if user.avatar else user.default_avatar.url
)
embed_log.set_footer(text="No Prefix Removal Log")
await log_channel.send(" ".join(f"<@{oid}>" for oid in OWNER_IDS), view=embed_log)
@_np.command(
name="status", help="Check if a user is in the No Prefix list and show details."
)
@commands.check(is_owner_or_staff)
async def np_status(self, ctx, user: discord.User):
async with aiosqlite.connect("db/np.db") as db:
async with db.execute(
"SELECT id, expiry_time FROM np WHERE id = ?", (user.id,)
) as cursor:
result = await cursor.fetchone()
if not result:
embed = CV2Embed(
title="No Prefix Status",
description=f"**{user}** is Not in the No Prefix list\n\n"
f"**Requested By**: "
f"[{ctx.author.display_name}](https://discord.com/users/{ctx.author.id})\n",
color=0xFF0000,
)
await ctx.reply(view=embed)
return
user_id, expires = result
if expires and expires != "Null":
expire_time = datetime.fromisoformat(expires)
expire_timestamp = f"<t:{int(expire_time.timestamp())}:F>"
else:
expire_time = "Lifetime"
expire_timestamp = "Lifetime"
embed = CV2Embed(
title="No Prefix Status",
description=(
f"**User**: [{user}](https://discord.com/users/{user.id})\n"
f"**User ID**: {user.id}\n\n"
f"{TIME} Expiry: {expire_time} ({expire_timestamp})"
),
color=0xFF0000,
)
embed.set_thumbnail(
url=user.display_avatar.url if user.avatar else user.default_avatar.url
)
await ctx.reply(view=embed)
@commands.group(name="autonp", help="Manage auto no-prefix for partner guilds.")
@commands.is_owner()
async def autonp(self, ctx):
if ctx.invoked_subcommand is None:
await ctx.send_help(ctx.command)
@autonp.group(name="guild", help="Manage partner guilds for auto no-prefix.")
async def autonp_guild(self, ctx):
if ctx.invoked_subcommand is None:
await ctx.send_help(ctx.command)
@autonp_guild.command(name="add", help="Add a guild to auto no-prefix.")
async def add_guild(self, ctx, guild_id: int):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT 1 FROM autonp WHERE guild_id = ?", (guild_id,)
) as cursor:
if await cursor.fetchone():
await ctx.reply("Guild is already added.")
return
await db.execute("INSERT INTO autonp (guild_id) VALUES (?)", (guild_id,))
await db.commit()
await ctx.reply(f"Guild {guild_id} added to auto no-prefix.")
@autonp_guild.command(name="remove", help="Remove a guild from auto no-prefix.")
async def remove_guild(self, ctx, guild_id: int):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT 1 FROM autonp WHERE guild_id = ?", (guild_id,)
) as cursor:
if not await cursor.fetchone():
await ctx.reply("Guild is not in auto no-prefix.")
return
await db.execute("DELETE FROM autonp WHERE guild_id = ?", (guild_id,))
await db.commit()
await ctx.reply(f"Guild {guild_id} removed from auto no-prefix.")
@autonp_guild.command(name="list", help="List all guilds with auto no-prefix.")
@commands.check(is_owner_or_staff)
async def list_guilds(self, ctx):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute("SELECT guild_id FROM autonp") as cursor:
guilds = [row[0] for row in await cursor.fetchall()]
if not guilds:
await ctx.reply(
"No guilds in auto no-prefix.", mention_author=False
)
return
await ctx.reply(
f"Guilds in auto no-prefix:\n" + "\n".join(str(g) for g in guilds),
mention_author=False,
)
async def is_user_in_np(self, user_id):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT 1 FROM np WHERE id = ?", (user_id,)
) as cursor:
return await cursor.fetchone() is not None
@commands.Cog.listener()
async def on_member_update(self, before, after):
if before.premium_since is None and after.premium_since is not None:
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT 1 FROM autonp WHERE guild_id = ?", (after.guild.id,)
) as cursor:
if not await cursor.fetchone():
return
if not await self.is_user_in_np(after.id):
await self.add_np(after, timedelta(days=60))
log_channel = self.client.get_channel(1406566123234787378)
embed = CV2Embed(
title="Added No prefix due to Boosting Partner Server",
description=f"**User**: **[{after}](https://discord.com/users/{after.id})** (ID: {after.id})\n**Server**: {after.guild.name}",
color=0xFF0000,
)
message = await log_channel.send(" ".join(f"<@{oid}>" for oid in OWNER_IDS), view=embed)
await message.publish()
elif before.premium_since is not None and after.premium_since is None:
await self.handle_boost_removal(after)
# @commands.Cog.listener()
# async def on_member_remove(self, member):
# await self.handle_boost_removal(member)
async def handle_boost_removal(self, user):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT 1 FROM autonp WHERE guild_id = ?", (user.guild.id,)
) as cursor:
if not await cursor.fetchone():
return
if await self.is_user_in_np(user.id):
await self.remove_np(user)
log_channel = self.client.get_channel(1406566257070964756)
embed = CV2Embed(
title="Removed No prefix due to Unboosting Partner Server",
description=f"**User**: **[{user}](https://discord.com/users/{user.id})** (ID: {user.id})\n**Server**: {user.guild.name}",
color=0xFF0000,
)
message = await log_channel.send(" ".join(f"<@{oid}>" for oid in OWNER_IDS), view=embed)
await message.publish()
async def add_np(self, user, duration):
expiry_time = datetime.utcnow() + duration
async with aiosqlite.connect(self.db_path) as db:
await db.execute(
"INSERT INTO np (id, expiry_time) VALUES (?, ?)",
(user.id, expiry_time.isoformat()),
)
await db.commit()
embed = CV2Embed(
title="Congratulations you got 2 months No Prefix!",
description=f"You've been credited 2 months of global No Prefix for boosting our Partnered Servers. You can now use my commands without prefix. If you wish to remove it, please reach out [Support Server](https://discord.gg/codexdev).",
color=0xFF0000,
)
try:
await user.send(view=embed)
except discord.Forbidden:
pass
except discord.HTTPException:
pass
guild = self.client.get_guild(1401125905677553716)
if guild:
member = guild.get_member(user.id)
if member is not None:
role = guild.get_role(1401134167873290311)
if role:
await member.add_roles(role)
async def remove_np(self, user):
async with aiosqlite.connect(self.db_path) as db:
async with db.execute(
"SELECT expiry_time FROM np WHERE id = ?", (user.id,)
) as cursor:
row = await cursor.fetchone()
if row is None or row[0] is None:
return
await db.execute("DELETE FROM np WHERE id = ?", (user.id,))
await db.commit()
embed = CV2Embed(
title=f"{ICONS_WARNING} Global No Prefix Expired",
description=f"Hey {user.mention}, your global no prefix has expired!\n\n__**Reason:**__ Unboosting our partnered Server.\nIf you think this is a mistake then please reach out [Support Server](https://discord.gg/codexdev).",
color=0xFF0000,
)
try:
await user.send(view=embed)
except discord.Forbidden:
pass
except discord.HTTPException:
pass
guild = self.client.get_guild(1401125905677553716)
if guild:
member = guild.get_member(user.id)
if member is not None:
role = guild.get_role(1401134167873290311)
if role and role in member.roles:
await member.remove_roles(role)
@_np.command(name="reset", help="Reset/clear all users from the no-prefix list")
@commands.is_owner()
async def np_reset(self, ctx):
# Confirmation message
embed = CV2Embed(
title="Confirm Reset",
description="Are you sure you want to remove **ALL** users from the no-prefix list? This action cannot be undone.",
color=0xFF0000,
)
# Create confirmation buttons
yes_button = Button(label="Yes", style=discord.ButtonStyle.danger)
no_button = Button(label="No", style=discord.ButtonStyle.secondary)
view = View()
view.add_item(yes_button)
view.add_item(no_button)
# Define button callbacks
async def yes_callback(interaction):
if interaction.user != ctx.author:
return await interaction.response.send_message(
"This interaction is not for you.", ephemeral=True
)
# Remove all users from no-prefix list
async with aiosqlite.connect(self.db_path) as db:
# Get count of users before deletion
async with db.execute("SELECT COUNT(*) FROM np") as cursor:
count = (await cursor.fetchone())[0]
# Delete all entries
await db.execute("DELETE FROM np")
await db.commit()
# Remove roles from all members in the main guild
guild = self.client.get_guild(1401125905677553716)
if guild:
role = guild.get_role(1401134167873290311)
if role:
members_with_role = [
member for member in guild.members if role in member.roles
]
for member in members_with_role:
try:
await member.remove_roles(
role, reason="Global no-prefix reset"
)
except discord.HTTPException:
pass
# Send success message
success_embed = CV2Embed(
title=f"{TICK} No-Prefix Reset Complete",
description=f"Successfully removed {count} users from the no-prefix list.",
color=0xFF0000,
)
await interaction.response.edit_message(view=success_embed)
# Log the action
log_channel = self.client.get_channel(LOG_CHANNEL_ID) if LOG_CHANNEL_ID else None
if log_channel:
log_embed = CV2Embed(
title="No-Prefix List Reset",
description=f"**Reset By**: [{ctx.author.display_name}](https://discord.com/users/{ctx.author.id})\n{INFO} Users Removed: {count}",
color=0xFF0000,
)
log_embed.set_footer(text="No Prefix Reset Log")
await log_channel.send(view=log_embed)
async def no_callback(interaction):
if interaction.user != ctx.author:
return await interaction.response.send_message(
"This interaction is not for you.", ephemeral=True
)
cancel_embed = CV2Embed(
title="Reset Cancelled",
description="No changes have been made to the no-prefix list.",
color=0xFF0000,
)
await interaction.response.edit_message(view=cancel_embed)
yes_button.callback = yes_callback
no_button.callback = no_callback
add_action_rows(embed, view.children)
await ctx.reply(view=embed)

Some files were not shown because too many files have changed in this diff Show More