Browse Source

added a check for the imgur token incase come cheeky bugger trys to run it without one

tags/v2.0.0
Roxie Gibson 5 years ago
parent
commit
9724e29bbf
1 changed files with 6 additions and 2 deletions
  1. +6
    -2
      roxbot/cogs/reddit.py

+ 6
- 2
roxbot/cogs/reddit.py View File

class Scrapper: class Scrapper:
"""Scrapper is a class to aid in the scrapping of reddit subreddit's of images. (includes small amount of video support) """Scrapper is a class to aid in the scrapping of reddit subreddit's of images. (includes small amount of video support)
This includes its own caching system.""" This includes its own caching system."""
# TODO: Reimplement eroshare, eroshae, and erome support. Also implement better api interaction with imgur now we require api key
# TODO: Reimplement eroshare, eroshae, and erome support.
# Also implement better api interaction with imgur now we require api key
def __init__(self, cache_limit=10): def __init__(self, cache_limit=10):
self.post_cache = {} self.post_cache = {}
self.cache_limit = cache_limit self.cache_limit = cache_limit


@staticmethod @staticmethod
async def sub_request(subreddit): async def sub_request(subreddit):
# TODO: Incorperate /random.json for better random results
options = [".json?count=1000", "/top/.json?sort=top&t=all&count=1000"] options = [".json?count=1000", "/top/.json?sort=top&t=all&count=1000"]
choice = random.choice(options) choice = random.choice(options)
subreddit += choice subreddit += choice
url = "https://reddit.com/r/" + subreddit url = "https://reddit.com/r/" + subreddit
r = await roxbot.http.api_request(url)
try: try:
r = await roxbot.http.api_request(url)
posts = r["data"] posts = r["data"]
# This part is to check for some common errors when doing a sub request # This part is to check for some common errors when doing a sub request
# t3 is a post in a listing. We want to avoid not having this instead of a subreddit search, which would be t5. # t3 is a post in a listing. We want to avoid not having this instead of a subreddit search, which would be t5.
def __init__(self, bot_client): def __init__(self, bot_client):
self.bot = bot_client self.bot = bot_client
self.scrapper = Scrapper() self.scrapper = Scrapper()
if not roxbot.imgur_token:
print("REDDIT COG REQUIRES A IMGUR API TOKEN. Without this, roxbot will not return imgur links.")


@commands.command() @commands.command()
@commands.has_permissions(add_reactions=True) @commands.has_permissions(add_reactions=True)

Loading…
Cancel
Save