def selective_reddit(bot: t.Bot, context: t.update, args): global sent_video_count params = [] for arg in args: params.append(arg) try: params[1] post_type = True except IndexError: post_type = None sub_name = str(params[0]).lower() if post_type == True: post_type = str(params[1]).lower() if post_type == None: request = reddit.random(sub_name=sub_name, post_type=None, video_name=sent_video_count) elif post_type == "image" or post_type == "photo": request = reddit.random(sub_name=sub_name, post_type=reddit.IMAGE) elif post_type == "text": request = reddit.random(sub_name=sub_name, post_type=reddit.TEXT) elif post_type == "video": request = reddit.random(sub_name=sub_name, post_type=reddit.VIDEO) post_type = request["type"] message = request["value"] if post_type == reddit.IMAGE: msg_info = bot.send_photo( chat_id=config.chat_id(context=context), photo=message ) elif post_type == reddit.VIDEO: try: video=open(path, "rb") msg_info = bot.send_video( chat_id=config.chat_id(context=context), video=video, supports_streaming=True ) except Exception as e: print(f"{type(e).__name__}\t {e}") finally: sent_video_count += 1 video.close() os.remove(message) else: msg_info = bot.send_message( chat_id=config.chat_id(context=context), text=message ) config.save_history(msg_info, "selective reddit")
def dad(bot: t.Bot, context: t.update): sentence = reddit.random("dadjokes", reddit.TEXT)["value"] msg_info = bot.send_message( chat_id=config.chat_id(context=context), text=sentence ) config.save_history(msg_info, "dad joke")
def horror(bot: t.Bot, context: t.update): sentence = reddit.random("twosentencehorror", reddit.TEXT)["value"] msg_info = bot.send_message( chat_id=config.chat_id(context=context), text=sentence ) config.save_history(msg_info, "two sentence horror")
def pun(bot: t.Bot, context: t.update): img_url = reddit.random("puns", reddit.IMAGE)["value"] msg_info = bot.send_photo( chat_id=config.chat_id(context=context), photo=img_url ) config.save_history(msg_info, "pun")
def shower(bot: t.Bot, context: t.update): sentence = reddit.random("showerthoughts", reddit.TEXT)["value"] msg_info = bot.send_message( chat_id=config.chat_id(context=context), text=sentence ) config.save_history(msg_info, "shower thought")
def meme(bot: t.Bot, context: t.update): sub_name = "memes" if reddit.r.randint(1,2) == 2: sub_name = "dankmemes" img_url = reddit.random(sub_name, reddit.IMAGE)["value"] msg_info = bot.send_photo( chat_id=config.chat_id(context=context), photo=img_url ) config.save_history(msg_info, "meme")