def qq_run_bot(): global bot fuse_argv = [s for s in sys.argv] sys.argv = [sys.argv[0]] bot = QQBot() bot.Login(qq='505498794') sys.argv = fuse_argv bot.Run()
#!/usr/bin/python # -*- coding: utf-8 -*- from qqbot import QQBot myqqbot = QQBot() @myqqbot.On('qqmessage') def handler(bot, message): if message.content == '-hello': bot.SendTo(message.contact, '你好,我是QQ机器人') elif message.content == '-stop': bot.SendTo(message.contact, 'QQ机器人已关闭') bot.Stop() myqqbot.LoginAndRun()
def test(): bot = QQBot() bot.Login(qq=my_qq) bot.Run()
def time_call(bot, tl): while True: time.sleep(5) bot.SendTo(tl, str(datetime.datetime.now())) def test(): bot = QQBot() bot.Login(qq=my_qq) bot.Run() # embed() if __name__ == '__main__': # RunBot() # x = QConf() # print(x.qq) # sys.exit(0) bot = QQBot() bot.Login(qq=my_qq) #tl = bot.List('buddy', '天龙')[0] # t = Thread(target=time_call, args=[bot, tl]) # t.start() # tl = search_friend(bot, '天龙') # hzc = search_friend(bot, '胡泽聪') bot.Run() #embed()
from qqbot import QQBot from common.config import Config from common import logger from common.common import HtmlContent from common import common class MockBizManager: def route(self,type,sender,group,msg): return None,None logger.init_4_debug() conf = Config("bot.conf") #为了让common.py中的类可以直接访问配置,来个trick common.set_config(conf) qqbot = QQBot(None,conf) qqbot.startup() #case1:测试文本消息 # qqbot.send("1234567","机器人","新版酷Q测试消息") #case2:测试HTML消息,会自动格式化成图片发送 qqbot.send("1234567","机器人","新版酷Q测试HTML消息",HtmlContent("<html><head></head><body>自带HTML标签的消息</body></html>","html")) qqbot.send("1234567","机器人","新版酷Q测试HTML Plain消息",HtmlContent("Plain Text的消息","plain")) #case3:测试图片消息 # qqbot.send_image("1234567","机器人","./test/bot.png") #case4:测试接收到回调消息后的处理 # data = \ # { # "group_id":"1234567", # "font":"1234567",
for module in modules: info = "" try: info = module.work(msg, infomation) except Exception, e: print e if info: msg.Reply(info) break load_module() if not os.path.exists('users/'): os.makedirs('users/') myqqbot = QQBot(qq=你要登陆的QQ) mapping = {} @myqqbot.On('qqmessage') def handler(bot, msg): global blackList global mapping msg.content = msg.content.strip(' ') qq = '' if msg.contact.ctype == 'buddy': qq = str(msg.contact.qq) else: qq = mapping.get(str(msg.memberUin), None) if not qq: mapping[str(msg.memberUin)] = myqqbot.uin2qq(msg.memberUin)
#coding:utf-8 from qqbot import QQBot from TrainSpider import TrainSpider import time if __name__ == '__main__': myqqbot = QQBot(qq='2389111521') myqqbot.Login() spider = TrainSpider() interVal = 30 while True: ret = spider.query('2017-02-26','庐山','武汉') if ret is not None: myqqbot.Send('buddy',qq='1050358918',content=ret) time.sleep(interVal)
if contact[0] == number: return contact[1], contact[2] return None def GetNumber(Contacts, nickname): for contact in Contacts: if contact[1].encode == nickname: return contact[0] return None if __name__ == '__main__': # start and login qq first bot = QQBot() bot.Login() Buddies = bot.buddy Groupes = bot.group Discusses = bot.discuss Contacts = [] for buddy in Buddies: tmpBuddy = list(buddy) tmpBuddy.append('buddy') Contacts.append(tmpBuddy) for group in Groupes: tmpGroup = list(group) tmpGroup.append('group') Contacts.append(tmpGroup) for discuss in Discusses: tmpDiscuss = list(discuss)
def __init__(self, server=None, port=None): Thread.__init__(self, name='QQ') QQBot.__init__(self, server, port) self.exit = False
bot.SendTo(contact, '不会自己看群公告啊,傻逼') bot.SendTo(contact, '网页版:http://tenhou.net/3/?L2587') bot.SendTo(contact, 'Flash 版:http://tenhou.net/0/?L2587') elif "傻逼" in content or "真蠢" in content: bot.SendTo(contact, '信不信我烟你') elif "疯了" in content or "可爱" in content: bot.SendTo(contact, '嘻嘻') elif "闭嘴" in content or "好吵" in content: bot.SendTo(contact, '哦,那你可以烟我啊') elif "吃" in content: bot.SendTo(contact, '不吃') elif "飞了" in content: bot.SendTo(contact, '丢人,你退群吧') else: num = random.random() if num < 0.3: bot.SendTo(contact, '操你妈要求真多') elif num < 0.66: bot.SendTo(contact, '人家不懂,不然先抽烟?') else: bot.SendTo(contact, '哎呀人家不懂了啦') elif random.random() > 0.98: bot.SendTo(contact, content) if __name__ == '__main__': bot = QQBot() botConnector = BotConnector(bot) bot.Login(user='******') bot.Run()
#!/usr/bin/python # -*- coding: utf-8 -*- from qqbot import QQBot myqqbot = QQBot() @myqqbot.On('qqmessage') def handler(bot, message): if message.content == '-hello': bot.SendTo(message.contact, '你好,我是QQ机器人') elif message.content == '-stop': bot.SendTo(message.contact, 'QQ机器人已关闭') bot.Stop() myqqbot.Login() myqqbot.Run()
from qqbot import QQBot bot = QQBot() bot.Login() bot.send('group', 3999311269, 'ha?')
result = startSearch.text result1 = re.findall( r'</div><div class="lemma-summary" label-module="lemmaSummary">\n<div class="para" label-module="para">(.*?)</div>\n</div>', result) regex = re.compile(r'<(S*?)[^>]*>.*?|<.*? />') result2 = result1[0].decode('utf-8', 'ignore') print(type(result2)) result3 = re.sub(regex, '', result2) #result = BeautifulSoup(startSearch.text) #result1 = result.find_all('div','lemma-summary') #result2 = re.findall(r'label-module="para">(.*?)</div>\n</div>',result1[0]) #result3 = result2[0].replace(re.findall(r'<(S*?)[^>]*>.*?|<.*? /> ',resule2[0]),'') return result3 myqq = QQBot() @myqq.On('qqmessage') def handler(bot, message): if unicode(message.contact.name, 'utf-8') in chatList: #妈的,非得转码一下才行,要是3.x的话就不需要转码了😭 #敏感字符检测 for x in sensitive: if message.content.find(x) >= 0: bot.SendTo(message.contact, '楼上包含敏感字符,并回复楼上 草泥马') return #检测搜索关键字 if '搜索' in message.content: bot.SendTo(message.contact, search(message.content.split('搜索')[1])) return
#该程序存在bug #1、引入模块 from qqbot import QQBot #QQBot就是一个qq登陆的实例 bot = QQBot() #实例化一个qq实例 bot.Login() #进行登陆,执行这条命令,系统会弹出一个二维码,我们扫码登陆即可 #使用脚本来查看用户和群 user_list = bot.List('buddy') #获得所有的用户 for user in user_list: print(user) group_list = bot.List('group') #获取所有的群 for group in group_list: if group == '不仅仅喇叭': #发送消息 bot.SendTo(group, '大家好,这是王海云的机器人') #print(group) bot.Stop() #退出qq