Files
brahmos/botclass.py
T
2024-03-08 23:20:27 +05:30

59 lines
1.6 KiB
Python

import base64
import json
import os
from typing import List, Literal, Optional, Union
import aiohttp
import discord
import jishaku
from discord.ext.commands import Bot, Context
from utils.paginator import Paginator, WebhookPaginator
OWNER = json.load(open("store/cfg.json"))["ReplOwners"]
class CustomCtx(Context):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.Paginator = Paginator
self.WebhookPaginator = WebhookPaginator
self.session = aiohttp.ClientSession(loop=self.bot.loop)
async def paginate(
self,
pages: List[discord.Embed | str],
pagetype: Optional[Literal["embed", "text"]] = "embed",
**kwargs,
):
await self.Paginator(pages=pages, pagetype=pagetype).start(ctx=self, **kwargs)
class Brahmos(Bot):
"""
Custom bot class
"""
def __init__(self, **kwargs):
kwargs["command_prefix"] = ["fr "]
super().__init__(**kwargs, help_command=None)
self.exts = [i[:-3] for i in os.listdir("exts") if i.endswith(".py")]
self.name = "brahmos"
async def is_owner(self, user: discord.user):
if user.id in OWNER:
return True
return False
async def setup_hook(self):
print(f"logged in as: {self.user.name}")
await self.load_extension("jishaku")
for ext in self.exts:
await self.load_extension(f"exts.{ext}")
async def get_context(self, message, *, cls=CustomCtx):
return await super().get_context(message, cls=cls)
def update_exts(self):
self.exts = [i[:-3] for i in os.listdir("exts") if i.endswith(".py")]