python类forwarded()的实例源码

telegrambot.py 文件源码 项目:django-telegrambot 作者: JungDev 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def main():
    logger.info("Loading handlers for telegram bot")

    # Default dispatcher (this is related to the first bot in settings.TELEGRAM_BOT_TOKENS)
    dp = DjangoTelegramBot.dispatcher
    # To get Dispatcher related to a specific bot
    # dp = DjangoTelegramBot.getDispatcher('BOT_n_token')     #get by bot token
    # dp = DjangoTelegramBot.getDispatcher('BOT_n_username')  #get by bot username

    # on different commands - answer in Telegram
    dp.add_handler(CommandHandler("start", start))
    dp.add_handler(CommandHandler("help", help))

    dp.add_handler(CommandHandler("startgroup", startgroup))
    dp.add_handler(CommandHandler("me", me))
    dp.add_handler(CommandHandler("chat", chat))
    dp.add_handler(MessageHandler(Filters.forwarded , forwarded))

    # on noncommand i.e message - echo the message on Telegram
    dp.add_handler(MessageHandler(Filters.text, echo))

    # log all errors
    dp.add_error_handler(error)
grammarnazibot.py 文件源码 项目:GrammarNaziBot 作者: SlavMetal 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def main():
    updater = Updater(cfg['botapi_token'])
    dp = updater.dispatcher

    dp.add_handler(CommandHandler("start", start))
    dp.add_handler(CommandHandler("help", help))
    dp.add_handler(CommandHandler("ping", ping))

    # on no command
    dp.add_handler(MessageHandler(Filters.text & (~ Filters.forwarded), echo))  # Message is text and is not forwarded

    # log all errors
    dp.add_error_handler(error)

    # Start the Bot
    updater.start_polling()

    # Run the bot until process receives SIGINT, SIGTERM or SIGABRT
    updater.idle()
FeedbackBot.py 文件源码 项目:TelegramBots 作者: d-qoi 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def statusReceived(bot, update):
    logger.debug("Message Received")

    if update.message.new_chat_member and update.message.new_chat_member.username == bot.username:
        logger.info("Added To Chat %s (%s)" %(update.message.chat.title, update.message.chat.id))
        newGroup = dict()
        chat = update.message.chat
        #newGroup['_id'] = chat.id
        newGroup['title'] = chat.title
        newGroup['admins'] = [chatmember.user.id for chatmember in chat.get_administrators()]
        logger.debug("newGroup: %s" % newGroup)

        MDB.groups.update({'_id':chat.id}, newGroup, upsert=True)
        logger.info("Added %s to the group list" % update.message.chat.title)

    elif update.message.new_chat_member:
        updateGroupData(update)
        logger.info("New member joined the chat.")
        update.message.reply_text(WELCOMETEXT, quote=False)

    elif update.message.left_chat_member and update.message.left_chat_member.username == bot.username:
        MDB.groups.remove({'_id':update.message.chat.id})
        logger.info("Removing entry for %s" % (update.message.chat.title))

# When a user sends a message, it is forwarded to everyone with this method.
telegrambot.py 文件源码 项目:django-telegrambot 作者: JungDev 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def forwarded(bot, update):
    bot.sendMessage(update.message.chat_id, text='This msg forwaded information:\n {}'.format(update.effective_message))


问题


面经


文章

微信
公众号

扫码关注公众号