79 lines
2.2 KiB
Python
Executable File
79 lines
2.2 KiB
Python
Executable File
import requests
|
|
import discord
|
|
|
|
my_guilds = [826547484632678450, 152921472304676865]
|
|
my_id = 144986109804412928
|
|
|
|
|
|
def download_image(url, path=None):
|
|
request = requests.get(url)
|
|
suffix_list = [
|
|
"jpeg",
|
|
"jpg",
|
|
"png",
|
|
"tif",
|
|
"svg",
|
|
]
|
|
extension = request.headers["content-type"].split("/")[1]
|
|
|
|
if not path:
|
|
path = "/tmp/image.{}".format(extension)
|
|
|
|
if extension in suffix_list:
|
|
open(path, "wb").write(requests.get(url).content)
|
|
return path
|
|
return "Invalid image format"
|
|
|
|
|
|
def generate_embed(
|
|
embed_url=None,
|
|
embed_title=None,
|
|
embed_description=None,
|
|
embed_color=None,
|
|
author_name=None,
|
|
author_image=None,
|
|
):
|
|
"""
|
|
generate_embed(embed_url=None, embed_title=None, embed_description=None, embed_color=None)
|
|
|
|
Generates a discord embed object based on the URL passed in
|
|
Optionally, you can set the title and description text for the embed object.
|
|
"""
|
|
|
|
if not embed_description and embed_url:
|
|
embed_description = "[Direct Link]({})".format(embed_url)
|
|
|
|
if not embed_color:
|
|
embed_color = discord.Color.gold()
|
|
|
|
embed = discord.Embed(
|
|
title=embed_title, description=embed_description, color=embed_color, type="rich"
|
|
)
|
|
if embed_url:
|
|
embed.set_image(url=embed_url)
|
|
|
|
if author_image or author_name:
|
|
embed.set_author(name=author_name, icon_url=author_image)
|
|
|
|
return embed
|
|
|
|
|
|
def gen_username():
|
|
from bs4 import BeautifulSoup
|
|
|
|
url = "https://generatorfun.com/code/model/generatorcontent.php?recordtable=generator&recordkey=960&gen=Y&itemnumber=1&randomoption=undefined&genimage=Yes&geneditor=No&nsfw=undefined&keyword=undefined&searchfilter=&searchfilterexclude=&tone=Normal&prefix=None&randomai=undefined"
|
|
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)"}
|
|
response = requests.get(url, headers=headers).text
|
|
soup = BeautifulSoup(response, "html.parser")
|
|
|
|
username = soup.find("div", {"id": "gencont"}).div.find("p").text
|
|
return username
|
|
|
|
|
|
def waifu_pics(endpoint, nsfw=False):
|
|
pic_type = "nsfw" if nsfw else "sfw"
|
|
|
|
return requests.get("https://api.waifu.pics/%s/%s" % (pic_type, endpoint)).json()[
|
|
"url"
|
|
]
|