From fb3e212f543f3e029f2843af9339880a62519bf5 Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Thu, 24 Oct 2024 14:19:12 -0700 Subject: [PATCH] good enough, fuckin wwith the get_from_reddit stuff mainly for sheebs --- app/animals.py | 3 ++- app/cogs/animal_functions.py | 3 ++- app/get_from_reddit.py | 29 +++++++++++++++++------------ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/animals.py b/app/animals.py index 6624e909..77961f2a 100755 --- a/app/animals.py +++ b/app/animals.py @@ -20,7 +20,8 @@ def get_dog(): 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(): diff --git a/app/cogs/animal_functions.py b/app/cogs/animal_functions.py index 6c19b175..0c7d4c07 100755 --- a/app/cogs/animal_functions.py +++ b/app/cogs/animal_functions.py @@ -23,7 +23,8 @@ class AnimalFunctions(commands.Cog): guild_ids=None, name="sheeb", description="Posts a photo of a Sheeb" ) 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( guild_ids=None, name="cowboy", description="Posts a photo of a bad dog" diff --git a/app/get_from_reddit.py b/app/get_from_reddit.py index 9c8d021f..5664e5c8 100755 --- a/app/get_from_reddit.py +++ b/app/get_from_reddit.py @@ -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 """ - if isinstance(boards, list): - boards = random.choice(boards) - domains = [ "cdn.awwni.m", "gfycat.com", @@ -26,11 +23,6 @@ def get_image(boards, nsfw=False): "v.redd.it", "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 random_user_agent = "".join( @@ -38,13 +30,26 @@ def get_image(boards, nsfw=False): 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( request_string, headers={"User-agent": random_user_agent} ).json()[0]["data"]["children"][0]["data"] - if response["secure_media"]: - image_url = response["secure_media"]["reddit_video"]["fallback_url"] - elif response["domain"] in domains: - image_url = response["url_overridden_by_dest"] + import pprint + + pprint.pprint(response, indent=2) + + image_url = "https://rxddit.com" + response["permalink"] + + if "youtu.be" in response["url"]: + image_url = response["url"] return image_url