diff --git a/launch.py b/launch.py index 21b236976ddfff40ab7b0a7dba7ea6b0264e12e0..664e34b1a9a0d368df83049601d29d209ba7cf2e 100644 --- a/launch.py +++ b/launch.py @@ -31,6 +31,12 @@ class Entry: client_secret=SECRET, \ user_agent=REDDIT_AGENT).subreddit(subName) hot_subreddit = self.subreddit.hot(limit=500) + self.name = name + self.subName = subName + +subreddits['kumiko'] = Entry('kumiko', 'rarekumikos') +subreddits['araragi'] = Entry('araragi', 'araragi') +subreddits['hitagi'] = Entry('hitagi', 'Senjougahara') @@ -42,23 +48,23 @@ def refresh_posts(entry): entry.posturls.clear() entry.totalimgs=0 i=0 - for submission in entry.subreddit.hot(limit=500): + for submission in entry.subreddit.hot(limit=100): #_ = os.system('clear') i = i + 1 - totalimgs = totalimgs + 1 + entry.totalimgs = entry.totalimgs + 1 print('Getting submission number '+ str(i) +' / 500!') if ".jpg" not in submission.url and ".png" not in submission.url: print('Post is not a jpg or png --------------------------') print(str(submission.url)) - totalimgs = totalimgs - 1 + entry.totalimgs = entry.totalimgs - 1 continue entry.posts.append(submission.url) entry.authors.append(submission.author) entry.posturls.append(submission.permalink) - print('Total amount of images: '+str(totalimgs)) + print('Total amount of images: '+str(entry.totalimgs)) def refresh_all_posts(): - for entry in subreddits: + for entry in subreddits.values(): refresh_posts(entry) @@ -82,17 +88,21 @@ async def on_message(message): if message.author == client.user: return if "show me a" in message.content.lower(): - name = re.search(r"show me a ([\S]+)", message) + name = re.search(r"show me a ([\S]+)", message.content.lower()) if name == None: return else: name = name.group(1) - if name in subreddits: + if name in subreddits.keys(): + print('asking for the following entry:') + print(name) + print(subreddits[name].name) + print(subreddits[name].subName) postnumber = random.randint(1,subreddits[name].totalimgs) await message.channel.send(embed = create_embed(subreddits[name].posts[postnumber], subreddits[name].authors[postnumber], subreddits[name].posturls[postnumber])) - if "refresh the kumikos" in message.content.lower(): - refresh_all_posts() + #if "refresh the kumikos" in message.content.lower(): + # refresh_all_posts() client.run(TOKEN)