2018-11-07 00:00:00 -05:00
|
|
|
from discord.ext.commands import Paginator
|
|
|
|
|
|
|
|
|
2018-11-06 15:22:02 -05:00
|
|
|
def tostring(i, *, order=None, newline=False):
|
2017-10-30 23:29:22 -04:00
|
|
|
o = ''
|
|
|
|
if i:
|
|
|
|
for v in i:
|
2018-11-07 00:00:00 -05:00
|
|
|
o += v + (' ' if newline is False else ' \n')
|
2017-10-30 23:29:22 -04:00
|
|
|
o = o[:-1]
|
|
|
|
elif order:
|
|
|
|
o += order
|
|
|
|
else:
|
|
|
|
o = ' '
|
|
|
|
return o
|
2017-09-24 11:05:28 -04:00
|
|
|
|
2017-10-12 22:26:22 -04:00
|
|
|
|
2017-09-24 11:05:28 -04:00
|
|
|
def tostring_commas(i):
|
2017-10-30 23:29:22 -04:00
|
|
|
if i:
|
|
|
|
o = ','
|
|
|
|
for v in i:
|
|
|
|
o += v + ','
|
|
|
|
return o[:-1]
|
|
|
|
return ''
|
2017-09-24 11:05:28 -04:00
|
|
|
|
2017-10-12 22:26:22 -04:00
|
|
|
|
2018-11-07 00:00:00 -05:00
|
|
|
async def paginate(
|
|
|
|
ctx,
|
|
|
|
i,
|
|
|
|
start='',
|
|
|
|
prefix='',
|
|
|
|
kprefix='',
|
|
|
|
ksuffix='\n',
|
|
|
|
eprefix='```\n',
|
|
|
|
ejoin=' ',
|
|
|
|
esuffix='\n```',
|
|
|
|
suffix='',
|
|
|
|
end=''):
|
|
|
|
paginator = Paginator(prefix=prefix, suffix=suffix)
|
|
|
|
messages = []
|
2018-11-06 15:22:02 -05:00
|
|
|
|
2018-11-07 00:00:00 -05:00
|
|
|
if start:
|
|
|
|
paginator.add_line(start)
|
|
|
|
|
|
|
|
if type(i) in (tuple, list, set):
|
2018-11-15 15:33:34 -05:00
|
|
|
paginator.add_line(eprefix + f'{ejoin}'.join(i) + esuffix)
|
|
|
|
|
2018-11-07 00:00:00 -05:00
|
|
|
elif type(i) is dict:
|
|
|
|
for k, e in sorted(i.items()):
|
2018-11-15 15:33:34 -05:00
|
|
|
if e and (k not in e) and (len(e) >= 1):
|
2018-11-07 00:00:00 -05:00
|
|
|
paginator.add_line(kprefix + k + ksuffix + eprefix + f'{ejoin}'.join(e) + esuffix)
|
|
|
|
|
|
|
|
if end:
|
|
|
|
paginator.add_line(end)
|
|
|
|
|
|
|
|
for page in paginator.pages:
|
|
|
|
messages.append(await ctx.send(page))
|
|
|
|
|
|
|
|
return messages
|
2017-09-24 11:05:28 -04:00
|
|
|
|
2017-10-12 22:26:22 -04:00
|
|
|
|
2017-09-24 11:05:28 -04:00
|
|
|
def dictelem_tostring(i):
|
2017-10-30 23:29:22 -04:00
|
|
|
o = ''
|
|
|
|
if i:
|
|
|
|
for dic, elem in i.items():
|
|
|
|
o += '**__' + dic + '__**\n'
|
|
|
|
for k, v in elem.items():
|
|
|
|
o += '***' + k + ':*** `' + tostring(v) + '`\n'
|
|
|
|
return o
|