Skip to content

Instantly share code, notes, and snippets.

@juni37
Created September 15, 2021 05:06
Show Gist options
  • Save juni37/e5d5570b9180bd0463193c689a56012d to your computer and use it in GitHub Desktop.
Save juni37/e5d5570b9180bd0463193c689a56012d to your computer and use it in GitHub Desktop.
@client.command(aliases=['hkdev', 'HKDev', 'hk', 'HK', 'leaderboard', 'lb', '하이케이', '에이치케이', '리더보드', 'ㅣㅠ'])
async def _leaderboard(ctx, count=None):
try:
if count == None:
count = '10'
elif int(count) < 10:
await ctx.send("10 이상의 수를 입력해 주세요!")
return None
elif int(count) > 25:
await ctx.send("숫자가 너무 큽니다! 최대 값인 25로 설정됩니다.")
count = '25'
url = "https://level.hkdev.xyz/leaderboard"
response = requests.get(url)
response_code = int(response.status_code)
if response_code == 200:
soup = BeautifulSoup(response.content, 'lxml')
lb_user = soup.select('#app > div > div > div > div.leader-wrap > div.leader-content > div.leader-name')
lb_level = soup.select(
'#app > div > div > div > div.leader-wrap > div.leader-content > div.leader-score > div:nth-child(1)')
lb_exp = soup.select(
'#app > div > div > div > div.leader-wrap > div.leader-content > div.leader-score > div:nth-child(2)')
lb_embed = discord.Embed(title="**HKDev Leaderboard**")
n = 0
lb_line = ""
while n != int(count):
lb_line = lb_line + f"{lb_user[n].get_text()} / {lb_level[n].get_text().replace('.', '')} | {lb_exp[n].get_text()}\n"
n += 1
lb_embed.description = "```c\n" + lb_line + "```"
lb_embed.color = 0x00FF00
lb_embed.set_footer(icon_url=f'{ctx.author.avatar_url}',
text=f'{ctx.author}' + " • " + str(now.month) + "월 " + str(now.day) + "일 " + str(
now.hour) + "시 " + str(now.minute) + "분")
await ctx.send(embed=lb_embed)
except Exception as error:
await ctx.send(emoji_warn + " 으악! 에러다!")
await ctx.send(emoji_warn + "" + str(error))
@client.command(aliases=['myrank', 'myrk', 'mr', '내랭크', '내랭크찾기'])
async def _myrank(ctx):
try:
url = "https://level.hkdev.xyz/leaderboard"
response = requests.get(url)
response_code = int(response.status_code)
if response_code == 200:
soup = BeautifulSoup(response.content, 'lxml')
lb_user = soup.select('#app > div > div > div > div.leader-wrap > div.leader-content > div.leader-name')
lb_level = soup.select(
'#app > div > div > div > div.leader-wrap > div.leader-content > div.leader-score > div:nth-child(1)')
lb_exp = soup.select(
'#app > div > div > div > div.leader-wrap > div.leader-content > div.leader-score > div:nth-child(2)')
lb_user_text = []
for i in lb_user:
lb_user_text.append(i.get_text().split('. ')[1].split('#')[0])
user_rank = lb_user_text.index(f'{ctx.author.name}')
embed = discord.Embed(title=f"{lb_user_text[user_rank]}'s HKDev Rank",
description=f"```Rank : {int(user_rank) + 1}\n{lb_level[user_rank].get_text().replace('.', '')} | {lb_exp[user_rank].get_text()}```",
color=0x00FF00)
embed.set_footer(icon_url=f'{ctx.author.avatar_url}',
text=f'{ctx.author}' + " • " + str(now.month) + "월 " + str(now.day) + "일 " + str(
now.hour) + "시 " + str(now.minute) + "분")
await ctx.send(embed=embed)
except Exception as error:
await ctx.send(emoji_warn + " 으악! 에러다!")
await ctx.send(emoji_warn + "" + str(error))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment