Skip to content

Commit

Permalink
added leaderboard command and tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
Soulsender committed Jun 6, 2024
1 parent 315991b commit 1fc0983
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 7 deletions.
49 changes: 49 additions & 0 deletions cogs/leaderboard.py
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))
3 changes: 1 addition & 2 deletions data.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Name,Value

Name,Value
36 changes: 31 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@
import os
import aiohttp
from random import randint
import csv

load_dotenv()

def update_csv(name, filename):
updated = False
with open(filename, 'r') as file:
reader = csv.DictReader(file)
rows = list(reader)
for row in rows:
if row['Name'] == name:
row['Value'] = str(int(row['Value']) + 1)
updated = True
break
else:
rows.append({'Name': name, 'Value': '1'})
updated = True

if updated:
with open(filename, 'w', newline='') as file:
writer = csv.DictWriter(file, fieldnames=['Name', 'Value'])
writer.writeheader()
writer.writerows(rows)

def main():
# allows privledged intents for monitoring members joining, roles editing, and role assignments
intents = nextcord.Intents.default()
Expand All @@ -24,17 +45,18 @@ def main():
owner_id="null",
)

csv_file = "data.csv"

# responses for the arch user replies
responses = ["",
"Oh you use arch? Why don’t you `sudo pacman -S some-bitches`.",
"""
```
sudo pacman -Syu
reboot
```
sudo pacman -Syu
reboot
grub rescue>
```
grub rescue>
```
""",
"https://tenor.com/view/arch-linux-linux-open-source-arch-i-use-arch-btw-gif-25315741",
"https://tenor.com/view/arch-linux-i-use-arch-lonely-gif-26341678",
Expand Down Expand Up @@ -78,6 +100,10 @@ async def on_message(message):
frong_words = ["frong"]
for word in frong_words:
if word.lower() in content_lower:
# increment message author frong count
update_csv(str(message.author), 'data.csv')

# send frong response
await message.channel.send('frong', files=[nextcord.File('frong.png')])
return

Expand Down

0 comments on commit 1fc0983

Please sign in to comment.