Merge remote-tracking branch 'origin/development' into development
This commit is contained in:
commit
3f33154606
@ -193,7 +193,7 @@ class Admin:
|
||||
@commands.command()
|
||||
@commands.is_owner()
|
||||
async def view_code(self, ctx, code_name):
|
||||
pag = utils.Paginator(prefix='```py', suffix='```')
|
||||
pag = utils.Paginator(self.bot, prefix='```py', suffix='```')
|
||||
pag.add(inspect.getsource(self.bot.get_command(code_name).callback))
|
||||
for page in pag.pages():
|
||||
await ctx.send(page)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
import logging
|
||||
from src.imports.utils import Paginator, run_command
|
||||
from src.imports.utils import Paginator, run_command, Book
|
||||
import asyncio
|
||||
|
||||
owner_id = 351794468870946827
|
||||
@ -29,22 +29,21 @@ class Git:
|
||||
@git.command()
|
||||
@commands.is_owner()
|
||||
async def pull(self, ctx):
|
||||
pag = Paginator(max_line_length=60, max_lines=30, max_chars=1014)
|
||||
em = discord.Embed(style='rich',
|
||||
title=f'Git Pull',
|
||||
color=embed_color)
|
||||
em.set_thumbnail(url=f'{ctx.guild.me.avatar_url}')
|
||||
result = await asyncio.wait_for(self.bot.loop.create_task(run_command('git fetch --all')), 120) + '\n'
|
||||
result += await asyncio.wait_for(self.bot.loop.create_task(run_command('git reset --hard '
|
||||
pag = Paginator(self.bot, max_line_length=44, embed=True)
|
||||
pag.set_embed_meta(title='Git Pull',
|
||||
color=self.bot.embed_color,
|
||||
thumbnail=f'{ctx.guild.me.avatar_url}')
|
||||
pag.add('\uFFF6' + await asyncio.wait_for(self.bot.loop.create_task(run_command('git fetch --all')), 120))
|
||||
pag.add(await asyncio.wait_for(self.bot.loop.create_task(run_command('git reset --hard '
|
||||
'origin/$(git '
|
||||
'rev-parse --symbolic-full-name'
|
||||
' --abbrev-ref HEAD)')), 120) + '\n\n'
|
||||
result += await asyncio.wait_for(self.bot.loop.create_task(run_command('git show --stat | '
|
||||
'sed "s/.*@.*[.].*/ /g"')), 10)
|
||||
pag.add(result)
|
||||
for page in pag.pages():
|
||||
em.add_field(name='', value=f'{page}')
|
||||
await ctx.send(embed=em)
|
||||
' --abbrev-ref HEAD)')), 120))
|
||||
pag.add('\uFFF7\n\uFFF8')
|
||||
pag.add(await asyncio.wait_for(self.bot.loop.create_task(run_command('git show --stat | '
|
||||
'sed "s/.*@.*[.].*/ /g"')), 10))
|
||||
msg = await ctx.send('Starting Book')
|
||||
book = Book(pag, (msg, ctx.channel, self.bot, ctx.message))
|
||||
await book.create_book()
|
||||
|
||||
@git.command()
|
||||
@commands.is_owner()
|
||||
|
||||
@ -141,7 +141,7 @@ class Repl:
|
||||
fmt = '{}'.format(value)
|
||||
try:
|
||||
if fmt is not None:
|
||||
pag = Paginator()
|
||||
pag = Paginator(self.bot)
|
||||
pag.add(fmt)
|
||||
for page in pag.pages():
|
||||
await response.channel.send(page)
|
||||
@ -157,7 +157,7 @@ class Repl:
|
||||
return
|
||||
try:
|
||||
body = self.cleanup_code(body)
|
||||
pag = Paginator()
|
||||
pag = Paginator(self.bot)
|
||||
pag.add(await asyncio.wait_for(self.bot.loop.create_task(run_command(body)), 10))
|
||||
for page in pag.pages():
|
||||
await ctx.send(page)
|
||||
|
||||
@ -580,15 +580,16 @@ class Utils:
|
||||
async def google_search(self, ctx, *, search):
|
||||
"""WIP Search Google for the given string"""
|
||||
res = self.bot.gcs_service.cse().list(q=search, cx=self.bot.bot_secrets['cx']).execute()
|
||||
results = res['items'][:4]
|
||||
em = discord.Embed()
|
||||
em.title = f'Google Search'
|
||||
em.description = f'Top 4 results for "{search}"'
|
||||
em.colour = embed_color
|
||||
# TODO Fix layout of Results
|
||||
results = res['items']
|
||||
pag = utils.Paginator(self.bot, max_line_length=100, embed=True)
|
||||
pag.set_embed_meta(title='Google Search', description=f'Top results for "{search}"', color=self.bot.embed_color)
|
||||
for result in results:
|
||||
em.add_field(name=f'{result["title"]}', value=f'{result["snippet"]}\n{result["link"]}')
|
||||
await ctx.send(embed=em)
|
||||
pag.add(f'\uFFF6{result["title"]}\n{result["link"]}', keep_intact=True)
|
||||
pag.add(f'{result["snippet"]}')
|
||||
pag.add('\uFFF7\n\uFFF8')
|
||||
msg = await ctx.send('Starting Book')
|
||||
book = utils.Book(pag, (msg, ctx.channel, self.bot, ctx.message))
|
||||
await book.create_book()
|
||||
|
||||
@commands.command(hidden=True, name='sheets')
|
||||
async def google_sheets(self, ctx, member: discord.Member):
|
||||
|
||||
@ -6,7 +6,7 @@ owner_id = 351794468870946827
|
||||
|
||||
|
||||
async def check_admin_role(bot, ctx, member):
|
||||
admin_roles = json.loads(await bot.db_concon.fetchval(f"select admin_roles from guild_config where guild_id = $1",
|
||||
admin_roles = json.loads(await bot.db_con.fetchval(f"select admin_roles from guild_config where guild_id = $1",
|
||||
ctx.guild.id))
|
||||
for role in admin_roles:
|
||||
if discord.utils.get(ctx.guild.roles, id=admin_roles[role]) in member.roles:
|
||||
@ -15,7 +15,7 @@ async def check_admin_role(bot, ctx, member):
|
||||
|
||||
|
||||
async def check_rcon_role(bot, ctx, member):
|
||||
rcon_admin_roles = json.loads(await bot.db_concon.fetchval("select rcon_admin_roles from guild_config "
|
||||
rcon_admin_roles = json.loads(await bot.db_con.fetchval("select rcon_admin_roles from guild_config "
|
||||
"where guild_id = $1", ctx.guild.id))
|
||||
for role in rcon_admin_roles:
|
||||
if discord.utils.get(ctx.guild.roles, id=rcon_admin_roles[role]) in member.roles:
|
||||
@ -24,7 +24,7 @@ async def check_rcon_role(bot, ctx, member):
|
||||
|
||||
|
||||
async def is_admin(bot, ctx):
|
||||
admin_roles = json.loads(await bot.db_concon.fetchval("select admin_roles from guild_config where guild_id = $1",
|
||||
admin_roles = json.loads(await bot.db_con.fetchval("select admin_roles from guild_config where guild_id = $1",
|
||||
ctx.guild.id))
|
||||
for role in admin_roles:
|
||||
if discord.utils.get(ctx.guild.roles, id=admin_roles[role]) in ctx.message.author.roles:
|
||||
@ -39,7 +39,7 @@ async def is_guild_owner(ctx):
|
||||
|
||||
|
||||
async def is_rcon_admin(bot, ctx):
|
||||
rcon_admin_roles = json.loads(await bot.db_concon.fetchval("select rcon_admin_roles from guild_config "
|
||||
rcon_admin_roles = json.loads(await bot.db_con.fetchval("select rcon_admin_roles from guild_config "
|
||||
"where guild_id = $1", ctx.guild.id))
|
||||
for role in rcon_admin_roles:
|
||||
if discord.utils.get(ctx.guild.roles, id=rcon_admin_roles[role]) in ctx.message.author.roles:
|
||||
|
||||
@ -128,9 +128,16 @@ class Paginator:
|
||||
self._inline_char = inline_char
|
||||
self._embed_title = ''
|
||||
self._embed_description = ''
|
||||
self._embed_color = None
|
||||
self._embed_thumbnail = None
|
||||
self._embed_url = None
|
||||
self._bot = bot
|
||||
|
||||
def set_embed_meta(self, title: str='\uFFF0', description: str='\uFFF0'):
|
||||
def set_embed_meta(self, title: str='\uFFF0',
|
||||
description: str='\uFFF0',
|
||||
color: discord.Colour=None,
|
||||
thumbnail: str=None,
|
||||
url: str=None):
|
||||
if len(title) <= self._max_field_name:
|
||||
self._embed_title = title
|
||||
else:
|
||||
@ -139,6 +146,9 @@ class Paginator:
|
||||
self._embed_description = description
|
||||
else:
|
||||
raise RuntimeError('Provided Description is too long')
|
||||
self._embed_color = color
|
||||
self._embed_thumbnail = thumbnail
|
||||
self._embed_url = url
|
||||
|
||||
def pages(self) -> typing.List[str]:
|
||||
_pages = list()
|
||||
@ -163,6 +173,7 @@ class Paginator:
|
||||
_page += self._suffix
|
||||
_pages.append(_page)
|
||||
else:
|
||||
if _fields:
|
||||
_pages.append(_fields)
|
||||
open_page()
|
||||
|
||||
@ -191,6 +202,7 @@ class Paginator:
|
||||
def close_field(next_name: str=None):
|
||||
nonlocal _field_name, _field_value, _fields
|
||||
_field_value += self._suffix
|
||||
if _field_value != self._prefix + self._suffix:
|
||||
_fields.append({'name': _field_name, 'value': _field_value, 'inline': _inline})
|
||||
if next_name:
|
||||
open_field(next_name)
|
||||
@ -244,6 +256,12 @@ class Paginator:
|
||||
description=self._embed_description,
|
||||
color=self._bot.embed_color,
|
||||
)
|
||||
if self._embed_thumbnail:
|
||||
em.set_thumbnail(url=self._embed_thumbnail)
|
||||
if self._embed_url:
|
||||
em.url = self._embed_url
|
||||
if self._embed_color:
|
||||
em.color = self._embed_color
|
||||
em.set_footer(text=f'{i + 1}/{_len_pages}')
|
||||
for field in page:
|
||||
em.add_field(name=field['name'], value=field['value'], inline=field['inline'])
|
||||
@ -348,9 +366,12 @@ class Book:
|
||||
# noinspection PyShadowingNames
|
||||
def check(reaction, user):
|
||||
if self._locked:
|
||||
return str(reaction.emoji) in self._bot.book_emojis.values() and user == self._calling_message.author
|
||||
return str(reaction.emoji) in self._bot.book_emojis.values() \
|
||||
and user == self._calling_message.author \
|
||||
and reaction.message.id == self._message.id
|
||||
else:
|
||||
return str(reaction.emoji) in self._bot.book_emojis.values()
|
||||
return str(reaction.emoji) in self._bot.book_emojis.values() \
|
||||
and reaction.message.id == self._message.id
|
||||
|
||||
await self.display_page()
|
||||
|
||||
@ -384,15 +405,16 @@ class Book:
|
||||
elif str(reaction.emoji) == self._bot.book_emojis['start']:
|
||||
self._current_page = 0
|
||||
elif str(reaction.emoji) == self._bot.book_emojis['hash']:
|
||||
m = await self._channel.send(f'Please enter a number between 1 and {self._len_pages}')
|
||||
m = await self._channel.send(f'Please enter a number in range 1 to {self._len_pages}')
|
||||
|
||||
def num_check(message):
|
||||
if self._locked:
|
||||
return message.content.isdigit() \
|
||||
and 0 < int(message.content) < self._len_pages \
|
||||
and 0 < int(message.content) <= self._len_pages \
|
||||
and message.author == self._calling_message.author
|
||||
else:
|
||||
return message.content.isdigit() \
|
||||
and 0 < int(message.content) < self._len_pages
|
||||
and 0 < int(message.content) <= self._len_pages
|
||||
|
||||
try:
|
||||
msg = await self._bot.wait_for('message', timeout=30, check=num_check)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user