From 49b4f68e2c8f78a8ad91153ecb56421131edbd64 Mon Sep 17 00:00:00 2001 From: Yuki Joou Date: Wed, 22 Feb 2023 18:41:33 +0100 Subject: [PATCH] Initial commit: Proof of concept Please add gifs to ./gifs.json :3 --- .gitignore | 1 + gifs.json | 5 +++++ main.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 .gitignore create mode 100644 gifs.json create mode 100755 main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8d865be --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +token diff --git a/gifs.json b/gifs.json new file mode 100644 index 0000000..8047df2 --- /dev/null +++ b/gifs.json @@ -0,0 +1,5 @@ +{ + "hugs": [ + "https://64.media.tumblr.com/5541ac10ee55974f882d9d437a3cc2d1/tumblr_nz0jt3jM421sbzv20o1_500.gif" + ] +} diff --git a/main.py b/main.py new file mode 100755 index 0000000..3692002 --- /dev/null +++ b/main.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +import discord +import json +import random + +intents = discord.Intents.default() +intents.message_content = True + +client = discord.Client(intents=intents) + +gifs = {} +with open("gifs.json") as file: + gifs = json.load(file) + +# Commands + + +async def hug_handler(message: discord.Message, command: list[str]): + target = "" + if len(command) <= 1: + target = f"<@{message.author.id}>" + else: + target = command[1] + + if "hugs" not in gifs: + await message.reply( + "im so sorry, i have no hugs to give you for now... come back later :3") + + hug = random.choice(gifs["hugs"]) + await message.reply(f"here u go {target}\n{hug}") + +COMMAND_HANDLERS = { + "hug": hug_handler, +} + +# Discord events + + +@client.event +async def on_message(message: discord.Message): + if message.author.bot == True: + return + + # TODO: Do proper parsing of the message + message_as_command = message.content.split(" ") + + command = message_as_command[0] + if command in COMMAND_HANDLERS: + await COMMAND_HANDLERS[command](message, message_as_command) + + +client.run(open("token").read())