Skip to content

Commit

Permalink
.rank_card() now returns a RankCard object
Browse files Browse the repository at this point in the history
  • Loading branch information
Soheab committed Sep 3, 2020
1 parent f28eed5 commit e611263
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Upload Python Package

on:
release:
types: [created]
types: [ created ]

jobs:
deploy:
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# VACEfron.py | Changelog
See here what changed or broke each version.

## 1.1.1
- `.rank_card()` now returns a [RankCard](docs.md#rankcard) object, so you can access the provided attributes, see
them in the [docs](docs.md). `.read()` should still work.

## v1.1.0
- Added support for new endpoint `.distracted_bf()`. See the [Docs](docs.md#await-vac_apidistracted_bfboyfriend-girlfriend-woman) for it.
- Renamed `image.py` to `classes.py`
- Added a RankCard class, nothing interesting, keep using `.rank_card()`.
- You can now easily get the version by doing `.__version__`.

## v1.0.2
- docs.md and README.md improvements. New version to update it on PyPi.
Expand Down
54 changes: 49 additions & 5 deletions docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ All available endpoints you can use.
### Rank card

---
#### await vac_api.rank_card(username, avatar, level, rank, current_xp, next_level_xp, previous_level_xp, custom_background, xp_color, is_boosting)
#### await vac_api.rank_card(username, avatar, level, rank, current_xp, next_level_xp, previous_level_xp, custom_background, xp_color, is_boosting)
Generate a Rank card for Discord bots!

**Parameters**:
Expand All @@ -37,8 +37,7 @@ Generate a Rank card for Discord bots!
- current_xp `int` | The user's current XP amount.
- next_level_xp `int` | The user's next XP amount.
- previous_level_xp `int` | The user's previous XP amount.

- custom_background `string` | A optional background for the rank card.
- custom_background `string` | An optional background for the rank card.
- xp_color `string` | The color for the XP bar. Defaults to #FCBA41.
- is_boosting `bool` | If True, a boost badge will be displayed next to user's name. Defaults to False.

Expand Down Expand Up @@ -177,12 +176,12 @@ Make someone's avatar a *little* bit wider.

---
### await vac_api.discord_server(creator)
Get an invitation to the Vacefron's server (or and the creator of this wrapper.)
Get an invitation to the VAC Efron's server (or and the creator of this wrapper.)

**Parameters**:
- creator `boolean` | To also get an invitation to the server of creator of this wrapper.

**Return type**: string or tuple
**Return type**: string or tuple when creator is True

# Objects
Here is explained what attributes the returned objects have
Expand All @@ -201,3 +200,48 @@ npc_meme = await vac_api.npc("ah yes", "no u")
npc_bytes = await npc_meme.read() # <_io.BytesIO object at 0x0438DFC8> - BytesIO object.
await ctx.send(file=discord.File(npc_bytes, filename="npc.png"))
```

## RankCard
This object gets returned from `.rank_card()`

#### RankCard.url
The url of the card

#### await RankCard.read()
This will return a BytesIO object, which can be passed to discord.File() with a filename
for [discord.py](https://github.com/Rapptz/discord.py):
```py
card = await vac_api.rank_card(....)
card_bytes = await card.read() # <_io.BytesIO object at 0x0438DFC8> - BytesIO object.
await ctx.send(file=discord.File(card_bytes, filename="rank_card.png"))
```

#### RankCard.username
The user's username, you provided but `#` replaced with `%23`

#### RankCard.avatar
The user's avatar, you provided

#### RankCard.level
The user's current level you provided

#### RankCard.rank
The user's position, you provided

#### RankCard.current_xp
The user's current XP amount, you provided

#### RankCard.next_level_xp
The user's next XP amount, you provided

#### RankCard.previous_level_xp
The user's previous XP amount, you provided

#### RankCard.custom_background
An optional background for the rank card, if you provided one else None

#### RankCard.xp_color
The color for the XP bar but `#` replaced with `%23`, if you provided one else None

#### RankCard.is_boosting
Bool, True if you set it to True else False
2 changes: 1 addition & 1 deletion vacefron/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .client import Client
from .errors import BadRequest, HTTPException, InternalServerError, NotFound

__version__ = '1.1.0'
__version__ = '1.1.1'
11 changes: 9 additions & 2 deletions vacefron/classes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from io import BytesIO
from re import search

from aiohttp import ClientSession

from .errors import BadRequest


Expand All @@ -20,13 +22,14 @@ async def read(self) -> BytesIO:


class RankCard:
__slots__ = ("username", "avatar", "level", "rank", "current_xp", "next_level_xp",
__slots__ = ("_session", "username", "avatar", "level", "rank", "current_xp", "next_level_xp",
"previous_level_xp", "custom_background", "xp_color", "is_boosting",
)

def __init__(self, username: str, avatar: str, level: int, rank: int, current_xp: int,
def __init__(self, _session: ClientSession, username: str, avatar: str, level: int, rank: int, current_xp: int,
next_level_xp: int, previous_level_xp: int, custom_background: str = None,
xp_color: str = None, is_boosting: bool = False) -> None:
self._session = _session
self.username = username
self.avatar = avatar
self.level = level
Expand All @@ -41,6 +44,10 @@ def __init__(self, username: str, avatar: str, level: int, rank: int, current_xp
def __str__(self) -> str:
return f"https://vacefron.nl/api/rankcard{self.create_rank_card}"

async def read(self) -> BytesIO:
_bytes = await (await self._session.get(str(self))).read()
return BytesIO(_bytes)

@property
def create_rank_card(self) -> str:
params = f"?username={self.username}" \
Expand Down
5 changes: 3 additions & 2 deletions vacefron/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,19 @@ async def wide(self, image: str) -> Image:
async def rank_card(
self, username: str, avatar: str, level: int, rank: int, current_xp: int,
next_level_xp: int, previous_level_xp: int, custom_background: str = None,
xp_color: str = None, is_boosting: bool = False) -> Image:
xp_color: str = None, is_boosting: bool = False) -> RankCard:

username = _replace_characters(str(username))
xp_color = str(xp_color).replace("#", "") if xp_color else None

card = RankCard(
self.session,
username, avatar, level, rank, current_xp,
next_level_xp, previous_level_xp, custom_background, xp_color, is_boosting
)

await self._check_url(str(card))
return Image(str(card), self.session)
return card

async def close(self) -> None:
if not self.session.closed:
Expand Down

0 comments on commit e611263

Please sign in to comment.