Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions users.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,27 @@ def handleLog(self, timestamp: datetime, message: str):
# Ignore but mirror log if it's new
if timestamp > self.lastUpdateTimestamp:
self.bot.log.debug(f"Ignored: {message}")


async def check_char_limit(self, tosend, ctx, headers=()):
"""
Check if the message is under the 2000 character discord limit, if not send in multiple messages
"""
# For each message -> make sure they are under the char limit
# If not make a new table and then send a new message
# Definitely could be more efficient but it works lol
messages = [tosend]
x = 0
for message in messages:
while len(f'```\n{tabulate(messages[x], headers=headers, tablefmt="fancy_grid")}\n```') > DISCORD_MAX_CHAR:
if x == len(messages) - 1:
messages.append([])
messages[x+1].append(messages[x][-1])
messages[x] = messages[x][0:-1]
await ctx.send(
f'```\n{tabulate(messages[x], headers=headers, tablefmt="fancy_grid")}\n```'
)
x += 1

@commands.command()
async def users(self, ctx, arg: str = None):
"""
Expand All @@ -144,21 +164,8 @@ async def users(self, ctx, arg: str = None):
user.hoursAlive,
]
)
# For each message -> make sure they are under the char limit
# If not make a new table and then send a new message
# Definitely could be more efficient but it works lol
messages = [table]
x = 0
for message in messages:
while len(f'```\n{tabulate(messages[x], headers=headers, tablefmt="fancy_grid")}\n```') > DISCORD_MAX_CHAR:
if x == len(messages) - 1:
messages.append([])
messages[x+1].append(messages[x][-1])
messages[x] = messages[x][0:-1]
await ctx.send(
f'```\n{tabulate(messages[x], headers=headers, tablefmt="fancy_grid")}\n```'
)
x += 1
await self.check_char_limit(table, ctx, headers=headers)


@commands.command()
async def info(self, ctx, name=None):
Expand All @@ -184,4 +191,4 @@ async def info(self, ctx, name=None):
for perk in user.perks:
if int(user.perks[perk]) != 0:
table.append([perk, user.perks[perk]])
await ctx.send(f'```\n{tabulate(table, tablefmt="fancy_grid")}\n```')
await self.check_char_limit(table, ctx)