diff --git a/launch.py b/launch.py index 2d90f681ef988f61885518098266d62aeb2ba15f..04b9fc7c63203f8e3c7edff146bcb1bba3652b84 100644 --- a/launch.py +++ b/launch.py @@ -9,24 +9,36 @@ load_dotenv() TOKEN = os.getenv('DISCORD_TOKEN') SECRET = os.getenv('REDDIT_SECRET') -subreddit = praw.Reddit(client_id='yvXh2hrDELw6eg', \ - client_secret=SECRET, \ - user_agent='KumikoBot').subreddit('rarekumikos') -hot_subreddit = subreddit.hot(limit=500) - -totalimgs = 0 -posts = [] -authors = [] -posturls = [] -def refresh_posts(): - print('Refreshing posts!') - posts.clear() - authors.clear() - posturls.clear() - global totalimgs - totalimgs=0 +subreddits = dict() + +class Entry: + name = "" + subName = "" + #subreddit + #hot_subredditu + + totalimgs = 0 + posts = [] + authors = [] + posturls = [] + + def __init__(name, subName): + self.subreddit = praw.Reddit( client_id='yvXh2hrDELw6eg', \ + client_secret=SECRET, \ + user_agent='SMAW').subreddit(subName) + hot_subreddit = self.subreddit.hot(limit=500) + + + + +def refresh_posts(entry): + print('Refreshing posts for ' + entry.name + '!') + entry.posts.clear() + entry.authors.clear() + entry.posturls.clear() + entry.totalimgs=0 i=0 - for submission in subreddit.hot(limit=500): + for submission in entry.subreddit.hot(limit=500): #_ = os.system('clear') i = i + 1 totalimgs = totalimgs + 1 @@ -36,11 +48,15 @@ def refresh_posts(): print(str(submission.url)) totalimgs = totalimgs - 1 continue - posts.append(submission.url) - authors.append(submission.author) - posturls.append(submission.permalink) + entry.posts.append(submission.url) + entry.authors.append(submission.author) + entry.posturls.append(submission.permalink) print('Total amount of images: '+str(totalimgs)) +def refresh_all_posts(): + for entry in subreddits: + refresh_posts(entry) + def create_embed(post,author,posturl): embed = discord.Embed( @@ -50,8 +66,7 @@ def create_embed(post,author,posturl): embed.description ='['+str(author)+'](https://www.reddit.com'+str(posturl)+')' return embed -refresh_posts() - +refresh_all_posts() client = discord.Client() @client.event @@ -62,9 +77,10 @@ async def on_ready(): async def on_message(message): if message.author == client.user: return - if "showmeakumiko" in message.content.lower().replace(' ',''): - postnumber = random.randint(1,totalimgs) - await message.channel.send(embed = create_embed(posts[postnumber],authors[postnumber],posturls[postnumber])) + if "showmea" in message.content.lower().replace(' ',''): + if name in subreddits: + 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_posts()