Skip to content

Commit

Permalink
misc: simplify message send method
Browse files Browse the repository at this point in the history
+ correct the api request sequence check request status code first
to ensure response data before formating to json

Signed-off-by: Mr.Miss <[email protected]>
  • Loading branch information
Mr.Miss committed Mar 30, 2021
1 parent ff83160 commit 92564d6
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions anjani_bot/plugins/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ async def paste(self, message):
text="Nekobin Raw",
url=f"https://nekobin.com/raw/{key}"),
]])
await sent.edit_text(await self.bot.text(message.chat.id, "paste-succes"), reply_markup=btn)
await sent.edit_text(
await self.bot.text(message.chat.id, "paste-succes"),
reply_markup=btn)
else:
await sent.edit_text(await self.bot.text(message.chat.id,
"fail-paste"))
Expand All @@ -143,18 +145,21 @@ async def src(self, message):
"[GitHub repo](https://github.com/userbotindo/Anjani)\n" +
"[Support](https://t.me/userbotindo)",
disable_web_page_preview=True)
@listener.on('slap', filters.group)

@listener.on("slap", filters.group)
async def neko_slap(self, message):
""" Slap member with neko slap. """
chat_id = message.chat.id
async with self.bot.http.get('https://www.nekos.life/api/v2/img/slap') as r:
res = await r.json()
if r.status != 200:
await message.reply(await self.bot.text(chat_id, "err-api-down"))
else:
reply_to = message.reply_to_message
if reply_to:
await reply_to.reply_animation(res['url'])
else:
await message.reply_animation(res['url'])
""" Slap member with neko slap. """
chat_id = message.chat.id
async with self.bot.http.get(
'https://www.nekos.life/api/v2/img/slap') as slap:
if slap.status != 200:
return await message.reply(
await self.bot.text(chat_id, "err-api-down"))
res = await slap.json()

reply_to = message.reply_to_message or message
await self.bot.client.send_animation(
message.chat.id,
res["url"],
reply_to_message_id=reply_to.message_id
)

0 comments on commit 92564d6

Please sign in to comment.