Skip to content
This repository was archived by the owner on Apr 11, 2025. It is now read-only.

Commit f894d98

Browse files
committed
added frong leaderboard command
1 parent 6bebc9c commit f894d98

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

cogs/frong.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import nextcord
22
from nextcord.ext import commands
3+
import os
4+
import csv
5+
6+
# get path name for csv file
7+
file_path = os.path.join(os.getcwd(), "")
38

49
class Sourcecode(commands.Cog):
510
def __init__(self,bot):
@@ -9,6 +14,37 @@ def __init__(self,bot):
914
async def on_ready(self):
1015
print(f"frong - Loaded")
1116

17+
@nextcord.slash_command(name="leaderboard", description="Frong leaderboard", guild_ids=[414625175217242113])
18+
async def leaderboard(self, interaction: nextcord.Interaction):
19+
csv_dict = {}
20+
data = ""
21+
total = 0
22+
with open(file_path + "data.csv", 'r') as file:
23+
reader = csv.DictReader(file)
24+
25+
# turn csv into dictionary
26+
for row in reader:
27+
key = row.pop('Name') # Replace 'Key_Column_Name' with the actual column name for the key
28+
csv_dict[key] = row
29+
30+
# sort the dictionary
31+
sorted_dict = dict(sorted(csv_dict.items(), key=lambda x: int(x[1]['Value']), reverse=True))
32+
33+
# get values from dictionary
34+
for key, value in sorted_dict.items():
35+
content = "**" + key + "**: "
36+
data += content
37+
for key2, value2 in dict(value).items():
38+
content2 = value2 + "\n"
39+
data += content2
40+
total += int(value2)
41+
42+
# send embed
43+
embed = nextcord.Embed(title="**LEADERBOARD**", color=0x4287f5)
44+
embed.add_field(name="__FRONGS BY USER__", value=data,inline=False)
45+
embed.add_field(name="__TOTAL FRONGS__", value=total,inline=False)
46+
await interaction.response.send_message(embed=embed, ephemeral=False)
47+
1248
@nextcord.slash_command(name="frongs", description="List all Frong definitions")
1349
async def frongs(self, interaction: nextcord.Interaction):
1450
embed = nextcord.Embed(title="**Frongs**", color=0x4287f5)

data.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Name,Value
2+

0 commit comments

Comments
 (0)