diff --git a/reddit.py b/reddit.py index d4abcdc..2dfbd69 100644 --- a/reddit.py +++ b/reddit.py @@ -1,7 +1,8 @@ import praw from prawcore import exceptions import requests -import random + +four_twenty_groups = [] def get_post_type(url): @@ -54,13 +55,21 @@ def get_reddit_post(sub, is_image_post=False): return post -# def fourtwenty(bot, update): -def fourtwenty(): - stoner_subs = ["StonerThoughts"] - # post = get_reddit_post(random.randint(0, len(stoner_subs) - 1)) - post = get_reddit_post("StonerThoughts") - print(post.title) - print(post.text) +def toggle_four_twenty(bot, update): + chat_id = update.message.chat_id + + if chat_id in four_twenty_groups: + four_twenty_groups.remove(chat_id) + update.message.reply_text("You killed the fire!") + else: + four_twenty_groups.append(update.message.chat_id) + update.message.reply_text("420 blaze it!") + + +def four_twenty(bot, update): + for group_id in four_twenty_groups: + post = get_reddit_post('trees', True) + bot.send_photo(chat_id=group_id, photo=post.url, caption=post.title) def wrong_dog(bot, update): @@ -93,5 +102,3 @@ def reddit_img(bot, update, args): except AttributeError: update.message.reply_text(post) print("ERROR") - -# fourtwenty()y diff --git a/schneiderbot.py b/schneiderbot.py index 6b15b1e..53daf85 100755 --- a/schneiderbot.py +++ b/schneiderbot.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- - +import datetime import logging import random @@ -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, reddit_img +from reddit import wrong_dog, hamster, reddit, reddit_img, toggle_four_twenty, four_twenty from schneiderbot_twitter import toggle_pepito_for_group, check_pepito_and_post_auto, check_pepito_and_post_manually from db import Db from mensa import mensa @@ -209,6 +209,7 @@ def init_commands(dp): dp.add_handler(CommandHandler("reddit_img", reddit_img, pass_args=True)) dp.add_handler(CommandHandler("pepito", check_pepito_and_post_manually)) dp.add_handler(CommandHandler("tpepito", toggle_pepito_for_group)) + dp.add_handler(CommandHandler("lightitup", toggle_four_twenty)) def main(): @@ -224,7 +225,8 @@ def main(): dp = updater.dispatcher init_commands(dp) - job_minute = jq.run_repeating(check_pepito_and_post_auto, interval=180, first=0) + jq.run_repeating(check_pepito_and_post_auto, interval=180, first=0) + jq.run_daily(four_twenty, datetime.time(4, 20, 0), days=(0, 1, 2, 3, 4, 5, 6)) # on different commands - answer in Telegram