logging added
This commit is contained in:
parent
b21d37b124
commit
495cb082a0
1 changed files with 99 additions and 95 deletions
|
|
@ -6,13 +6,18 @@ import discord
|
|||
from discord.ext import commands
|
||||
|
||||
|
||||
@commands.command(
|
||||
class Highscores(commands.Cog):
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
@commands.command(
|
||||
description="Highscores",
|
||||
help="Shows a bar graph of users in this channel and how many messages they have sent.",
|
||||
brief="Display chat highscores",
|
||||
aliases=["highscore"]
|
||||
)
|
||||
async def highscores(ctx, limit=15):
|
||||
async def highscores(self, ctx, limit=15):
|
||||
filename = str(ctx.channel.id) + ".log"
|
||||
with open("data/chatgpt/logs/" + filename, 'r', encoding="utf-8") as logfile:
|
||||
data = logfile.readlines()
|
||||
|
|
@ -36,7 +41,7 @@ async def highscores(ctx, limit=15):
|
|||
else:
|
||||
user_message_counts[user] += 1
|
||||
except Exception as error:
|
||||
print("Error occurred in highscores")
|
||||
self.bot.logger.exception("Error occurred in highscores")
|
||||
|
||||
sorted_message_counts = sorted(user_message_counts.items(), key=lambda x:x[1])
|
||||
sorted_dict = dict(sorted_message_counts[-limit::])
|
||||
|
|
@ -55,13 +60,13 @@ async def highscores(ctx, limit=15):
|
|||
await ctx.send(file=f)
|
||||
|
||||
|
||||
@commands.command(
|
||||
@commands.command(
|
||||
description="Highscores Server",
|
||||
help="Shows a bar graph of users across all servers I am in and how many messages they have sent.",
|
||||
brief="Display chat highscores",
|
||||
aliases=["highscore_server"]
|
||||
)
|
||||
async def highscores_server(ctx, limit=15):
|
||||
async def highscores_server(self, ctx, limit=15):
|
||||
|
||||
def is_username(user):
|
||||
for character in user:
|
||||
|
|
@ -87,7 +92,7 @@ async def highscores_server(ctx, limit=15):
|
|||
else:
|
||||
user_message_counts[user] += 1
|
||||
except Exception as error:
|
||||
print("Error occurred in highscores_server")
|
||||
self.bot.logger.exception("Error occurred in highscores_server")
|
||||
|
||||
sorted_message_counts = sorted(user_message_counts.items(), key=lambda x:x[1])
|
||||
sorted_dict = dict(sorted_message_counts[-limit::])
|
||||
|
|
@ -106,5 +111,4 @@ async def highscores_server(ctx, limit=15):
|
|||
await ctx.send(file=f)
|
||||
|
||||
async def setup(bot):
|
||||
bot.add_command(highscores)
|
||||
bot.add_command(highscores_server)
|
||||
bot.add_cog(Highscores(bot))
|
||||
Loading…
Add table
Add a link
Reference in a new issue