Update heroku_info.py

pull/50/head
Who? 2024-12-26 11:43:56 +07:00 committed by GitHub
parent 978e33429c
commit 795aa3ff90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 28 additions and 0 deletions

View File

@ -33,6 +33,12 @@ class HerokuInfoMod(loader.Module):
validator=loader.validators.Link(),
),
loader.ConfigValue(
"pp_to_banner",
False,
validator=loader.validators.Boolean(),
),
loader.ConfigValue(
"show_heroku",
True,
@ -40,6 +46,26 @@ class HerokuInfoMod(loader.Module):
),
)
async def upload_pp_to_oxo(self, photo):
save_path = "profile_photo.jpg"
await self._client.download_media(photo, file=save_path)
try:
oxo = await utils.run_sync(
requests.post,
"https://0x0.st",
files={"file": open(save_path, 'rb')},
data={"secret": True},
)
return oxo.text.strip()
except Exception:
return ""
async def get_pp_for_banner(self):
photos = await self._client.get_profile_photos('me')
if photos:
return await self.upload_pp_to_oxo(photos[0])
return ""
def _render_info(self, inline: bool) -> str:
try:
repo = git.Repo(search_parent_directories=True)
@ -154,6 +180,8 @@ class HerokuInfoMod(loader.Module):
@loader.command()
async def infocmd(self, message: Message):
if self.config['pp_to_banner']:
self.config['banner_url'] = await self.get_pp_for_banner()
await utils.answer_file(
message,
self.config["banner_url"],