diff --git a/cogs/chatgpt.py b/cogs/chatgpt.py index 45a13de..40e3c96 100644 --- a/cogs/chatgpt.py +++ b/cogs/chatgpt.py @@ -284,7 +284,7 @@ class ChatGPT(commands.Cog): channel_config = await self.get_channel_config(ctx.channel.id) current_topic = channel_config["channel_topic"] await ctx.send(f"Current topic is {current_topic}") - + @commands.command( description="Chat", @@ -403,6 +403,53 @@ class ChatGPT(commands.Cog): log_filepath.writelines(log_data) await ctx.send(f'Generated by: {ctx.author.name}\nPrompt: {prompt}', file=f) + @commands.command( + description="Big Spenders", + help="Generate a list of the biggest spenders. Usage: !bigspenders", + brief="Generate list of big spenders" + ) + async def bigspenders(self, ctx): + filenames = os.listdir(self.data_dir + "logs/") + user_cost_dict = {} + for filename in filenames: + if ".log" in filename: + with open(f"{self.data_dir}logs/{filename}", 'r', encoding="utf-8") as f: + for line in f: + try: + if "!dalle3hd" in line: + cost = 0.08 + username = line[0:line.index(':')] + if " " in username: + break + if username not in user_cost_dict: + user_cost_dict[username] = 0 + user_cost_dict[username] += cost + elif "!dalle2" in line: + cost = 0.02 + username = line[0:line.index(':')] + if " " in username: + break + if username not in user_cost_dict: + user_cost_dict[username] = 0 + user_cost_dict[username] += cost + if "!dalle" in line or "!dalle3" in line: + cost = 0.04 + username = line[0:line.index(':')] + if " " in username: + break + if username not in user_cost_dict: + user_cost_dict[username] = 0 + user_cost_dict[username] += cost + else: + pass + except: + pass + message = "Big Spenders:\n" + sorted_dictionary = sorted(user_cost_dict.items(), key=lambda x: x[1], reverse=True) + for user in sorted_dictionary: + message += f"{user[0]}: ${user[1]:.2f}\n" + await ctx.send(message) + @commands.command( description="Dalle 2",