main: Added support for more gif types

Though most don't have links for yet, so they won't work :(
This commit is contained in:
Yuki Joou 2023-02-22 18:46:54 +01:00
parent 49b4f68e2c
commit a3b6cfdc53

26
main.py
View file

@ -14,25 +14,31 @@ with open("gifs.json") as file:
gifs = json.load(file) gifs = json.load(file)
# Commands # Commands
# Gif commands
async def hug_handler(message: discord.Message, command: list[str]): async def gif_handler(message: discord.Message, command: list[str]):
gif_kind = command[0]
target = "" target = ""
if len(command) <= 1: if len(command) <= 1:
target = f"<@{message.author.id}>" target = f"<@{message.author.id}>"
else: else:
target = command[1] target = command[1]
if "hugs" not in gifs: if gif_kind not in gifs:
await message.reply( await message.reply(
"im so sorry, i have no hugs to give you for now... come back later :3") "im so sorry, i have no such thing to give you for now... come back later :3")
hug = random.choice(gifs["hugs"]) choosen_gif = random.choice(gifs[gif_kind])
await message.reply(f"here u go {target}\n{hug}") await message.reply(f"here u go {target}\n{choosen_gif}")
COMMAND_HANDLERS = { GIF_COMMANDS = [
"hug": hug_handler, "hug",
} "kiss",
"cuddle",
"hold",
]
# Discord events # Discord events
@ -46,8 +52,8 @@ async def on_message(message: discord.Message):
message_as_command = message.content.split(" ") message_as_command = message.content.split(" ")
command = message_as_command[0] command = message_as_command[0]
if command in COMMAND_HANDLERS: if command in GIF_COMMANDS:
await COMMAND_HANDLERS[command](message, message_as_command) await gif_handler(message, message_as_command)
client.run(open("token").read()) client.run(open("token").read())