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

Commit 1fc0983

Browse files
committed
added leaderboard command and tracking
1 parent 315991b commit 1fc0983

3 files changed

Lines changed: 81 additions & 7 deletions

File tree

cogs/leaderboard.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import nextcord
2+
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(), "")
8+
9+
class Leaderboard(commands.Cog):
10+
def __init__(self,bot):
11+
self.bot=bot
12+
13+
@commands.Cog.listener()
14+
async def on_ready(self):
15+
print(f"leaderboard - Loaded")
16+
17+
@nextcord.slash_command(name="leaderboard", description="Frong leaderboard")
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=":crown: **LEADERBOARD**", color=0xd6b509)
44+
embed.add_field(name=":speech_balloon: __FRONGS BY USER__", value=data,inline=False)
45+
embed.add_field(name=":loudspeaker: __TOTAL FRONGS__", value=total,inline=False)
46+
await interaction.response.send_message(embed=embed, ephemeral=True)
47+
48+
def setup(bot):
49+
bot.add_cog(Leaderboard(bot))

data.csv

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

main.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,30 @@
44
import os
55
import aiohttp
66
from random import randint
7+
import csv
78

89
load_dotenv()
910

11+
def update_csv(name, filename):
12+
updated = False
13+
with open(filename, 'r') as file:
14+
reader = csv.DictReader(file)
15+
rows = list(reader)
16+
for row in rows:
17+
if row['Name'] == name:
18+
row['Value'] = str(int(row['Value']) + 1)
19+
updated = True
20+
break
21+
else:
22+
rows.append({'Name': name, 'Value': '1'})
23+
updated = True
24+
25+
if updated:
26+
with open(filename, 'w', newline='') as file:
27+
writer = csv.DictWriter(file, fieldnames=['Name', 'Value'])
28+
writer.writeheader()
29+
writer.writerows(rows)
30+
1031
def main():
1132
# allows privledged intents for monitoring members joining, roles editing, and role assignments
1233
intents = nextcord.Intents.default()
@@ -24,17 +45,18 @@ def main():
2445
owner_id="null",
2546
)
2647

48+
csv_file = "data.csv"
2749

2850
# responses for the arch user replies
2951
responses = ["",
3052
"Oh you use arch? Why don’t you `sudo pacman -S some-bitches`.",
3153
"""
32-
```
33-
sudo pacman -Syu
34-
reboot
54+
```
55+
sudo pacman -Syu
56+
reboot
3557
36-
grub rescue>
37-
```
58+
grub rescue>
59+
```
3860
""",
3961
"https://tenor.com/view/arch-linux-linux-open-source-arch-i-use-arch-btw-gif-25315741",
4062
"https://tenor.com/view/arch-linux-i-use-arch-lonely-gif-26341678",
@@ -78,6 +100,10 @@ async def on_message(message):
78100
frong_words = ["frong"]
79101
for word in frong_words:
80102
if word.lower() in content_lower:
103+
# increment message author frong count
104+
update_csv(str(message.author), 'data.csv')
105+
106+
# send frong response
81107
await message.channel.send('frong', files=[nextcord.File('frong.png')])
82108
return
83109

0 commit comments

Comments
 (0)