feat: add rank
This commit is contained in:
+19
-1
@@ -17,4 +17,22 @@ async def currency_check(ctx: commands.Context):
|
||||
await ctx.send("Có lỗi xảy ra khi tạo tài khoản currency")
|
||||
return
|
||||
|
||||
await ctx.send(f"Thông tin tài khoản của bạn: {currency.balance}")
|
||||
await ctx.send(f"Thông tin tài khoản của bạn: {currency.balance}")
|
||||
|
||||
@bot.command(name="rank", description="list rank")
|
||||
async def list_rank(ctx: commands.Context):
|
||||
"""Kiểm tra thông tin tài khoản của bạn"""
|
||||
# Check if user is registered in database. If not, create a new one
|
||||
balances = await currency_repo.get_all()
|
||||
msg = "```\n"
|
||||
msg += f"{'No.':<4} {'Name':<20} {'Win':>8}\n"
|
||||
msg += "-" * 34 + "\n"
|
||||
for i, b in enumerate(balances, start=1):
|
||||
msg += f"{i:<4} {b.user_name:<20} {b.balance:>8}\n"
|
||||
msg += "```"
|
||||
|
||||
await ctx.send(msg)
|
||||
|
||||
async def incr(user_id, user_name, amount):
|
||||
await currency_repo.upsert_or_increment_balance(user_id, user_name, amount)
|
||||
|
||||
|
||||
+4
-1
@@ -5,6 +5,7 @@ from core.bot import bot
|
||||
from discord.ext import commands
|
||||
from typing import Dict, Set, Optional
|
||||
from datetime import datetime, timedelta
|
||||
from apps.currency import incr
|
||||
|
||||
# Lazy load repository để tránh lỗi database connection
|
||||
noi_tu_repo = None
|
||||
@@ -186,6 +187,7 @@ async def end_game(ctx):
|
||||
value=f"**{game.last_player_name}** - Từ cuối: **{game.current_word}**",
|
||||
inline=False
|
||||
)
|
||||
await incr(game.last_player_id, game.last_player_name, 1)
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
@@ -291,6 +293,7 @@ async def game_timeout():
|
||||
value=f"**{game.last_player_name}** - Từ cuối: **{game.current_word}**",
|
||||
inline=False
|
||||
)
|
||||
await incr(game.last_player_id, game.last_player_name, 1)
|
||||
|
||||
if game.channel:
|
||||
await game.channel.send(embed=embed)
|
||||
@@ -359,7 +362,7 @@ async def handle_game_message(message):
|
||||
await message.add_reaction('❌')
|
||||
return
|
||||
|
||||
with game.lock:
|
||||
async with game.lock:
|
||||
if not is_valid(game.current_word, word):
|
||||
return
|
||||
# Từ hợp lệ
|
||||
|
||||
Reference in New Issue
Block a user