From 65c1beb01073fda3b6d71ae8d9d239e8d887f634 Mon Sep 17 00:00:00 2001 From: deadcade Date: Sun, 12 Jun 2022 15:24:31 +0200 Subject: [PATCH] Add httpcat command --- data/settings.json | 4 +++- main.py | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/data/settings.json b/data/settings.json index e6b60cd..7f004cc 100644 --- a/data/settings.json +++ b/data/settings.json @@ -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" diff --git a/main.py b/main.py index 6c69f13..ba8bbe3 100644 --- a/main.py +++ b/main.py @@ -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'])}: {rj['safe_title']}") 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"]: