From fd14fa4c5e87d133fa42a7a875874568652656f2 Mon Sep 17 00:00:00 2001 From: Elliu <goyard.louis@gmail.com> Date: Mon, 21 Dec 2020 21:08:36 +0100 Subject: [PATCH] Should now kinda work, needs debug --- .gitignore | 1 + launch.py | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c49bd7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.env diff --git a/launch.py b/launch.py index 04b9fc7..21b2369 100644 --- a/launch.py +++ b/launch.py @@ -2,12 +2,16 @@ import discord import os import praw import random +import re from dotenv import load_dotenv + load_dotenv() TOKEN = os.getenv('DISCORD_TOKEN') SECRET = os.getenv('REDDIT_SECRET') +REDDIT_ID = os.getenv('REDDIT_ID') +REDDIT_AGENT = os.getenv('REDDIT_AGENT') subreddits = dict() @@ -15,17 +19,17 @@ class Entry: name = "" subName = "" #subreddit - #hot_subredditu + #hot_subreddit totalimgs = 0 posts = [] authors = [] posturls = [] - def __init__(name, subName): - self.subreddit = praw.Reddit( client_id='yvXh2hrDELw6eg', \ + def __init__(self, name, subName): + self.subreddit = praw.Reddit( client_id=REDDIT_ID, \ client_secret=SECRET, \ - user_agent='SMAW').subreddit(subName) + user_agent=REDDIT_AGENT).subreddit(subName) hot_subreddit = self.subreddit.hot(limit=500) @@ -77,12 +81,18 @@ async def on_ready(): async def on_message(message): if message.author == client.user: return - if "showmea" in message.content.lower().replace(' ',''): + if "show me a" in message.content.lower(): + name = re.search(r"show me a ([\S]+)", message) + if name == None: + return + else: + name = name.group(1) + 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() + refresh_all_posts() client.run(TOKEN) -- GitLab