ADD: Quote leaderboard feature

pull/3/head
Kamal Curi 2 years ago
parent b3ea63d265
commit 3aba3e19b2

@ -11,7 +11,7 @@ from discord import Embed, Intents
from discord.ext import commands
from settings.config import IMAGE_TYPES, OW_API_CONFIG, PERMISSIONS
from utils.database import (count_quotes, get_by_id, get_quote_contains,
from utils.database import (count_quotes, count_quotes_user, get_by_id, get_quote_contains,
get_quotes, remove_quote, set_quote)
from utils.machine_monitor import Monitor
from utils.news_paper import News
@ -364,3 +364,17 @@ async def neofetch(bot: object) -> str:
nfetch = open('/tmp/neofetch', mode='r')
nfetch = nfetch.read()
return await bot.send("```\n" + nfetch + "\n```")
@client.command(aliases=['qlb'])
async def count_leaderboard(bot:object):
"""
Returns a list of quoters, sorted by amount of quotes.
"""
qlb = "```\nLista de quoteiros\n"
lis = count_quotes_user()
lis = sorted(lis, key=lambda lis: lis[1], reverse=True)
for data in lis:
qlb = qlb + data[0] + " - " + str(data[1]) + "\n"
qlb = qlb + "```"
return await bot.send(qlb)

@ -6,6 +6,7 @@ import logging
import MySQLdb
from models.quotes import Quotes
from settings.config import MYSQL_CONFIG, SQLACHEMY
from sqlalchemy import func
from sqlalchemy.orm import Session
logger = logging.getLogger(__name__)
@ -122,6 +123,13 @@ def count_quotes() -> int:
response = session.query(Quotes.id).count()
return response
def count_quotes_user():
"""
Quote "leaderboard"
"""
with Session(SQLACHEMY) as session:
response = session.query(Quotes.user, func.count(Quotes.user)).group_by(Quotes.user).all()
return response
def get_quote_contains(part: str) -> tuple:
"""

Loading…
Cancel
Save