11import nextcord
22from 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
49class 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 )
0 commit comments