Skip to content

Commit 4fdca1f

Browse files
authored
Fix/top chat (#6)
* Add header message to top-chat * fixed user id
1 parent e7656a0 commit 4fdca1f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

tops.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def top_chat(update: Update, context: ContextTypes.DEFAULT_TYPE):
3636
top_10 = sorted(ratings.items(), key=lambda x: x[1], reverse=True)[:10]
3737

3838
# format the response message
39-
response = ""
39+
response = f"Top 10 players in {game_mode}:\n\n"
4040
for i, (lichess_username, rating) in enumerate(top_10):
4141
response += f"{i+1}. {lichess_username}: {rating}\n"
4242

users.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
async def register(update: Update, context: ContextTypes.DEFAULT_TYPE):
77
# Get the Telegram user ID and the Lichess username from the message
8-
telegram_id = update.effective_chat.id
8+
telegram_id = update.effective_user.id
9+
910
try:
1011
lichess_username = context.args[0]
1112
except Exception as error:
@@ -28,7 +29,12 @@ async def register(update: Update, context: ContextTypes.DEFAULT_TYPE):
2829
await context.bot.send_message(chat_id=update.effective_chat.id, text=message)
2930

3031
async def stats(update: Update, context: ContextTypes.DEFAULT_TYPE):
31-
stats_query = f'SELECT lichess_username FROM users WHERE telegram_id = {update.effective_chat.id}'
32+
telegram_id = update.effective_user.id
33+
34+
if update.message.reply_to_message:
35+
telegram_id = update.message.reply_to_message.from_user.id
36+
37+
stats_query = f'SELECT lichess_username FROM users WHERE telegram_id = {telegram_id}'
3238
result = database_fetchone(stats_query)
3339

3440
if result is None:

0 commit comments

Comments
 (0)