good enough, fuckin wwith the get_from_reddit stuff mainly for sheebs
This commit is contained in:
parent
fd8f539872
commit
54825892a8
@ -20,7 +20,8 @@ def get_dog():
|
|||||||
|
|
||||||
|
|
||||||
def random_sheeb():
|
def random_sheeb():
|
||||||
return requests.get("http://shibe.online/api/shibes?count=1&urls=true").json()[0]
|
# return requests.get("http://shibe.online/api/shibes?count=1&urls=true").json()[0]
|
||||||
|
return get_from_reddit.get_image(["shiba", "shibe", "shibainu"])
|
||||||
|
|
||||||
|
|
||||||
def random_dog():
|
def random_dog():
|
||||||
|
@ -23,7 +23,8 @@ class AnimalFunctions(commands.Cog):
|
|||||||
guild_ids=None, name="sheeb", description="Posts a photo of a Sheeb"
|
guild_ids=None, name="sheeb", description="Posts a photo of a Sheeb"
|
||||||
)
|
)
|
||||||
async def sheeb(self, ctx: commands.Context):
|
async def sheeb(self, ctx: commands.Context):
|
||||||
await ctx.respond(animals.random_sheeb())
|
await ctx.defer()
|
||||||
|
await ctx.send_followup(animals.random_sheeb())
|
||||||
|
|
||||||
@commands.slash_command(
|
@commands.slash_command(
|
||||||
guild_ids=None, name="cowboy", description="Posts a photo of a bad dog"
|
guild_ids=None, name="cowboy", description="Posts a photo of a bad dog"
|
||||||
|
@ -11,9 +11,6 @@ def get_image(boards, nsfw=False):
|
|||||||
as long as it is hosted on one of the domains in the domains list
|
as long as it is hosted on one of the domains in the domains list
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if isinstance(boards, list):
|
|
||||||
boards = random.choice(boards)
|
|
||||||
|
|
||||||
domains = [
|
domains = [
|
||||||
"cdn.awwni.m",
|
"cdn.awwni.m",
|
||||||
"gfycat.com",
|
"gfycat.com",
|
||||||
@ -26,11 +23,6 @@ def get_image(boards, nsfw=False):
|
|||||||
"v.redd.it",
|
"v.redd.it",
|
||||||
"reddit.com",
|
"reddit.com",
|
||||||
]
|
]
|
||||||
request_string = "https://reddit.com/r/{}/random.json".format(boards)
|
|
||||||
|
|
||||||
if not nsfw:
|
|
||||||
# Append this header to the request. Tells the API to only return SFW results
|
|
||||||
request_string += "?obey_over18=true"
|
|
||||||
|
|
||||||
# Spoof our user agent with each request so we dont get rate limited
|
# Spoof our user agent with each request so we dont get rate limited
|
||||||
random_user_agent = "".join(
|
random_user_agent = "".join(
|
||||||
@ -38,13 +30,26 @@ def get_image(boards, nsfw=False):
|
|||||||
for _ in range(5)
|
for _ in range(5)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if isinstance(boards, list):
|
||||||
|
boards = random.choice(boards)
|
||||||
|
|
||||||
|
request_string = f"https://reddit.com/r/{boards}/random.json"
|
||||||
|
|
||||||
|
if not nsfw:
|
||||||
|
# Append this header to the request. Tells the API to only return SFW results
|
||||||
|
request_string += "?obey_over18=true"
|
||||||
|
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
request_string, headers={"User-agent": random_user_agent}
|
request_string, headers={"User-agent": random_user_agent}
|
||||||
).json()[0]["data"]["children"][0]["data"]
|
).json()[0]["data"]["children"][0]["data"]
|
||||||
|
|
||||||
if response["secure_media"]:
|
import pprint
|
||||||
image_url = response["secure_media"]["reddit_video"]["fallback_url"]
|
|
||||||
elif response["domain"] in domains:
|
pprint.pprint(response, indent=2)
|
||||||
image_url = response["url_overridden_by_dest"]
|
|
||||||
|
image_url = "https://rxddit.com" + response["permalink"]
|
||||||
|
|
||||||
|
if "youtu.be" in response["url"]:
|
||||||
|
image_url = response["url"]
|
||||||
|
|
||||||
return image_url
|
return image_url
|
||||||
|
Loading…
x
Reference in New Issue
Block a user