Spaces:
Running on CPU Upgrade

lunarflu HF staff commited on
Commit
74bc7fc
·
1 Parent(s): 0aa83ad

top messages

Browse files
Files changed (1) hide show
  1. app.py +18 -16
app.py CHANGED
@@ -14,26 +14,16 @@ bot = commands.Bot(command_prefix='!', intents=intents)
14
 
15
 
16
 
17
-
18
-
19
  """"""
20
  XP_PER_MESSAGE = 10
 
21
 
22
 
23
-
24
-
25
-
26
-
27
-
28
- """"""
29
  @bot.event
30
  async def on_ready():
31
  print(f'Logged in as {bot.user.name}')
32
 
33
 
34
-
35
-
36
-
37
  try:
38
  with open('xp_data.json', 'r') as f:
39
  xp_data = json.load(f)
@@ -46,9 +36,6 @@ def save_xp_data():
46
  json.dump(xp_data, f)
47
 
48
 
49
-
50
-
51
-
52
  @bot.event
53
  async def on_message(message):
54
  try:
@@ -65,8 +52,7 @@ async def on_message(message):
65
  except Exception as e:
66
  print(f"Error: {e}")
67
 
68
-
69
-
70
  # Calculate the level based on XP
71
  def calculate_level(xp):
72
  return int(xp ** 0.5)
@@ -81,6 +67,22 @@ async def level(ctx):
81
  await ctx.send(f'You are at level {level} with {xp} XP.')
82
  else:
83
  await ctx.send('You have not earned any XP yet.')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  """"""
86
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
 
14
 
15
 
16
 
 
 
17
  """"""
18
  XP_PER_MESSAGE = 10
19
+ """"""
20
 
21
 
 
 
 
 
 
 
22
  @bot.event
23
  async def on_ready():
24
  print(f'Logged in as {bot.user.name}')
25
 
26
 
 
 
 
27
  try:
28
  with open('xp_data.json', 'r') as f:
29
  xp_data = json.load(f)
 
36
  json.dump(xp_data, f)
37
 
38
 
 
 
 
39
  @bot.event
40
  async def on_message(message):
41
  try:
 
52
  except Exception as e:
53
  print(f"Error: {e}")
54
 
55
+
 
56
  # Calculate the level based on XP
57
  def calculate_level(xp):
58
  return int(xp ** 0.5)
 
67
  await ctx.send(f'You are at level {level} with {xp} XP.')
68
  else:
69
  await ctx.send('You have not earned any XP yet.')
70
+
71
+
72
+ @bot.command()
73
+ async def top_users(ctx, limit: int = 10):
74
+ """Get the top users with the highest message counts."""
75
+ message_counts = {}
76
+ for member in ctx.guild.members:
77
+ #if not member.bot:
78
+ message_counts[member] = sum(1 for _ in await ctx.history(user=member).flatten())
79
+
80
+ sorted_users = sorted(message_counts.items(), key=lambda x: x[1], reverse=True)
81
+ top_list = "\n".join([f"{member.name}: {count}" for member, count in sorted_users[:limit]])
82
+ await ctx.send(f"Top {limit} users by message count:\n{top_list}")
83
+
84
+
85
+
86
 
87
  """"""
88
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)