first commit

This commit is contained in:
RayExo
2026-07-12 15:16:07 +05:30
commit 2289301f26
915 changed files with 69400 additions and 0 deletions

14
bot/core/Cog.py Normal file
View File

@@ -0,0 +1,14 @@
from __future__ import annotations
from discord.ext import commands
__all__ = ("Cog",)
class Cog(commands.Cog):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
def __str__(self) -> str:
return "{0.__class__.__name__}".format(self)

76
bot/core/Context.py Normal file
View File

@@ -0,0 +1,76 @@
from __future__ import annotations
from discord.ext import commands
import discord
import functools
from typing import Optional, Any
import asyncio
__all__ = ("Context", )
class Context(commands.Context):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
def __repr__(self):
return "<core.Context>"
@property
async def session(self):
return self.bot.session
@discord.utils.cached_property
def replied_reference(self) -> Optional[discord.Message]:
ref = self.message.reference
if ref and isinstance(ref.resolved, discord.Message):
return ref.resolved.to_reference()
return None
def with_type(func):
@functools.wraps(func)
async def wrapped(self, *args, **kwargs):
context = args[0] if isinstance(args[0],
commands.Context) else args[1]
try:
async with context.typing():
await func(*args, **kwargs)
except discord.Forbidden:
await func(*args, **kwargs)
return wrapped
async def show_help(self, command: str = None) -> Any:
cmd = self.bot.get_command('help')
command = command or self.command.qualified_name
await self.invoke(cmd, command=command)
async def send(self,
content: Optional[str] = None,
**kwargs) -> Optional[discord.Message]:
if not (self.channel.permissions_for(self.me)).send_messages:
try:
await self.author.send(
"bot dont have perms to send msg in that channel")
except discord.Forbidden:
pass
return
return await super().send(content, **kwargs)
async def reply(self,
content: Optional[str] = None,
**kwargs) -> Optional[discord.Message]:
if not (self.channel.permissions_for(self.me)).send_messages:
try:
await self.author.send(
"bot dont have perms to send msg in that channel")
except discord.Forbidden:
pass
return
return await super().reply(content, **kwargs)
async def release(self, delay: Optional[int] = None) -> None:
delay = delay or 0
await asyncio.sleep(delay)

3
bot/core/__init__.py Normal file
View File

@@ -0,0 +1,3 @@
from .zyrox import zyrox
from .Context import Context
from .Cog import Cog

132
bot/core/zyrox.py Normal file
View File

@@ -0,0 +1,132 @@
from __future__ import annotations
from discord.ext import commands, tasks
import discord
import aiohttp
import json
import jishaku
import asyncio
import typing
from typing import List
import aiosqlite
from utils.config import OWNER_IDS, BotName
from utils import getConfig, updateConfig
from .Context import Context
from colorama import Fore, Style, init
import importlib
import inspect
init(autoreset=True)
# Corrected the extensions list
extensions: List[str] = [
"cogs"
]
class zyrox(commands.AutoShardedBot):
def __init__(self, *arg, **kwargs):
intents = discord.Intents.all()
intents.presences = True
intents.members = True
super().__init__(command_prefix=self.get_prefix,
case_insensitive=True,
intents=intents,
# The status is already set to Do Not Disturb here
status=discord.Status.do_not_disturb,
strip_after_prefix=True,
owner_ids=OWNER_IDS,
allowed_mentions=discord.AllowedMentions(
everyone=False, replied_user=False, roles=False),
sync_commands_debug=True,
sync_commands=True,
shard_count=1)
self.status_index = 0
self.status_list = []
async def setup_hook(self):
await self.load_extensions()
self.status_task.start()
async def load_extensions(self):
for extension in extensions:
try:
await self.load_extension(extension)
print(Fore.GREEN + Style.BRIGHT + f"Loaded extension: {extension}")
except Exception as e:
print(f"{Fore.RED}{Style.BRIGHT}Failed to load extension {extension}. {e}")
print(Fore.GREEN + Style.BRIGHT + "*" * 20)
@tasks.loop(seconds=30)
async def status_task(self):
await self.wait_until_ready()
if not self.guilds:
return
guild = self.guilds[0] # Use first available guild for prefix
try:
config = await getConfig(guild.id)
prefix = config.get("prefix", ">")
except:
prefix = ">"
user_count = sum(g.member_count or 0 for g in self.guilds)
guild_count = len(self.guilds)
self.status_list = [
(discord.ActivityType.playing, f"{prefix}help | Security in your Server"),
(discord.ActivityType.watching, f"{user_count} users"),
(discord.ActivityType.watching, f"{guild_count} servers"),
(discord.ActivityType.listening, "Killing Nukers"),
(discord.ActivityType.playing, f"Protector {BotName}"),
]
current = self.status_list[self.status_index % len(self.status_list)]
# This task only changes the activity, not the online status (dnd, idle, etc.)
await self.change_presence(activity=discord.Activity(type=current[0], name=current[1]))
self.status_index += 1
async def send_raw(self, channel_id: int, content: str, **kwargs) -> typing.Optional[discord.Message]:
await self.http.send_message(channel_id, content, **kwargs)
async def invoke_help_command(self, ctx: Context) -> None:
return await ctx.send_help(ctx.command)
async def fetch_message_by_channel(self, channel: discord.TextChannel, messageID: int) -> typing.Optional[discord.Message]:
async for msg in channel.history(limit=1, before=discord.Object(messageID + 1), after=discord.Object(messageID - 1)):
return msg
async def get_prefix(self, message: discord.Message):
if message.guild:
guild_id = message.guild.id
async with aiosqlite.connect('db/np.db') as db:
async with db.execute("SELECT id FROM np WHERE id = ?", (message.author.id,)) as cursor:
row = await cursor.fetchone()
data = await getConfig(guild_id)
prefix = data["prefix"]
if row:
return commands.when_mentioned_or(prefix, '')(self, message)
else:
return commands.when_mentioned_or(prefix)(self, message)
else:
async with aiosqlite.connect('db/np.db') as db:
async with db.execute("SELECT id FROM np WHERE id = ?", (message.author.id,)) as cursor:
row = await cursor.fetchone()
if row:
return commands.when_mentioned_or('?', '')(self, message)
else:
return commands.when_mentioned_or('')(self, message)
async def on_message_edit(self, before, after):
ctx: Context = await self.get_context(after, cls=Context)
if before.content != after.content:
if after.guild is None or after.author.bot:
return
if ctx.command is None:
return
if type(ctx.channel) == "public_thread":
return
await self.invoke(ctx)
def setup_bot():
intents = discord.Intents.all()
bot = zyrox(intents=intents)
return bot