Exemple #1
0
def __upload_to_imgur(path, caption):
    if not isfile(path):
        return

    # TODO: Convert to GIF and upload.
    if path[-3:] == 'mp4':
        remove(path)
        return

    im = Imgur(environ.get('IMGUR_CLIENT_ID'), environ.get('IMGUR_CLIENT_KEY'),
               environ.get('IMGUR_ACCESS_TOKEN'),
               environ.get('IMGUR_REFRESH_TOKEN'))
    for _ in range(5):
        # noinspection PyBroadException
        try:
            im.upload_image(path=abspath(path),
                            title=caption,
                            album=environ.get('IMGUR_ALBUM'))
        except Exception:
            im.refresh_access_token()
            sleep(10)
            continue

        remove(path)
        return
Exemple #2
0
def __upload_to_imgur(path, caption):
    log_debug('__upload started')
    if not isfile(path):
        log_warn('File to be uploaded not found')
        return

    # TODO: Convert to GIF and upload.
    if path[-3:] == 'mp4':
        remove(path)
        log_warn('Skipping mp4 upload')
        return

    log_debug('Authorizing imgur client')
    im = Imgur(environ.get('IMGUR_CLIENT_ID'), environ.get('IMGUR_CLIENT_KEY'),
               environ.get('IMGUR_ACCESS_TOKEN'),
               environ.get('IMGUR_REFRESH_TOKEN'))

    for _ in range(5):
        try:
            im.upload_image(path=abspath(path),
                            title=caption,
                            album=environ.get('IMGUR_ALBUM'))
            log_debug('Image successfully uploaded')
            break
        except Exception:
            log_warn('Upload failed, refreshing token')
            im.refresh_access_token()
            sleep(10)
            continue
    else:
        log_error('Upload failed, proceeding')

    log_debug('Deleting file')
    remove(path)
    return
Exemple #3
0
 def __init__(self, parent=None):
     super(trayApp, self).__init__(parent)
     self.loadSettings()
     self.setIcon(QIcon("icon.png"))
     self.createSysTrayMenu()
     self.setGlobalHotkeys()
     self.imgurClient = Imgur("", "")
     self.clipboard = QApplication.clipboard()
Exemple #4
0
 def get_link(self, words):
     key = config.__dict__.get(u'IMGUR_ID', False)
     if key:
         imgur = Imgur(key)
         words = '/'.join(words)
         try:
             doge = imgur.upload_image(url="http://dogr.io/%s/wow.png" % words)
             return doge.link
         except:
             return "No upload, so unfulfil, much sad, very broken, wow"
Exemple #5
0
def upload_image_to_imgur(path):
    """
  Uploads an image file to imgur and returns the link
  --
  input:
    path: str
  --
  output:
    res: str
  """
    imgur = Imgur(Constants.IMGUR_CLIENT_ID)
    img = imgur.upload_image(path)
    return img.link
def get_authed_client():
    refresh_token = config.get(config.IMGUR_SECTION, 'refresh_token')
    if refresh_token:
        client = Imgur(client_id=config.IMGUR_CLIENT_ID,
                       client_secret=config.IMGUR_CLIENT_SECRET,
                       refresh_token=refresh_token)
    else:
        client = Imgur(client_id=config.IMGUR_CLIENT_ID,
                       client_secret=config.IMGUR_CLIENT_SECRET)
        auth_with_pin(client)

    try:
        access_token = client.refresh_access_token()
        config.set(config.IMGUR_SECTION, 'access_token', access_token)
    except Exception as e:
        print(e)
        print('Access token failed to refresh')
        auth_with_pin(client)
        client = Imgur(client_id=config.IMGUR_CLIENT_ID,
                       client_secret=config.IMGUR_CLIENT_SECRET,
                       refresh_token=config.get(config.IMGUR_SECTION,
                                                'refresh_token'))

    return client
Exemple #7
0
    async def send(self, ctx: Context, title: str, *, message: str) -> None:
        """Invia un embed."""
        try:
            colorcode = (await
                         self.db.find_one({"_id":
                                           "embedcolor-config"}))["colorcode"]
        except (KeyError, TypeError):
            colorcode = "0x3498DB"  # blue

        embed = Embed(
            title=title,
            description=message,
            color=Color(int(colorcode, 0)),
            timestamp=datetime.utcnow(),
        )

        embed.set_author(name=ctx.author.display_name,
                         icon_url=ctx.author.avatar_url)

        if len(ctx.message.attachments) == 1:
            try:
                imgur = Imgur("0f032be3851849a")
                image_url = ctx.message.attachments[0].url

                uploaded_image = imgur.upload_image(url=image_url,
                                                    title="Modmail")
                embed.set_image(url=uploaded_image.link)
            except BaseException:
                pass
        elif len(ctx.message.attachments) > 1:
            await ctx.message.delete()

            embed = Embed(
                title="Embedder",
                url=
                "https://github.com/Ergastolator1/fhmail-plugins/blob/master/embedder",
                description="Puoi solo usare un immagine per embed.",
                color=self.bot.main_color,
            )

            error: Message = await ctx.send(embed=embed)
            return await error.delete(5000)

        await ctx.send(embed=embed)
        await ctx.message.delete()
Exemple #8
0
def upload(config, tmp_dir):
    print('Uploading screens and sample videos...')
    links = {}
    imgur_client_id = config['imgur_client_id']
    imgur = Imgur(imgur_client_id)
    for i in range(1, 5):
        file = f'screen-0{i}.jpeg'
        path = os.path.join(tmp_dir, file)
        try:
            links[file] = imgur.upload_image(path).link
        except:
            sys.exit('Error uploading to Imgur! Exiting.')
    streamable_username = config['streamable_username']
    streamable_password = config['streamable_password']
    streamable = StreamableApi(streamable_username, streamable_password)
    for i in range(1, 3):
        file = f'sample-00{i}.mkv'
        path = os.path.join(tmp_dir, file)
        try:
            links[
                file] = f'https://streamable.com/{streamable.upload_video(path)["shortcode"]}'
        except:
            sys.exit('Error uploading to Streamable! Exiting.')
    return links
Exemple #9
0
from discord.ext import commands
from utils import Crombed, chance, is_mention, extract_id, random_string
from garlic_functions import (generate_scream, generate_screech, ProbDist,
                              string_to_bf, run_bf, ooojoy, generate_gibberish)
import usernumber
import random
import json
import zlib
import base64
import requests
import os
from pyimgur import Imgur

imgur = Imgur(os.environ["IMGUR_CLIENT_ID"])

REPLY_CHAIN_LENGTH = int(os.environ["REPLY_CHAIN_LENGTH"])


class GarlicCommands(commands.Cog):
    """ Commands made by garlicOS®! """
    def __init__(self, bot):
        self.bot = bot

    @commands.command(aliases=["aaa"])
    async def scream(self, ctx: commands.Context):
        """ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA """
        await ctx.send(generate_scream())

    @commands.command(aliases=["eee", "ree"])
    async def screech(self, ctx: commands.Context):
        """ EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE """