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
|
from discord.ext import commands
|
||||||
|
|
||||||
|
|
||||||
|
class Highscores(commands.Cog):
|
||||||
|
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
@commands.command(
|
@commands.command(
|
||||||
description="Highscores",
|
description="Highscores",
|
||||||
help="Shows a bar graph of users in this channel and how many messages they have sent.",
|
help="Shows a bar graph of users in this channel and how many messages they have sent.",
|
||||||
brief="Display chat highscores",
|
brief="Display chat highscores",
|
||||||
aliases=["highscore"]
|
aliases=["highscore"]
|
||||||
)
|
)
|
||||||
async def highscores(ctx, limit=15):
|
async def highscores(self, ctx, limit=15):
|
||||||
filename = str(ctx.channel.id) + ".log"
|
filename = str(ctx.channel.id) + ".log"
|
||||||
with open("data/chatgpt/logs/" + filename, 'r', encoding="utf-8") as logfile:
|
with open("data/chatgpt/logs/" + filename, 'r', encoding="utf-8") as logfile:
|
||||||
data = logfile.readlines()
|
data = logfile.readlines()
|
||||||
|
|
@ -36,7 +41,7 @@ async def highscores(ctx, limit=15):
|
||||||
else:
|
else:
|
||||||
user_message_counts[user] += 1
|
user_message_counts[user] += 1
|
||||||
except Exception as error:
|
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_message_counts = sorted(user_message_counts.items(), key=lambda x:x[1])
|
||||||
sorted_dict = dict(sorted_message_counts[-limit::])
|
sorted_dict = dict(sorted_message_counts[-limit::])
|
||||||
|
|
@ -61,7 +66,7 @@ async def highscores(ctx, limit=15):
|
||||||
brief="Display chat highscores",
|
brief="Display chat highscores",
|
||||||
aliases=["highscore_server"]
|
aliases=["highscore_server"]
|
||||||
)
|
)
|
||||||
async def highscores_server(ctx, limit=15):
|
async def highscores_server(self, ctx, limit=15):
|
||||||
|
|
||||||
def is_username(user):
|
def is_username(user):
|
||||||
for character in user:
|
for character in user:
|
||||||
|
|
@ -87,7 +92,7 @@ async def highscores_server(ctx, limit=15):
|
||||||
else:
|
else:
|
||||||
user_message_counts[user] += 1
|
user_message_counts[user] += 1
|
||||||
except Exception as error:
|
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_message_counts = sorted(user_message_counts.items(), key=lambda x:x[1])
|
||||||
sorted_dict = dict(sorted_message_counts[-limit::])
|
sorted_dict = dict(sorted_message_counts[-limit::])
|
||||||
|
|
@ -106,5 +111,4 @@ async def highscores_server(ctx, limit=15):
|
||||||
await ctx.send(file=f)
|
await ctx.send(file=f)
|
||||||
|
|
||||||
async def setup(bot):
|
async def setup(bot):
|
||||||
bot.add_command(highscores)
|
bot.add_cog(Highscores(bot))
|
||||||
bot.add_command(highscores_server)
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue