Modify paginator
This commit is contained in:
parent
4945ac630b
commit
bfa9d7c1ef
@ -66,6 +66,14 @@ def to_list_of_str(items, out: list=list(), level=1, recurse=0):
|
|||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
|
def format_output(text):
|
||||||
|
if type(text) == list:
|
||||||
|
text = to_list_of_str(text)
|
||||||
|
elif type(text) == dict:
|
||||||
|
text = to_list_of_str(text)
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
def replace_text_ignorecase(in_str: str, old: str, new: str='') -> str:
|
def replace_text_ignorecase(in_str: str, old: str, new: str='') -> str:
|
||||||
re_replace = re.compile(re.escape(old), re.IGNORECASE)
|
re_replace = re.compile(re.escape(old), re.IGNORECASE)
|
||||||
return re_replace.sub(f'{new}', in_str)
|
return re_replace.sub(f'{new}', in_str)
|
||||||
@ -194,13 +202,3 @@ class Paginator:
|
|||||||
self._parts.insert(0, item)
|
self._parts.insert(0, item)
|
||||||
else:
|
else:
|
||||||
self._parts.append(item)
|
self._parts.append(item)
|
||||||
|
|
||||||
|
|
||||||
def paginate(text):
|
|
||||||
paginator = Paginator()
|
|
||||||
if type(text) == list:
|
|
||||||
text = to_list_of_str(text)
|
|
||||||
elif type(text) == dict:
|
|
||||||
text = to_list_of_str(text)
|
|
||||||
paginator.add(text)
|
|
||||||
return paginator.pages()
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import inspect
|
|||||||
import textwrap
|
import textwrap
|
||||||
from contextlib import redirect_stdout
|
from contextlib import redirect_stdout
|
||||||
import io
|
import io
|
||||||
from .imports.utils import paginate, run_command
|
from .imports.utils import run_command, format_output, Paginator
|
||||||
|
|
||||||
ownerids = [351794468870946827, 275280442884751360]
|
ownerids = [351794468870946827, 275280442884751360]
|
||||||
ownerid = 351794468870946827
|
ownerid = 351794468870946827
|
||||||
@ -69,8 +69,11 @@ class Repl:
|
|||||||
await ctx.message.add_reaction('✅')
|
await ctx.message.add_reaction('✅')
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
output = f'{value}\nReturned: {ret}'
|
value = format_output(value)
|
||||||
for page in paginate(output):
|
pag = Paginator()
|
||||||
|
pag.add(value)
|
||||||
|
pag.add(f'\nReturned: {ret}')
|
||||||
|
for page in pag.pages():
|
||||||
await ctx.send(page)
|
await ctx.send(page)
|
||||||
|
|
||||||
@commands.command(hidden=True)
|
@commands.command(hidden=True)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user