Browse Source

added reddit img command

master
Angerstoner 6 years ago
parent
commit
1462089c42
  1. 4
      misc/commandlist
  2. 24
      reddit.py
  3. 7
      schneiderbot.py

4
misc/commandlist

@ -1,8 +1,12 @@
mensa - [TAG/full/veggy/fleisch/fisch] essen in der mensa, filter möglich
cat - cat pic
dog - dog pic
wrongdog - post from /r/whatswrongwithyourdog
hamster - hamster pic
catdog - catdog pic
codinglove - random gif from the coding love
reddit - [sub] random post from given subreddit
reddit_img - [sub] random image post from given subreddit
manta - boah ey, geile Karre!
magie - Magie ist Physik durch wollen
kill - kill me pls

24
reddit.py

@ -33,13 +33,7 @@ def wrong_dog(bot, update):
def hamster(bot, update):
reddit_instance = get_reddit_instance()
sub = reddit_instance.subreddit('hamsters')
post = sub.random()
while "image" not in get_post_type(post.url):
post = sub.random()
bot.send_photo(chat_id=update.message.chat_id, photo=post.url)
reddit_img(bot, update, ['hamsters'])
def reddit(bot, update, args):
@ -51,3 +45,19 @@ def reddit(bot, update, args):
post = reddit_instance.subreddit(sub).random()
update.message.reply_text(post.url)
def reddit_img(bot, update, args):
print(args)
if not args:
update.message.reply_text("Geile, sag sub")
return
desired_sub = args[0]
reddit_instance = get_reddit_instance()
sub = reddit_instance.subreddit(desired_sub)
post = sub.random()
while "image" not in get_post_type(post.url):
post = sub.random()
bot.send_photo(chat_id=update.message.chat_id, photo=post.url)

7
schneiderbot.py

@ -10,7 +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, hamster, reddit
from reddit import wrong_dog, hamster, reddit, reddit_img
from db import Db
from mensa import mensa
@ -205,13 +205,14 @@ def init_commands(dp):
dp.add_handler(CommandHandler("wrongdog", wrong_dog))
dp.add_handler(CommandHandler("hamster", hamster))
dp.add_handler(CommandHandler("reddit", reddit, pass_args=True))
dp.add_handler(CommandHandler("reddit_img", reddit_img, pass_args=True))
def main():
"""Start the bot."""
# Create the EventHandler and pass it your bot's token.
token = open("token").read()
# token = open("test_token").read()
# token = open("token").read()
token = open("test_token").read()
updater = Updater(token.strip())
# Get the dispatcher to register handlers

Loading…
Cancel
Save