diff --git a/payphone/bot.py b/payphone/bot.py index fad71f0..f5da2fd 100644 --- a/payphone/bot.py +++ b/payphone/bot.py @@ -7,7 +7,7 @@ from discord import abc from discord.ext import commands from discord.ext.commands import errors -from tortoise import expressions, transactions +from tortoise import expressions, transactions, exceptions as tortoise_exc import redis.asyncio as aredis @@ -366,6 +366,11 @@ class Payphone(commands.AutoShardedBot): elif isinstance(exception, errors.CommandNotFound): return + + elif isinstance(exception, tortoise_exc.TransactionManagementError): + # Tortoise ORM bug. This may need to be logged for debugging, but for now they just + # clutter the logs. + return else: return await super().on_command_error(context, exception) diff --git a/payphone/cogs/calls/cog.py b/payphone/cogs/calls/cog.py index 0fc92db..283381f 100644 --- a/payphone/cogs/calls/cog.py +++ b/payphone/cogs/calls/cog.py @@ -678,6 +678,10 @@ class Calls(base.Cog): lambda c: c.id != channel_id, call.channels ) + if other_channel is None: + # BUG: The call wasn't properly set up. + return + user, profile = await utils.get_user(message.author) call_rss = await models.CallUserChannelRelationship.filter( diff --git a/payphone/cogs/users/cog.py b/payphone/cogs/users/cog.py index ff07d8d..e4d1855 100644 --- a/payphone/cogs/users/cog.py +++ b/payphone/cogs/users/cog.py @@ -390,37 +390,28 @@ class Users(base.Cog): top_users = ( await models.User.filter(leaderboard_position__lte=10) + .prefetch_related("profiles") .order_by("leaderboard_position") .limit(10) ) - rows = [ - [ - f"#{pos + 1}", - fmt.trim(user.username, 13), - f"{user.leaderboard_calls_count if user.leaderboard_calls_count is not None else "?"} call{"s" if user.leaderboard_calls_count != 1 else ""}", - ] + user_rows = [ + f"**#{pos + 1} - {user.profiles[0].name}**{" (You!)" if user.id == ctx.author.id else ""}\nParticipated in {user.leaderboard_calls_count} calls." for pos, user in enumerate(top_users) ] - if not any(map(lambda u: u.id == ctx.author.id, top_users)): - user, _ = await utils.get_user(ctx.author) - - if user.leaderboard_position is not None: - rows.append( - [ - f"#{user.leaderboard_position}", - fmt.trim(user.username, 13), - f"{user.leaderboard_calls_count if user.leaderboard_calls_count is not None else "?"} call{"s" if user.leaderboard_calls_count != 1 else ""}", - ] - ) - - table = fmt.monospace_table(rows) - embed = discord.Embed( color=constants.EMBED_COLOR, title=f"Monthly Leaderboard ({datetime.now(timezone.utc).strftime("%B")})", - description=f"```\n{table if len(rows) > 0 else "Come back in 15 minutes!"}\n```", + description=( + "Payphone's monthly leaderboard is based on the amount of calls you've " + "participated in with more than 25 messages sent (to prevent spam). The stats are " + "resetted every month.\n" + "\n" + "__**Top Users:**__\n" + "\n" + ) + + "\n\n".join(user_rows), author=self.bot.embed_author, footer=discord.EmbedFooter( text="The leaderboard is updated every 15 minutes."