diff --git a/.gitignore b/.gitignore index 0a2795b..deb529a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ discord_info.txt .venv -.env \ No newline at end of file +.env +__pycache__ \ No newline at end of file diff --git a/bot.py b/bot.py index 8378cf7..7627952 100644 --- a/bot.py +++ b/bot.py @@ -17,8 +17,9 @@ async def send_message(message, user_message, is_private): await message.channel.send("You do not have permission to manage emojis.") return + gif_data, gif_name = response try: - await message.guild.create_custom_emoji(name="gif", image=response) + await message.guild.create_custom_emoji(name=gif_name, image=gif_data) await message.channel.send("Emote Added") except discord.HTTPException as e: await message.channel.send(f"An error occurred: {e}") diff --git a/responses.py b/responses.py index 7d0cbab..20b2f51 100644 --- a/responses.py +++ b/responses.py @@ -36,4 +36,7 @@ def addGif(url): image = pyvips.Image.new_from_buffer(webp_data, '') gif_data = image.write_to_buffer('.gif') - return gif_data \ No newline at end of file + + gif_name = seventv.get_emote_name(url) + + return gif_data, gif_name diff --git a/seventv.py b/seventv.py index 2cad4f9..5aada2c 100644 --- a/seventv.py +++ b/seventv.py @@ -1,7 +1,5 @@ import requests -#import imageio -#import io -#imageio.plugins.freeimage.download() + def get_webp_url(url): emote_id = url[23:] @@ -16,26 +14,14 @@ def get_webp_url(url): return ('No 128x128 file detected') -''' -Old function that might be used later +def get_emote_name(url): + emote_id = url[23:] + api_call = ('https://7tv.io/v3/emotes/' + emote_id) + response = requests.get(api_call).json() -def webp_to_gif(url): - # Download the webp file - response = requests.get(url) + emote_name = response['name'] + + return emote_name - print(url) - - # Open the webp file using imageio - im = imageio.imread(response.content, format="WEBP") - - # Create a bytes buffer to hold the GIF data - gif_buffer = io.BytesIO() - - # Write the image as a GIF file to the bytes buffer - imageio.mimwrite(gif_buffer, [im], format='GIF', loop=1, duration=1) - - # Return the GIF data as a bytes object - return gif_buffer.getvalue() -'''