From f8091a490edf8603f06ce5c9bd59907313641f37 Mon Sep 17 00:00:00 2001 From: Angerstoner Date: Mon, 11 Feb 2019 02:53:04 +0100 Subject: [PATCH] first version of /wrongdog --- misc/requirements.txt | 2 +- reddit.py | 24 ++++++++++++++++++++++++ schneiderbot.py | 4 +++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/misc/requirements.txt b/misc/requirements.txt index bc12aa3..1fe07ed 100644 --- a/misc/requirements.txt +++ b/misc/requirements.txt @@ -1,5 +1,5 @@ python-telegram-bot telegram requests -random-cat git+git://github.com/xNinjaKittyx/pydog.git#egg=pydog +praw \ No newline at end of file diff --git a/reddit.py b/reddit.py index e69de29..504a387 100644 --- a/reddit.py +++ b/reddit.py @@ -0,0 +1,24 @@ +import praw + + +def get_reddit_instance(): + reddit_config = {} + with open("reddit_config") as tmp_file: + for line in tmp_file: + (key, val) = line.split(';') + reddit_config[key] = val.replace('\n', '') + + return praw.Reddit( + user_agent=reddit_config['user_agent'], + client_id=reddit_config['client_id'], + client_secret=reddit_config['client_secret'] + ) + + +def wrong_dog(bot, update): + reddit = get_reddit_instance() + + sub = reddit.subreddit('whatswrongwithyourdog') + post = sub.random() + update.message.reply_text("This dog has serious issues: %s" % post.url) + diff --git a/schneiderbot.py b/schneiderbot.py index c4b3dac..3759be6 100755 --- a/schneiderbot.py +++ b/schneiderbot.py @@ -10,6 +10,7 @@ from telegram import ParseMode from telegram.ext import Updater, CommandHandler from coding_love import send_coding_love_gif +from reddit import wrong_dog from db import Db from mensa import mensa @@ -187,7 +188,7 @@ def error(bot, update, error): def main(): """Start the bot.""" # Create the EventHandler and pass it your bot's token. - token = open("token").read() + token = open("test_token").read() updater = Updater(token.strip()) # Get the dispatcher to register handlers @@ -210,6 +211,7 @@ def main(): dp.add_handler(CommandHandler("simon", simon, pass_args=True)) dp.add_handler(CommandHandler("graveyard", graveyard)) dp.add_handler(CommandHandler("codinglove", send_coding_love_gif)) + dp.add_handler(CommandHandler("wrongdog", wrong_dog)) # log all errors dp.add_error_handler(error)