Basic utils for models, added some stuff to the bot
This commit is contained in:
@@ -78,6 +78,7 @@ class Geeksbot(commands.Bot):
|
||||
self.config_dir = 'geeksbot/config/'
|
||||
self.config_file = 'bot_config.json'
|
||||
self.extension_dir = 'exts'
|
||||
self.api_token = os.environ['API_TOKEN']
|
||||
self.aio_session = aiohttp.ClientSession(loop=self.loop)
|
||||
with open(f'{self.config_dir}{self.config_file}') as f:
|
||||
self.bot_config = json.load(f)
|
||||
@@ -90,6 +91,16 @@ class Geeksbot(commands.Bot):
|
||||
self.git_url = 'https://github.com/dustinpianalto/geeksbot_v2'
|
||||
self.load_default_extensions()
|
||||
|
||||
self.book_emojis = {
|
||||
'unlock': '🔓',
|
||||
'start': '⏮',
|
||||
'back': '◀',
|
||||
'hash': '#\N{COMBINING ENCLOSING KEYCAP}',
|
||||
'forward': '▶',
|
||||
'end': '⏭',
|
||||
'close': '🇽',
|
||||
}
|
||||
|
||||
async def load_ext(self, mod):
|
||||
self.load_extension(f'geeksbot.{self.extension_dir}.{mod}')
|
||||
logger.info(f'Extension Loaded: {mod}')
|
||||
|
||||
@@ -64,9 +64,9 @@ class Exec(commands.Cog):
|
||||
ret = await func()
|
||||
except Exception:
|
||||
pag.add(stdout.getvalue())
|
||||
pag.add(traceback.format_exc())
|
||||
for page in pag.pages():
|
||||
await ctx.send(page)
|
||||
pag.add(f'\n\uFFF8{traceback.format_exc()}')
|
||||
book = Book(pag, (None, ctx.channel, ctx.bot, ctx.message))
|
||||
await book.create_book()
|
||||
else:
|
||||
value = stdout.getvalue()
|
||||
# noinspection PyBroadException
|
||||
@@ -76,10 +76,10 @@ class Exec(commands.Cog):
|
||||
pass
|
||||
value = format_output(value)
|
||||
pag.add(value)
|
||||
pag.add(f'\nReturned: {ret}')
|
||||
pag.add(f'\n\uFFF8Returned: {ret}')
|
||||
self._last_result = ret
|
||||
for page in pag.pages():
|
||||
await ctx.send(page)
|
||||
book = Book(pag, (None, ctx.channel, ctx.bot, ctx.message))
|
||||
await book.create_book()
|
||||
|
||||
@commands.command(hidden=True)
|
||||
async def repl(self, ctx):
|
||||
@@ -161,8 +161,8 @@ class Exec(commands.Cog):
|
||||
body = self.cleanup_code(body)
|
||||
pag = Paginator(self.bot)
|
||||
pag.add(await asyncio.wait_for(self.bot.loop.create_task(run_command(body)), 120))
|
||||
for page in pag.pages():
|
||||
await ctx.send(page)
|
||||
book = Book(pag, (None, ctx.channel, ctx.bot, ctx.message))
|
||||
await book.create_book()
|
||||
await ctx.message.add_reaction('✅')
|
||||
except asyncio.TimeoutError:
|
||||
await ctx.send(f"Command did not complete in the time allowed.")
|
||||
|
||||
@@ -156,7 +156,7 @@ class Paginator:
|
||||
|
||||
if not self._embed:
|
||||
for part in [str(p) for p in self._parts]:
|
||||
if part == self._page_break:
|
||||
if part.startswith(self._page_break):
|
||||
close_page()
|
||||
|
||||
new_chars = len(_page) + len(part)
|
||||
@@ -185,9 +185,8 @@ class Paginator:
|
||||
open_field('\uFFF0')
|
||||
|
||||
for part in [str(p) for p in self._parts]:
|
||||
if part.strip() == self._page_break:
|
||||
if part.strip().startswith(self._page_break):
|
||||
close_page()
|
||||
continue
|
||||
elif part == self._field_break:
|
||||
if len(_fields) + 1 < 25:
|
||||
close_field(next_name='\uFFF0')
|
||||
|
||||
Reference in New Issue
Block a user