Skip to content

Commit

Permalink
Fix/top chat (#6)
Browse files Browse the repository at this point in the history
* Add header message to top-chat

* fixed user id
  • Loading branch information
sldenazis authored Apr 12, 2023
1 parent e7656a0 commit 4fdca1f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tops.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ async def top_chat(update: Update, context: ContextTypes.DEFAULT_TYPE):
top_10 = sorted(ratings.items(), key=lambda x: x[1], reverse=True)[:10]

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

Expand Down
10 changes: 8 additions & 2 deletions users.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

async def register(update: Update, context: ContextTypes.DEFAULT_TYPE):
# Get the Telegram user ID and the Lichess username from the message
telegram_id = update.effective_chat.id
telegram_id = update.effective_user.id

try:
lichess_username = context.args[0]
except Exception as error:
Expand All @@ -28,7 +29,12 @@ async def register(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(chat_id=update.effective_chat.id, text=message)

async def stats(update: Update, context: ContextTypes.DEFAULT_TYPE):
stats_query = f'SELECT lichess_username FROM users WHERE telegram_id = {update.effective_chat.id}'
telegram_id = update.effective_user.id

if update.message.reply_to_message:
telegram_id = update.message.reply_to_message.from_user.id

stats_query = f'SELECT lichess_username FROM users WHERE telegram_id = {telegram_id}'
result = database_fetchone(stats_query)

if result is None:
Expand Down

0 comments on commit 4fdca1f

Please sign in to comment.