Beispiel #1
0
def btdigg_get(bot, update):
    #print("btdigg_get in")
    content = str(update.message.text)
    #print(content)
    outputlist = btdiggTop10.btdiggtop10get(content)
    reply_str = ""
    if len(outputlist) == 0:
        reply_str += "error, no resources"
    else:
        cnt_ = 0
        for out in outputlist:
            reply_str += out + "\n"
            cnt_ += 1
            if cnt_ >= min(10, len(outputlist)):
                break
    update.message.reply_text(reply_str)
    return ConversationHandler.END
Beispiel #2
0
def bot_response(bot):
    global last_update_id
    #print(bot.getMe())
    updates=bot.getUpdates(offset=last_update_id,timeout=1)
    #print(updates[-1].message)
    for update in updates:
        chatid=updates[-1].message.chat_id
        targetid=updates[-1].update_id
        content=updates[-1].message.text
        if content=="/test":
            bot.sendMessage(chat_id=chatid,text="testing")
        elif content=="/about":
            bot.sendMessage(chatid,"a virtual girlfriend demo(testing)")
        elif content.startswith("/pixiv"):
            pixiv_id=content.split('#')[1]
            aaa=pixiv_auto_get.pixiv_auto_get(pixiv_id)
            bot.sendMessage(chat_id=chatid,text=aaa)
            del aaa
        elif content=="/about_moebean":
            aboutcontent="某初学者为了装装逼加学习Python,\n基于github上的Python-telegram-bot项目开发的简易机器人,\n如果后期成功脱团并且有了思路会继续改进为真正的虚拟女友项目。\n具体功能如下:\n/about--获取帮助\n/pixiv#p站图片ID--自动获取图片(暂时只能实现第一张获取且需要本人服务器中转\n/google$内容或者/baidu$内容--搜索相关内容\n未完待续"
            bot.sendMessage(chat_id=chatid,text=aboutcontent)
        elif content.startswith('/google'):
            search_content=content.split('$')[1]
            link='https://www.google.com/?gfe_rd=cr&ei=5zzlVYSoFueN8QeOjKuoDQ&gws_rd=cr&fg=1#q='+search_content
            bot.sendMessage(chat_id=chatid,text=link)
            del link
        elif content.startswith("/baidu"):
            search_content=content.split("$")[1]
            link="https://www.baidu.com/from=844b/s?word="+search_content
            bot.sendMessage(chat_id=chatid,text=link)
            del link
        elif content.startswith('/top10btdigg'):
            search_content=content.split('$')[1]
            link='http://btdigg.org/search?info_hash=&q='+search_content
            print(link)
            list1=btdiggTop10.btdiggtop10get(link)
            output=list1[0]+'\n'+list1[1]+'\n'+list1[2]+'\n'+list1[3]+'\n'+list1[4]+'\n'+list1[5]+'\n'+list1[6]+'\n'+list1[7]+'\n'+list1[8]+'\n'+list1[9]
            bot.sendMessage(chat_id=chatid,text=output)
        last_update_id=updates[-1].update_id+1
Beispiel #3
0
                    link='https://www.google.com/?gfe_rd=cr&ei=5zzlVYSoFueN8QeOjKuoDQ&gws_rd=cr&fg=1#q='+search_content
                    bot.sendMessage(chat_id=chatid,text=link)
                    del link
        elif content.startswith("/baidu")and '$'in content:
            search_content=content.split("$")[1]
            link="https://www.baidu.com/from=844b/s?word="+search_content
            bot.sendMessage(chat_id=chatid,text=link)
            del link
        elif content.startswith('/top10btdigg')and '$'in content:
            if content=='top10btdigg' or content.split('$')[1]=='':
                bot.sendMessage(chat_id=chatid,text='请按照格式"/top10btdigg$content"发送')
            else:
                search_content=content.split('$')[1]
                link='http://btdigg.org/search?info_hash=&q='+search_content
                try:
                    list1=btdiggTop10.btdiggtop10get(link)
                    print(list1)
                    output=""
                    i=0
                    while i<len(list1):
                        output+=list1[i]+'\n'
                        print(output)
                        i+=1
                    #output=list1[0]+'\n'+list1[1]+'\n'+list1[2]+'\n'+list1[3]+'\n'+list1[4]+'\n'+list1[5]+'\n'+list1[6]+'\n'+list1[7]+'\n'+list1[8]+'\n'+list1[9]
                    bot.sendMessage(chat_id=chatid,text=output)
                except:
                    output="error:something wrong"
                    bot.sendMessage(chat_id=chatid,text=output)
        else:
	        pass
        last_update_id=updates[-1].update_id+1