chatter.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:Sarabot 作者: AlexR1712 项目源码 文件源码
def chatter(bot,update):

    chat_id = update.message.chat_id
    message = update.message.text
    if message == 'foto':
        bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.UPLOAD_PHOTO)
        bot.sendPhoto(chat_id=chat_id, photo='https://unsplash.it/600?random')
    else:
        k = aiml.Kernel()
        k.learn("std-startup.xml")
        k.respond("sara")
        k.setBotPredicate("name", "Sara")
        k.setBotPredicate("anyo_nacimiento", "2015")
        k.setBotPredicate("edad", str(date.today().year-2015) )
        k.setBotPredicate("botmaster", 'Alexander' )
        k.setBotPredicate("nombre_bot", 'Sara' )
        k.setBotPredicate("birthday", '17/12/2015' )
        bot.sendChatAction(chat_id=chat_id, action=telegram.ChatAction.TYPING)
        response = k.respond(message)    
        #bot.sendMessage(chat_id, text=response)
        tts = gTTS(text=response, lang='es') 

        file = str(chat_id) + str(time.time()) + '.ogg'
        tts.save(file)
        bot.sendVoice(chat_id=chat_id, voice=open(file, 'rb'))
        os.remove(file)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号