Coder Social home page Coder Social logo

pet-pet-gif's Introduction

pet-pet-gif

Python adaptation of https://github.com/aDu/pet-pet-gif

Usage:

from petpetgif import petpet  
petpet.make(source, dest)
  • source: A filename (string), pathlib.Path object or a file object. (This parameter corresponds and is passed to the PIL.Image.open() method.)

  • dest: A filename (string), pathlib.Path object or a file object. (This parameter corresponds and is passed to the PIL.Image.save() method.)

Basic example:

from petpetgif import petpet
petpet.make('test.png', 'out.gif')

Discord.py example:

import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
from io import BytesIO
from typing import Union, Optional
from petpetgif import petpet as petpetgif

load_dotenv()
token = os.getenv('DISCORD_BOT_TOKEN')

client = commands.Bot(command_prefix='!')

@client.event
async def on_ready():
    print('Bot is ready.')

@client.command()
async def pet(ctx, image: Optional[Union[discord.PartialEmoji, discord.member.Member]]):
    if type(image) == discord.PartialEmoji:
        image = await image.url_as(format='png').read() # retrieve the image bytes
    elif type(image) == discord.member.Member:
        image = await image.avatar_url_as(format='png').read() # retrieve the image bytes
    else:
        await ctx.reply('Please use a custom emoji or tag a member to petpet their avatar.')
        return

    source = BytesIO(image) # file-like container to hold the emoji in memory
    dest = BytesIO() # container to store the petpet gif in memory
    petpetgif.make(source, dest)
    dest.seek(0) # set the file pointer back to the beginning so it doesn't upload a blank file.
    await ctx.send(file=discord.File(dest, filename=f"{image[0]}-petpet.gif"))


client.run(token)

pet-pet-gif's People

Contributors

camprevail avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pet-pet-gif's Issues

Can't load the module from a script on another disk

Traceback (most recent call last):
  File "C:\Users\MK - Gaming PC\AppData\Local\Programs\Python\Python38\lib\site-packages\discord\ext\commands\bot.py", line 607, in _load_from_module_spec
    spec.loader.exec_module(lib)
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "E:\Project-Ludde\libs\cogs\fun.py", line 2, in <module>
    from petpetgif import petpet as petpetmaker
  File "C:\Users\MK - Gaming PC\AppData\Local\Programs\Python\Python38\lib\site-packages\petpetgif\petpet.py", line 6, in <module>
    package_dir = Path(os.path.relpath(__file__)).parent
  File "C:\Users\MK - Gaming PC\AppData\Local\Programs\Python\Python38\lib\ntpath.py", line 703, in relpath
    raise ValueError("path is on mount %r, start on mount %r" % (
ValueError: path is on mount 'C:', start on mount 'E:'

petpetgif on members

it would be a cool feature for it to be able to get the members avatar then turn it into a petpet gif instead of just emojis

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.