From 6e74ac1fd58d0f488437b5fb66a2a7873934f5b1 Mon Sep 17 00:00:00 2001 From: phixxy Date: Mon, 11 Mar 2024 23:45:34 -0700 Subject: [PATCH] added bigspenders command to guilt people into donating --- cogs/chatgpt.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) 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",