Add http cat command

This commit is contained in:
DasMoorhuhn 2025-07-08 23:47:51 +02:00
parent fb52e0d842
commit 39f1a777f9
6 changed files with 58 additions and 9 deletions

View File

@ -4,3 +4,4 @@ sys.path.append('..')
from src.addons.date_time_helper import DateTimeHelper
from src.addons.programmer_excuses import ProgrammerExcuses
from src.addons.xkcd import XKCD
from src.addons.http_cat import HttpCat

9
src/addons/http_cat.py Normal file
View File

@ -0,0 +1,9 @@
import requests
class HttpCat:
def __init__(self) -> None:
self.url = "https://http.cat/images"
def get_http_cat_code(self, http_code:int):
return f"{self.url}/{http_code}.jpg"

View File

@ -10,7 +10,6 @@ from discord import Interaction
from client import Client
import secret_handler
bot_info = {'version': '1.1.4', 'date': '20.02.2024'}
logger = logging.getLogger('discord')
logger.setLevel(logging.DEBUG)
@ -23,7 +22,7 @@ formatter = logging.Formatter('%(asctime)s|%(levelname)s|%(name)s|:%(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
bot = Client(intents=discord.Intents.all(), command_prefix="!", log=logger, bot_info=bot_info)
bot = Client(intents=discord.Intents.all(), command_prefix="!", log=logger)
@bot.event
@ -49,6 +48,10 @@ async def on_ready():
logger.info(f"Synced {len(synced)} command(s)")
await bot.update_presence()
# for guild in bot.guilds:
# if guild.system_channel is not None:
# await guild.system_channel.send("NEW COMMAND: /http")
@bot.event
async def on_app_command_error(interaction: Interaction, error):

View File

@ -10,13 +10,12 @@ import addons
class Client(commands.Bot):
"""Custom bot class"""
def __init__(self, command_prefix, *, intents: Intents, log:logging, bot_info:dict):
def __init__(self, command_prefix, *, intents: Intents, log:logging):
super().__init__(command_prefix, intents=intents)
self.log:logging = log
self.addons:addons = addons
self.start_time:float = self.addons.DateTimeHelper.get_unix_time()
self.version:str = bot_info['version']
self.date:str = bot_info['date']
self.version:str = "2025-07-08"
async def startup(self):
await self.wait_until_ready()

View File

@ -32,7 +32,8 @@ class HelpCommands(Cog):
command_list_string += "`/help` : Get this view\n"
command_list_string += "`/get-random-comic`: Get a randowm XCCD comic\n"
command_list_string += "`/get-latest-comic`: Get latest comic from XKCD\n"
command_list_string += "`/excuse` : Get a random excuse from programmingexcuses"
command_list_string += "`/excuse` : Get a random excuse from programmingexcuses\n"
command_list_string += "`/http` : Get a cat picture for your HTTP Code. If the Code doesn't exists, it will give you HTTP Cat 404"
embed = Embed(title=f"Help", description="List of commands", color=Color.blue())
embed.add_field(name="Commands", value=command_list_string, inline=True)
@ -44,11 +45,11 @@ class HelpCommands(Cog):
bot_string = ""
bot_string += f"Uptime : {await self.bot.get_uptime()}s\n"
bot_string += f"Version : {self.bot.version} from {self.bot.date}\n"
bot_string += f"Version : {self.bot.version}\n"
bot_string += f"On Servers: {await self.bot.count_guilds()}\n"
bot_string += f"Developer : dasmoorhuhn\n"
bot_string += f"Sourcecode: [Gitlab](https://gitlab.com/DasMoorhuhn/tux-discord-bot)\n"
bot_string += f"Privacy : [Read about privacy](https://gitlab.com/DasMoorhuhn/tux-discord-bot/-/blob/main/README.md?ref_type=heads#privacy)"
bot_string += f"Sourcecode: [Gitlab](https://git.pinguin-software.de/DasMoorhuhn/tux-discord-bot)\n"
bot_string += f"Privacy : [Read about privacy](https://git.pinguin-software.de/DasMoorhuhn/tux-discord-bot#privacy)"
embed = Embed(title=f"Info", description="about this Bot",
color=Color.blue())

View File

@ -0,0 +1,36 @@
import discord
from discord import Embed
from discord import Color
from discord import app_commands
from discord import Interaction
from discord.ext import commands
from discord.ext.commands import Cog
import sys
sys.path.append('..')
from src.client import Client as Bot
class HttpCatCommands(Cog):
def __init__(self, bot:Bot):
self.bot = bot
self.log = bot.log
self.http_cat = bot.addons.HttpCat()
@commands.Cog.listener()
async def on_ready(self):
self.log.info("Done: HttpCat")
@app_commands.command(name="http", description="Get a cat picture for your HTTP Code. If the Code doesn't exists, it will give you HTTP Cat 404.")
async def http(self, interaction: Interaction, http_code:int):
self.log.info("Command: HTTP")
cat = self.http_cat.get_http_cat_code(http_code=http_code)
embed = Embed(title=f"HTTP Code {http_code}", color=Color.blue(), url=cat)
embed.set_image(url=cat)
await interaction.response.send_message(embed=embed)
async def setup(bot:Bot):
await bot.add_cog(HttpCatCommands(bot))
bot.log.info(f"Loaded HttpCat")