예제 #1
0
async def random_image(context):
    log(context)
    if (str(context.message.channel.type) == "private"
            or context.message.channel.is_nsfw()):
        try:
            msg_content = {
                "file":
                discord.File(IMG_FOLDER + "/{}".format(rdm(IMG_FOLDER)))
            }
        except FileNotFoundError:
            DISPLAY_ERROR("The folder `{}` was not found".format(IMG_FOLDER))
            msg_content = {
                "content": "The folder with images is missing, sorry..."
            }
        except ValueError:
            DISPLAY_ERROR("The folder `{}` is empty".format(IMG_FOLDER))
            msg_content = {"content": "The folder with images is totaly empty"}
    else:
        msg_content = {"content": "Sorry, this channel isn't a NSFW channel"}

    try:
        await context.send(**msg_content)
    except:
        DISPLAY_ERROR("Somethings went wrong")
        msg_content = {
            "content": "Somethings went wrons, sorry.\n┬─┬ ︵ /(.□. \)"
        }
        await context.send(**msg_content)
예제 #2
0
def make_answer():
    """Create the message to send"""
    # Create the message and set a subject
    msg = EmailMessage()
    msg["Subject"] = "A random image."

    try:
        # Choose an image
        attachement = IMG_FOLDER + "/" + rdm(IMG_FOLDER)
        # Attach the image to the email
        with open(attachement, "rb") as img:
            img = img.read()
            msg.add_attachment(img,
                               maintype="image",
                               subtype=imghdr.what(None, img))
    except Exception as err:
        msg.set_content("No image found")
        if isinstance(err, FileNotFoundError):
            DISPLAY_ERROR("`{}` directory is not found".format(IMG_FOLDER))
        elif isinstance(err, ValueError):
            DISPLAY_ERROR("`{}` directory is empty".format(IMG_FOLDER))
        else:
            DISPLAY_ERROR("An error occurred")

    return msg
예제 #3
0
async def send_img(folder, context):
    log(context)
    try:
        msg_content = {
            "file": discord.File(
                folder + "/{}".format(rdm(folder))
            )
        }
    except FileNotFoundError:
        DISPLAY_ERROR("The folder `{}` was not found".format(folder))
        msg_content = {
            "content": "The folder with images is missing, sorry..."
        }
    except ValueError:
        DISPLAY_ERROR("The folder `{}` is empty".format(folder))
        msg_content = {"content": "The folder with images is totaly empty"}

    try:
        await context.send(**msg_content)
    except:
        DISPLAY_ERROR("Somethings went wrong")
        msg_content = {"content": "Somethings went wrongs, sorry.\n┬─┬ ︵ /(.□. \)"}
        await context.send(**msg_content)
예제 #4
0
def img():
    try:
        pics = rdm(IMG_FOLDER)
        content = "<img src='image/{image}' style='max-width: 100vw; max-height: 100vh;'>".format(image=pics)
    except FileNotFoundError:
        content = "Sorry, the folder with the images is not present"
    except ValueError:
        content = "There is currently no images"

    return """
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>RIS</title>
    </head>
    <body>
        <center>
            {content}
        </center>
    </body>
</html>
    """.format(content=content)