86 lines
2.5 KiB
Python
86 lines
2.5 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 db import create_db_pool
|
|
|
|
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)
|
|
|
|
async def cbsend(self, content: Optional[str] = None, lang: Optional[str] = "py"):
|
|
"""
|
|
send content in a paginated codeblock
|
|
"""
|
|
codeblock = "```" + lang + "\n{}" + "\n```"
|
|
if not len(content) > 1900:
|
|
await self.send(content=codeblock.format(content))
|
|
return
|
|
pages = []
|
|
string = ""
|
|
for p in content.splitlines():
|
|
if not len(string) > 1900:
|
|
string += p + '\n'
|
|
else:
|
|
pages.append(codeblock.format(string))
|
|
string = ""
|
|
string += p
|
|
if string:
|
|
pages.append(string)
|
|
await self.paginate(pages=pages, pagetype="text")
|
|
|
|
|
|
|
|
class Brahmos(Bot):
|
|
"""
|
|
Custom bot class
|
|
"""
|
|
|
|
def __init__(self, **kwargs):
|
|
kwargs["command_prefix"] = ["fr ", "frog "]
|
|
super().__init__(**kwargs, help_command=None)
|
|
self.exts = [i[:-3] for i in os.listdir("exts") if i.endswith(".py")]
|
|
self.name = "brahmos"
|
|
self.db_pool = None
|
|
|
|
async def is_owner(self, user: discord.user):
|
|
if user.id in OWNER:
|
|
return True
|
|
return False
|
|
|
|
async def setup_hook(self):
|
|
if self.db_pool is None:
|
|
self.db_pool = await create_db_pool()
|
|
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")]
|