-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added leaderboard command and tracking
- Loading branch information
1 parent
315991b
commit 1fc0983
Showing
3 changed files
with
81 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import nextcord | ||
from nextcord.ext import commands | ||
import os | ||
import csv | ||
|
||
# get path name for csv file | ||
file_path = os.path.join(os.getcwd(), "") | ||
|
||
class Leaderboard(commands.Cog): | ||
def __init__(self,bot): | ||
self.bot=bot | ||
|
||
@commands.Cog.listener() | ||
async def on_ready(self): | ||
print(f"leaderboard - Loaded") | ||
|
||
@nextcord.slash_command(name="leaderboard", description="Frong leaderboard") | ||
async def leaderboard(self, interaction: nextcord.Interaction): | ||
csv_dict = {} | ||
data = "" | ||
total = 0 | ||
with open(file_path + "data.csv", 'r') as file: | ||
reader = csv.DictReader(file) | ||
|
||
# turn csv into dictionary | ||
for row in reader: | ||
key = row.pop('Name') # Replace 'Key_Column_Name' with the actual column name for the key | ||
csv_dict[key] = row | ||
|
||
# sort the dictionary | ||
sorted_dict = dict(sorted(csv_dict.items(), key=lambda x: int(x[1]['Value']), reverse=True)) | ||
|
||
# get values from dictionary | ||
for key, value in sorted_dict.items(): | ||
content = "**" + key + "**: " | ||
data += content | ||
for key2, value2 in dict(value).items(): | ||
content2 = value2 + "\n" | ||
data += content2 | ||
total += int(value2) | ||
|
||
# send embed | ||
embed = nextcord.Embed(title=":crown: **LEADERBOARD**", color=0xd6b509) | ||
embed.add_field(name=":speech_balloon: __FRONGS BY USER__", value=data,inline=False) | ||
embed.add_field(name=":loudspeaker: __TOTAL FRONGS__", value=total,inline=False) | ||
await interaction.response.send_message(embed=embed, ephemeral=True) | ||
|
||
def setup(bot): | ||
bot.add_cog(Leaderboard(bot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
Name,Value | ||
|
||
Name,Value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters