Add httpcat command

This commit is contained in:
deadcade 2022-06-12 15:24:31 +02:00
parent 2d5d145dc7
commit 65c1beb010
2 changed files with 19 additions and 2 deletions

View file

@ -17,13 +17,15 @@
"ping",
"roll",
"xkcd",
"help"
"help",
"httpcat"
],
"help_messages": {
"help": "{prefix}help (command): Get information on commands",
"ping": "{prefix}ping {Host}: Ping the selfbot (or any host)",
"roll": "{prefix}roll (Number): Roll a dice (with number sides)",
"xkcd": "{prefix}xkcd (Number/Title): Get an XKCD comic",
"httpcat": "{prefix}httpcat (Status Code): Get a HTTP Cat",
"shrug": "{prefix}shrug {text}: Append ¯\\_(ツ)_/¯ to the text",
"emoji_size": "{prefix}emoji_size {size}: Set the default emoji size",
"emoji_list": "{prefix}emoji_list: Get a list of usable custom emojis"

17
main.py
View file

@ -11,7 +11,7 @@ import html # HTML formatting
import requests # XKCD command
import difflib # XKCD Title lookup
import subprocess # GIF Emojis, ping command (admin)
import random # roll command
import random # roll command, http cat without args
import datetime # Ratelimiting
# External dependencies
@ -266,6 +266,21 @@ async def xkcd(args, room, event):
await send_text(room.room_id, f"{rj['year']}/{rj['month']}/{rj['day']}, {str(rj['num'])}: <a href=\"https://xkcd.com/{str(rj['num'])}/\">{rj['safe_title']}</a>")
return await send_image(room.room_id, image, rj['alt'])
async def httpcat(args, room, event):
global settings
if len(args) == 1 and args[0].isdecimal():
code = args[0]
elif len(args) == 0:
code = random.choice([100, 101, 102, 200, 201, 202, 203, 204, 206, 207, 300, 301, 302, 303, 304, 305, 307, 308, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 420, 421, 422, 423, 424, 425, 426, 429, 431, 444, 450, 451, 498, 499, 500, 501, 502, 503, 504, 506, 507, 508, 509, 510, 511, 521, 522, 523, 525, 599])
r = requests.get(f"https://http.cat/{str(code)}.jpg")
filename = download_file(f"https://http.cat/{str(code)}.jpg", settings["cache_path"] + "/httpcat-" + str(code) + ".jpg")
if filename:
image = await send_file(filename)
return await send_image(room.room_id, image, str(code))
else:
return await send_text(room.room_id, "Failed to get HTTP Cat!")
async def message_callback(room: nio.MatrixRoom, event: nio.RoomMessageText) -> None:
global client, settings, emojis
if settings["debug"]: