-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from varundeepsaini/lint
Lint
- Loading branch information
Showing
9 changed files
with
199 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: Lint | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: psf/black@stable | ||
with: | ||
options: "--check --verbose" | ||
src: "." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,60 @@ | ||
from requests import get | ||
from bs4 import BeautifulSoup | ||
from discord import Embed, Colour, ApplicationContext, bot | ||
from discord import Embed, Colour, ApplicationContext, bot | ||
from discord.ext import commands | ||
|
||
|
||
class AtCoderProfile: | ||
success = False | ||
|
||
def __init__(self, username: str): | ||
response = get(f"https://atcoder.jp/users/{username}") | ||
if not response.ok: | ||
self.success = False | ||
return | ||
soup = BeautifulSoup(response.content, 'html5lib') | ||
self.username = soup.find('a', attrs={'class': 'username'}).contents[0].getText() | ||
self.kyu = soup.find('div', attrs={'id': 'main-container'}).find('h3').find('b').contents[0] | ||
statsRows = soup.findAll('div', attrs={'id': 'main-container', 'class': 'container'})[0].findAll('table')[1].findAll('tr') | ||
soup = BeautifulSoup(response.content, "html5lib") | ||
self.username = ( | ||
soup.find("a", attrs={"class": "username"}).contents[0].getText() | ||
) | ||
self.kyu = ( | ||
soup.find("div", attrs={"id": "main-container"}) | ||
.find("h3") | ||
.find("b") | ||
.contents[0] | ||
) | ||
statsRows = ( | ||
soup.findAll("div", attrs={"id": "main-container", "class": "container"})[0] | ||
.findAll("table")[1] | ||
.findAll("tr") | ||
) | ||
self.rank = statsRows[0].td.getText() | ||
self.rating = statsRows[1].td.span.getText() | ||
self.highestRating = statsRows[2].td.span.getText() | ||
self.ratedMatches = statsRows[3].td.getText() | ||
self.success = True | ||
|
||
def embed(self): | ||
embed = Embed(title=self.username, color=Colour.dark_grey()) | ||
embed.set_author(name="AtCoder", icon_url="https://img.atcoder.jp/assets/icon/avatar.png") | ||
embed.set_author( | ||
name="AtCoder", icon_url="https://img.atcoder.jp/assets/icon/avatar.png" | ||
) | ||
embed.add_field(name="", value=f"**{self.kyu}**", inline=False) | ||
embed.add_field(name="Rank", value=self.rank) | ||
embed.add_field(name="Rated Matches", value=self.ratedMatches) | ||
embed.add_field(name="Rating", value=self.rating) | ||
embed.add_field(name="Highest Rating", value=self.highestRating) | ||
return embed | ||
|
||
class AtCoder(commands.Cog): | ||
|
||
class AtCoder(commands.Cog): | ||
@commands.slash_command() | ||
async def at_coder(self, ctx: ApplicationContext, username: str): | ||
profile = AtCoderProfile(username) | ||
if (not profile.success): | ||
if not profile.success: | ||
await ctx.respond("Invalid username") | ||
return | ||
await ctx.respond(embed=profile.embed()) | ||
|
||
|
||
def setup(bot: bot.Bot): | ||
bot.add_cog(AtCoder(bot)) | ||
bot.add_cog(AtCoder(bot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.