示例#1
0
def init_news(bot, update, args=None):
    chat_id, chat_type, user_id, text, message = support.extract_update_info(
        update)
    support.delete_message(chat_id, message.message_id, bot)

    if chat_type != "channel":
        return

    if hasattr(message.chat, 'username') and message.chat.username is not None:
        alias = message.chat.username
    elif args is not None and len(args) != 0:
        alias = args[0]
    else:
        output = "❌ He reconocido este canal como un canal privado y no me has especificado un nombre para el canal."
        bot.sendMessage(chat_id=chat_id, text=output)
        return

    if not news_sql.is_news_provider(chat_id):
        news_sql.set_news_provider(chat_id, alias)

    output = (
        "📰 Bienvenido al sistema de noticias de @ProfesorDumbledoreBot.\nYa tan solo "
        "queda el último paso. Ejecuta `/add_news {}` en los grupos que quie"
        "ras recibir las noticias de este canal.".format(chat_id))
    bot.sendMessage(chat_id=chat_id,
                    text=output,
                    parse_mode=telegram.ParseMode.MARKDOWN)
示例#2
0
def send_news(bot, update):
    chat_id, chat_type, user_id, text, message = support.extract_update_info(
        update)

    if chat_type != "channel":
        return

    if not news_sql.is_news_provider(chat_id):
        return

    time.sleep(60)

    groups = news_sql.get_news_consumers(chat_id)
    if groups is None:
        return

    exceptions_users = []
    for k in groups:
        time.sleep(0.2)
        try:
            bot.forwardMessage(chat_id=k.user_id,
                               from_chat_id=chat_id,
                               message_id=message.message_id)
        except Exception:
            exceptions_users.append(k.user_id)
            logging.info('sendingMessageTo:FAILURE->: %s', k.user_id)

    for k in exceptions_users:
        news_sql.rm_all_news_subscription(k)
示例#3
0
def stop_news(bot, update):
    chat_id, chat_type, user_id, text, message = support.extract_update_info(update)
    support.delete_message(chat_id, message.message_id, bot)

    if chat_type != "channel":
        return

    if news_sql.is_news_provider(chat_id):
        news_sql.rm_news_provider(chat_id)
        output = "✅ ¡Canal eliminado correctamente!"
    else:
        output = "❌ No he reconocido este canal como proveedor de noticias."

    bot.sendMessage(chat_id=chat_id, text=output)
示例#4
0
def add_news(bot, update, args=None):
    chat_id, chat_type, user_id, text, message = support.extract_update_info(update)
    support.delete_message(chat_id, message.message_id, bot)

    if not support.is_admin(chat_id, user_id, bot) or are_banned(user_id, chat_id):
        return

    if args is None or len(args)!=1:
        return

    output = "❌ No he reconocido este canal como proveedor de noticias."

    if news_sql.is_news_provider(args[0]) and not news_sql.is_news_subscribed(chat_id, args[0]):
        news_sql.set_news_subscription(chat_id, args[0])
        output = "✅ ¡Suscripción realizada correctamente!"

    bot.sendMessage(chat_id=chat_id, text=output)