def killCenter(bot): while (True): time.sleep(30) print('定时踢人倒计时触发') member_num = len(bot_global.kill_list) if member_num > 0: for i in range(member_num - 1, -1, -1): bot_global.kill_list[i][ 'time'] = bot_global.kill_list[i]['time'] - 1 if bot_global.kill_list[i]['time'] == 0: group = bot_global.kill_list[i]['group'] qq = bot_global.kill_list[i]['qq'] msg = '操作执行成功: 踢出QQ号%s' % qq del bot_global.kill_list[i] bot_global.check_out_lock.acquire() for j in range( len(bot_global.user_check_out_list) - 1, -1, -1): if bot_global.user_check_out_list[j][ 'qq'] == qq and bot_global.user_check_out_list[ j]['group'] == group: del bot_global.user_check_out_list[j] bot_IOfile.write_pkl_data( bot_global.user_check_out_list, 'data/data_check_out_list.pkl') break bot_global.check_out_lock.release() try: bot.set_group_kick(group_id=group, user_id=qq) bot.send_group_msg(group_id=group, message=msg) except: pass time.sleep(30)
def checkOutCenter(bot): while (True): time.sleep(50) print('定时pp超限踢人触发') now_day = datetime.date.today() bot_global.check_out_lock.acquire() for i in range(len(bot_global.user_check_out_list) - 1, -1, -1): group = bot_global.user_check_out_list[i]['group'] qq = bot_global.user_check_out_list[i]['qq'] deadline = bot_global.user_check_out_list[i]['deadline'] context_temp = { 'message_type': 'group', 'group_id': group, 'user_id': qq, 'message': '0' } if now_day >= deadline: if bot_superstar.ignoreUserCheck(bot, context_temp) <= 1: content = '!kill[CQ:at,qq=%s] ' % qq bot.send_group_msg(group_id=group, message=content) msg = bot_msgcheck.sendKill(bot, bot_global.kill_list, group, content) bot.send_group_msg(group_id=group, message=msg) else: del bot_global.user_check_out_list[i] bot_IOfile.write_pkl_data(bot_global.user_check_out_list, 'data/data_check_out_list.pkl') bot_global.check_out_lock.release() time.sleep(10750)
def cleanCenter(bot): while (True): time.sleep(100) print('定时清除记录触发') bot_global.user_check_in_list.clear() bot_IOfile.write_pkl_data(bot_global.user_check_in_list, 'data/data_check_in_list.pkl') time.sleep(3500)
def pick11(card_member, list_c): for i in range(len(list_c)): if card_member == list_c[i]['qq']: if list_c[i]['money_now'] < 100: msg = '金币数量低于100! 快去打图' else: list_c[i]['money_now'] = list_c[i]['money_now'] - 100 msg = '11连结果:' card_set = list_c[i]['card'] getR = False # 这一轮11连是不是抽到了R或以上 for times in range(11): (rare_code, new_card) = choose() getNew = True if rare_code < 4: getR = True for j in range(len( card_set[rare_code])): # 如果这张卡不是首次抽到...... if new_card == card_set[rare_code][j]['card_name']: getNew = False msg = msg + '\n%s: %s' % (rare_name[rare_code], new_card) card_set[rare_code][j]['card_number'] = card_set[ rare_code][j]['card_number'] + 1 break if getNew: # 如果这张卡是首次抽到...... msg = msg + '\n%s: %s (new!)' % (rare_name[rare_code], new_card) card_set[rare_code].append({ 'card_name': new_card, 'card_number': 1 }) new_unlock = medalUnlock(card_set) if list_c[i]['medal'][9] == 100 or not getR: new_unlock[9] = 100 new_pt = check_pt(card_set, list_c[i]['pt_bonus'], new_unlock) medal_msg = medalUpdate(list_c[i]['medal'], new_unlock) msg = msg + '\n金币数变更: %s → %s' % (list_c[i]['money_now'] + 100, list_c[i]['money_now']) msg = msg + '\n机票数变更: %s → %s' % (flyNumCal( list_c[i]['fly']), flyNumCal(list_c[i]['fly'] + 10)) msg = msg + '\n活动pt变更: %s → %s' % (list_c[i]['pt_total'], new_pt) if medal_msg: msg = msg + '\n解锁隐藏成就:' + medal_msg list_c[i]['fly'] = list_c[i]['fly'] + 10 list_c[i]['card'] = card_set list_c[i]['pt_total'] = new_pt list_c[i]['medal'] = new_unlock list_c[i]['num_pick'] = list_c[i]['num_pick'] + 11 (lucky, lucky_rate) = European(list_c[i]) list_c[i]['lucky'] = lucky list_c[i]['lucky_rate'] = lucky_rate bot_IOfile.write_pkl_data(list_c, 'data/data_card_game_list.pkl') return msg msg = '此玩家并未参与活动' return msg
def oneUserUpdate(card_member, list_c): for i in range(len(list_c)): member = list_c[i] if card_member == member['qq']: (list_c[i], msg, update_success, update_success_detail) = GameUpdate(member) bot_IOfile.write_pkl_data(list_c, 'data/data_card_game_list.pkl') return msg msg = '此玩家并未参与活动' return msg
def addMoney(card_member, list_c): for i in range(len(list_c)): if card_member == list_c[i]['qq']: list_c[i]['money_now'] = list_c[i]['money_now'] + 1000 list_c[i]['money_bonus'] = list_c[i]['money_bonus'] + 1000 bot_IOfile.write_pkl_data(list_c, 'data/data_card_game_list.pkl') msg = '金币+1000' return msg msg = '此玩家并未参与活动' return msg
def startCard(card_member, list_c, content): for member in list_c: if card_member == member['qq']: msg = '此QQ号已被注册,活动进行中' return msg if content == '!start_card': msg = '倒是告诉我id啊' elif '!start_card ' in content: check_id = re.match(r'^!start_card (.*)$', content) if check_id: osu_name = check_id.group(1) osu_id = '0' real_name = '0' pc = [0, 0, 0, 0] tth = [0, 0, 0, 0] medal = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] for i in range(4): (osu_id, real_name, pp, pc[i], tth[i], acc, sec) = bot_osu.getUserInfo(osu_name, i) if not osu_id: msg = '查询失败,可能为输入错误或网络延迟' return msg user_info = { 'qq': card_member, 'uid': osu_id, 'name': real_name, 'pc': pc, 'tth': tth, 'medal': medal, 'card': [[], [], [], [], []], 'money_now': 100, 'money_total': 100, 'money_boom_total': 0, 'money_boom_cost': 30, 'money_smoke': 0, 'money_bonus': 0, 'pt_total': 0, 'pt_bonus': 0, 'lucky': 0, 'lucky_rate': 0, 'fly': 0, 'num_pick': 0, 'num_fly': 0 } msg = '玩家信息:\nqq号: %s\nuid: %s\nname: %s\npc: %s\ntth: %s\nmoney: %s\n机票数: 0\n活动开始!'\ % (card_member, osu_id, real_name, pc, tth, 100) list_c.append(user_info) bot_IOfile.write_pkl_data(list_c, 'data/data_card_game_list.pkl') else: msg = '您的!start_card指令使用错误' else: msg = '无法识别,bot猜测您是想使用指令!start_card x (x为参数)' return msg
def pick1(card_member, list_c): for i in range(len(list_c)): if card_member == list_c[i]['qq']: if list_c[i]['money_now'] < 10: msg = '金币数量低于10! 快去打图' else: list_c[i]['money_now'] = list_c[i]['money_now'] - 10 msg = '单抽结果:' card_set = list_c[i]['card'] (rare_code, new_card) = choose() existence = 0 for j2 in range(len(card_set[rare_code])): # 如果这张卡不是首次抽到...... if new_card == card_set[rare_code][j2]['card_name']: existence = 1 msg = msg + '\n%s: %s' % (rare_name[rare_code], new_card) card_set[rare_code][j2]['card_number'] = card_set[ rare_code][j2]['card_number'] + 1 break if existence == 0: # 如果这张卡是首次抽到...... msg = msg + '\n%s: %s (new!)' % (rare_name[rare_code], new_card) card_set[rare_code].append({ 'card_name': new_card, 'card_number': 1 }) new_unlock = medalUnlock(card_set) if list_c[i]['medal'][9] == 100: new_unlock[9] = 100 new_pt = check_pt(card_set, list_c[i]['pt_bonus'], new_unlock) medal_msg = medalUpdate(list_c[i]['medal'], new_unlock) msg = msg + '\n金币数变更: %s → %s' % (list_c[i]['money_now'] + 10, list_c[i]['money_now']) msg = msg + '\n机票数变更: %s → %s' % (flyNumCal( list_c[i]['fly']), flyNumCal(list_c[i]['fly'] + 1)) msg = msg + '\n活动pt变更: %s → %s' % (list_c[i]['pt_total'], new_pt) if medal_msg: msg = msg + '\n解锁隐藏成就:' + medal_msg list_c[i]['fly'] = list_c[i]['fly'] + 1 list_c[i]['card'] = card_set list_c[i]['pt_total'] = new_pt list_c[i]['medal'] = new_unlock list_c[i]['num_pick'] = list_c[i]['num_pick'] + 1 (lucky, lucky_rate) = European(list_c[i]) list_c[i]['lucky'] = lucky list_c[i]['lucky_rate'] = lucky_rate bot_IOfile.write_pkl_data(list_c, 'data/data_card_game_list.pkl') return msg msg = '此玩家并未参与活动' return msg
def fly1(card_member, list_c): for i in range(len(list_c)): if card_member == list_c[i]['qq']: if list_c[i]['fly'] < 50: msg = '机票数量低于5! 快去抽卡' else: list_c[i]['fly'] = list_c[i]['fly'] - 50 msg = '偷渡结果:' card_set = list_c[i]['card'] (rare_code, new_card) = choose_fly() getNew = True for j in range(len(card_set[rare_code])): if new_card == card_set[rare_code][j]['card_name']: getNew = False msg = msg + '\n%s: %s' % (rare_name[rare_code], new_card) card_set[rare_code][j]['card_number'] = card_set[ rare_code][j]['card_number'] + 1 break if getNew: msg = msg + '\n%s: %s (new!)' % (rare_name[rare_code], new_card) card_set[rare_code].append({ 'card_name': new_card, 'card_number': 1 }) new_unlock = medalUnlock(card_set) if list_c[i]['medal'][9] == 100: new_unlock[9] = 100 new_pt = check_pt(card_set, list_c[i]['pt_bonus'], new_unlock) medal_msg = medalUpdate(list_c[i]['medal'], new_unlock) msg = msg + '\n机票数变更: %s → %s' % (flyNumCal( list_c[i]['fly'] + 50), flyNumCal(list_c[i]['fly'])) msg = msg + '\n活动pt变更: %s → %s' % (list_c[i]['pt_total'], new_pt) if medal_msg: msg = msg + '\n解锁隐藏成就:' + medal_msg list_c[i]['card'] = card_set list_c[i]['pt_total'] = new_pt list_c[i]['medal'] = new_unlock list_c[i]['num_fly'] = list_c[i]['num_fly'] + 1 (lucky, lucky_rate) = European(list_c[i]) list_c[i]['lucky'] = lucky list_c[i]['lucky_rate'] = lucky_rate bot_IOfile.write_pkl_data(list_c, 'data/data_card_game_list.pkl') return msg msg = '此玩家并未参与活动' return msg
def certainUserUpdate(list_c, content): check_name = re.match(r'^!update (.*)$', content) if check_name: osu_name = check_name.group(1) for i in range(len(list_c)): member = list_c[i] if osu_name == member['name']: (list_c[i], msg, success, success_detail) = GameUpdate(member) bot_IOfile.write_pkl_data(list_c, 'data/data_card_game_list.pkl') return msg msg = '此玩家并未参与活动' else: msg = '您的!update指令使用错误' return msg
def stopCare(list_b, content, group): if content == '!reset_bp': msg = '倒是告诉我id啊' elif '!reset_bp ' in content: check_id = re.match(r'^!reset_bp (.*),([0123])$', content) if check_id: osu_name = check_id.group(1) osu_mode = check_id.group(2) else: check_id = re.match(r'^!reset_bp (.*)$', content) if check_id: osu_name = check_id.group(1) osu_mode = '0' else: msg = '您的!reset_bp指令使用错误' return msg (osu_id, real_name, pp, pc, tth, acc, sec) = getUserInfo(osu_name, osu_mode) if not osu_id: msg = '查不到这个人哎' else: success = 0 bp_num = len(list_b) for i in range(0, bp_num): if list_b[i][20]['user_id'] == osu_id and list_b[i][20][ 'user_mode'] == osu_mode: if group in list_b[i][20]['user_group']: list_b[i][20]['user_group'].remove(group) if not list_b[i][20]['user_group']: del list_b[i] success = 1 break else: success = 2 break if success == 1: msg = '移除%s的bp监视成功!' % real_name bot_IOfile.write_pkl_data(list_b, 'data/data_bp_care_list.pkl') elif success == 2: msg = '此人并没有在本群内监视' else: msg = '此人并没有在任何群内监视' else: msg = '无法识别,bot猜测您是想使用指令!reset_bp x(x为参数)' return msg
def stopCard(list_c, content): if content == '!ban_card': msg = '倒是告诉我qq号啊' elif '!ban_card ' in content: check_qq = re.match(r'^!ban_card ([123456789][0123456789]*)$', content) if check_qq: qq = int(check_qq.group(1)) for i in range(len(list_c)): if list_c[i]['qq'] == qq: del list_c[i] bot_IOfile.write_pkl_data(list_c, 'data/data_card_game_list.pkl') msg = '已删除此qq号活动数据' return msg msg = '该qq号并没有参加活动' else: msg = '您的!ban_card指令使用错误' else: msg = '无法识别,bot猜测您是想使用指令!ban_card x (x为参数)' return msg
def add(list_h, qq): if qq in list_h: msg = '您已经是关爱对象了,无需重复添加\n输入!care查看' else: list_h.append(qq) success = bot_IOfile.write_pkl_data(list_h, 'data/data_health_list.pkl') if success == 1: msg = '设置成功!dalou将会每晚关照您的健康\n输入!care查看' else: msg = '本地保存失败,请联系dalou,错误代码:21' return msg
def sub(list_h, qq): if qq in list_h: t = list_h.index(qq) del list_h[t] success = bot_IOfile.write_pkl_data(list_h, 'data/data_health_list.pkl') if success == 1: msg = '移除关爱对象成功\n输入!care查看' else: msg = '本地保存失败,请联系dalou,错误代码:22' else: msg = 'dalou压根就没在关心你!' return msg
def sendBoom(list_c, card_member, content): success = 0 smoke1 = 0 smoke2 = 0 qq = 0 if content == '!boom': msg = '我觉得你在逗我(指令最后需要紧跟着艾特一个人)' return msg, success, qq, smoke1, smoke2 for i in range(len(list_c)): if card_member == list_c[i]['qq']: now_boom_money = list_c[i]['money_boom_cost'] if list_c[i]['money_now'] < now_boom_money: msg = '金币数量低于%s! 快去打图' % now_boom_money else: check_msg = re.match(r'^!boom\[CQ:at,qq=([1-9][0-9]*)\]', content) if check_msg: list_c[i][ 'money_now'] = list_c[i]['money_now'] - now_boom_money list_c[i]['money_boom_total'] = list_c[i][ 'money_boom_total'] + now_boom_money list_c[i][ 'money_boom_cost'] = list_c[i]['money_boom_cost'] + 3 bot_IOfile.write_pkl_data(list_c, 'data/data_card_game_list.pkl') qq = int(check_msg.group(1)) smoke2 = random.randint(30, 100) smoke1 = int(smoke2 * random.uniform(0.5, 3)) msg = '操作执行成功\n对方: %s秒, 自己: %s秒\n金币变更情况: %s → %s\n炸弹购买价格: %s → %s' \ % (smoke1, smoke2, list_c[i]['money_now']+now_boom_money, list_c[i]['money_now'], now_boom_money, list_c[i]['money_boom_cost']) success = 1 else: msg = '您的!boom指令使用错误(指令最后需要紧跟着艾特一个人)' return msg, success, qq, smoke1, smoke2 msg = '此玩家并未参与活动' return msg, success, qq, smoke1, smoke2
def allUserUpdate(list_c): error_list = [] error_detail = [] for i in range(len(list_c)): member = list_c[i] (list_c[i], msg, update_success, update_success_detail) = GameUpdate(member) if not update_success: error_list.append(member['name']) error_detail.append(update_success_detail) print('%s. 完成%s, 失败' % (i + 1, member['name'])) else: print('%s. 完成%s, 成功' % (i + 1, member['name'])) bot_IOfile.write_pkl_data(list_c, 'data/data_card_game_list.pkl') if not error_list: msg = '全体打图记录更新完毕,没有发生错误' else: msg = '下列玩家由于延迟爆炸查询失败:' for i in range(len(error_list)): msg = msg + '\n%s:' % error_list[i] for j in range(4): if not error_detail[i][j]: msg = msg + ' %s' % bot_osu.getMode(j) return msg
card_member = list_card[i]['qq'] osu_id = list_card[i]['uid'] name = list_card[i]['name'] pc = list_card[i]['pc'] tth = list_card[i]['tth'] medal = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] user_info = { 'qq': card_member, 'uid': osu_id, 'name': name, 'pc': pc, 'tth': tth, 'medal': medal, 'card': [[], [], [], [], []], 'money_now': 100, 'money_total': 100, 'money_boom_total': 0, 'money_boom_cost': 30, 'money_smoke': 0, 'money_bonus': 0, 'pt_total': 0, 'pt_bonus': 0, 'lucky': 0, 'lucky_rate': 0, 'fly': 0, 'num_pick': 0, 'num_fly': 0 } newlist.append(user_info) bot_IOfile.write_pkl_data( newlist, 'D:\Python POJ\lxybot_v2\data\data_card_game_list.pkl')
def MsgCenter(bot, context): global game_member global game_diff global game_content # 转义字符与指令字符处理 content = context['message'] content = content.replace('[', '[') content = content.replace(']', ']') content = content.replace(',', ',') content = content.replace('&', '&') if content and content[0] == '!': content = content.replace('!', '!', 1) print(content) # 无权限指令 if content == '!hello': msg = '响应测试成功' reply(bot, context, msg, atPeople=False) elif content == '!help': msg = bot_getmsg.getHelp() reply(bot, context, msg, atPeople=False) elif content == '!group': msg = bot_getmsg.suitL(bot_global.group_total_list) reply(bot, context, msg, atPeople=False) # 权限判断 if context[ 'user_id'] in bot_global.host_list and 'lxybot_sudo' not in context: pass elif context['message_type'] == 'group' and ( context['group_id'] not in bot_global.group_total_list or context['user_id'] in bot_global.ignore_list): pass elif context['message_type'] == 'discuss' and context[ 'discuss_id'] not in bot_global.discuss_total_list: pass else: if content == '!月常活动': msg = bot_getmsg.dalouCardGame() reply(bot, context, msg, atPeople=False) elif content == '!chart活动': msg = bot_getmsg.chartSystem() reply(bot, context, msg, atPeople=False) elif content == '!找图系统': msg = bot_getmsg.ppSuggestSystem() reply(bot, context, msg, atPeople=False) elif content == '!健康系统': msg = bot_getmsg.healthSystem() reply(bot, context, msg, atPeople=False) elif content == '!监视系统': msg = bot_getmsg.watchSystem() reply(bot, context, msg, atPeople=False) elif content == '!咩羊游戏': msg = bot_getmsg.mieGame() reply(bot, context, msg, atPeople=False) elif content == '!抽烟系统': msg = bot_getmsg.smokeSystem() reply(bot, context, msg, atPeople=False) elif content == '!欢送系统': msg = bot_getmsg.farewellSystem() reply(bot, context, msg, atPeople=False) elif content == '!dog': msg = bot_getmsg.dogL(bot_global.dog_list) reply(bot, context, msg, atPeople=False) elif content == '!egg': msg = bot_getmsg.eggL(egg_list) reply(bot, context, msg, atPeople=False) elif content == '!kill': msg = bot_getmsg.killL(bot_global.kill_list) reply(bot, context, msg, atPeople=False) elif content == '!farewell': msg = bot_getmsg.farewellL(bot_global.user_check_out_list, context['user_id']) reply(bot, context, msg, atPeople=False) elif content == '!whitelist': msg = bot_getmsg.whiteL(bot_global.white_list, bot_global.white_temp_list) reply(bot, context, msg, atPeople=False) elif '!roll' in content: msg = bot_msgcheck.roll(content) reply(bot, context, msg, atPeople=True) # osu基本功能 elif '!myid' in content: bot_global.sql_action_lock.acquire() msg = bot_osu.setSQL(context['user_id'], content) bot_global.sql_action_lock.release() reply(bot, context, msg, atPeople=True) elif content == '!mypp': bot_global.sql_action_lock.acquire() userinfo = bot_osu.searchUserInfo(context['user_id']) bot_global.sql_action_lock.release() reply(bot, context, userinfo['msg'], atPeople=True) elif content == '!myrct': # 此指令存在bug,为了避免死锁暂时先取消加锁 # bot_global.sql_action_lock.acquire() if context['message_type'] == 'group': group_qq = context['group_id'] else: group_qq = 0 (msg, smoke) = bot_osu.searchUserRecent(context['user_id'], group_qq=group_qq) # bot_global.sql_action_lock.release() reply(bot, context, msg, atPeople=True) if smoke > 0: bot.set_group_ban(group_id=context['group_id'], user_id=context['user_id'], duration=smoke) msg = '核能侦测启动成功: %s秒' % smoke reply(bot, context, msg, atPeople=False) elif content == '!mylevel': bot_global.sql_action_lock.acquire() msg = bot_osu.searchUserLevel(context['user_id']) bot_global.sql_action_lock.release() reply(bot, context, msg, atPeople=True) elif '!level' in content: bot_global.sql_action_lock.acquire() msg = bot_osu.searchOtherLevel(content) bot_global.sql_action_lock.release() reply(bot, context, msg, atPeople=False) # 月常活动 elif '!start_card' in content: if not verify(context, {'group': bot_global.group_main_list}): msg = '该指令不支持在此处使用' else: bot_global.user_card_list_lock.acquire() msg = bot_card.startCard(context['user_id'], user_card_list, content) bot_global.user_card_list_lock.release() reply(bot, context, msg, atPeople=True) elif content == '!mygame': msg = bot_card.userGameInfo(context['user_id'], user_card_list) reply(bot, context, msg, atPeople=True) elif content == '!mycard': msg = bot_card.userCardInfo(context['user_id'], user_card_list) reply(bot, context, msg, atPeople=True) elif content == '!mymedal': msg = bot_card.userMedalDetail(context['user_id'], user_card_list) reply(bot, context, msg, atPeople=True) elif content == '!myMR': msg = bot_card.userCardDetail(context['user_id'], user_card_list, 0, contact=context['message_type']) reply(bot, context, msg, atPeople=True) elif content == '!myUR': msg = bot_card.userCardDetail(context['user_id'], user_card_list, 1, contact=context['message_type']) reply(bot, context, msg, atPeople=True) elif content == '!mySR': msg = bot_card.userCardDetail(context['user_id'], user_card_list, 2, contact=context['message_type']) reply(bot, context, msg, atPeople=True) elif content == '!myR': msg = bot_card.userCardDetail(context['user_id'], user_card_list, 3, contact=context['message_type']) reply(bot, context, msg, atPeople=True) elif content == '!myN': msg = bot_card.userCardDetail(context['user_id'], user_card_list, 4, contact=context['message_type']) reply(bot, context, msg, atPeople=True) elif content == '!update': bot_global.user_card_list_lock.acquire() msg = bot_card.oneUserUpdate(context['user_id'], user_card_list) bot_global.user_card_list_lock.release() reply(bot, context, msg, atPeople=True) elif content == '!pick': bot_global.user_card_list_lock.acquire() msg = bot_card.pick1(context['user_id'], user_card_list) bot_global.user_card_list_lock.release() reply(bot, context, msg, atPeople=True) elif content == '!pick11': bot_global.user_card_list_lock.acquire() msg = bot_card.pick11(context['user_id'], user_card_list) bot_global.user_card_list_lock.release() reply(bot, context, msg, atPeople=True) elif content == '!pickall': bot_global.user_card_list_lock.acquire() msg = bot_card.pickall(context['user_id'], user_card_list) bot_global.user_card_list_lock.release() reply(bot, context, msg, atPeople=True) elif content == '!fly': bot_global.user_card_list_lock.acquire() msg = bot_card.fly1(context['user_id'], user_card_list) bot_global.user_card_list_lock.release() reply(bot, context, msg, atPeople=True) elif content == '!pt_top': msg = bot_card.rankAll(user_card_list, 'pt_down', contact=context['message_type']) reply(bot, context, msg, atPeople=False) elif content == '!pt_last': msg = bot_card.rankAll(user_card_list, 'pt_up', contact=context['message_type']) reply(bot, context, msg, atPeople=False) elif content == '!mn_top': msg = bot_card.rankAll(user_card_list, 'mn_down', contact=context['message_type']) reply(bot, context, msg, atPeople=False) elif content == '!mn_last': msg = bot_card.rankAll(user_card_list, 'mn_up', contact=context['message_type']) reply(bot, context, msg, atPeople=False) elif content == '!lucky_top': msg = bot_card.rankAll(user_card_list, 'lucky_down', contact=context['message_type']) reply(bot, context, msg, atPeople=False) elif content == '!lucky_last': msg = bot_card.rankAll(user_card_list, 'lucky_up', contact=context['message_type']) reply(bot, context, msg, atPeople=False) elif content == '!rankme': msg = bot_card.userRank(context['user_id'], user_card_list) reply(bot, context, msg, atPeople=True) elif '!addmoney' in content: bot_global.user_card_list_lock.acquire() # msg = bot_card.addMoney(context['user_id'], user_card_list) msg = '别想着作弊啦,努力打图去吧' bot_global.user_card_list_lock.release() reply(bot, context, msg, atPeople=True) elif context['message_type'] == 'group' and context[ 'group_id'] in bot_global.group_main_list and '!boom' in content: bot_global.user_card_list_lock.acquire() (msg, success, user, smoke1, smoke2) = bot_card.sendBoom(user_card_list, context['user_id'], content) bot_global.user_card_list_lock.release() if success: bot.set_group_ban(group_id=context['group_id'], user_id=user, duration=smoke1) bot.set_group_ban(group_id=context['group_id'], user_id=context['user_id'], duration=smoke2) reply(bot, context, msg, atPeople=True) # 找图系统 elif '!getmap' in content: reply(bot, context, 'Dalou去找图了,请稍等', atPeople=False) bot_global.sql_action_lock.acquire() msg = bot_suggest.searchMap(context['user_id'], content, contact=context['message_type']) bot_global.sql_action_lock.release() reply(bot, context, msg, atPeople=True) elif '!banmap' in content: bot_global.sql_action_lock.acquire() msg = bot_suggest.banMap(context['user_id'], content) bot_global.sql_action_lock.release() reply(bot, context, msg, atPeople=True) elif '!mapinfo' in content: bot_global.sql_action_lock.acquire() msg = bot_suggest.infoMap(content, contact=context['message_type']) bot_global.sql_action_lock.release() reply(bot, context, msg, atPeople=False) # 监视系统 elif '!set_bp' in content: if not verify(context, {'group': bot_global.group_total_list}): msg = '该指令不支持在此处使用' else: bot_global.user_bp_list_lock.acquire() msg = bot_osu.setCare(bot_global.user_bp_list, content, context['group_id']) bot_global.user_bp_list_lock.release() reply(bot, context, msg, atPeople=True) elif '!reset_bp' in content: if not verify(context, {'group': bot_global.group_total_list}): msg = '该指令不支持在此处使用' else: bot_global.user_bp_list_lock.acquire() msg = bot_osu.stopCare(bot_global.user_bp_list, content, context['group_id']) bot_global.user_bp_list_lock.release() reply(bot, context, msg, atPeople=True) elif content == '!bp': if not verify(context, {'group': bot_global.group_total_list}): msg = '该指令不支持在此处使用' else: msg = bot_getmsg.bpL(bot_global.user_bp_list, context['group_id']) reply(bot, context, msg, atPeople=False) # 健康系统 elif content == '!health': bot_global.health_list_lock.acquire() msg = bot_health.add(health_list, context['user_id']) bot_global.health_list_lock.release() reply(bot, context, msg, atPeople=True) elif content == '!stop_h': bot_global.health_list_lock.acquire() msg = bot_health.sub(health_list, context['user_id']) bot_global.health_list_lock.release() reply(bot, context, msg, atPeople=True) elif content == '!care': msg = bot_getmsg.careL(health_list) reply(bot, context, msg, atPeople=False) # 咩羊游戏 elif '!game_mie' in content: (msg, diff) = bot_miegame.startGame(game_member, context['user_id'], content) if diff > 0: game_member = context['user_id'] game_diff = diff game_content = [[1, 1], [1, 1]] reply(bot, context, msg, atPeople=True) elif content == '!stop_g': if context['user_id'] == game_member: game_member = 0 msg = '解除成功,游戏结束' else: msg = '您并没有绑定该游戏' reply(bot, context, msg, atPeople=True) # 其余具体情况具体分析 else: # 超级权限指令 if context['user_id'] in bot_global.dog_list: if content == '!watch': bot_global.bp_watch = 1 msg = 'BP监视开启' reply(bot, context, msg, atPeople=False) elif content == '!stop_w': bot_global.bp_watch = 0 msg = 'BP监视关闭' reply(bot, context, msg, atPeople=False) elif '!ban_card' in content: bot_global.user_card_list_lock.acquire() msg = bot_card.stopCard(user_card_list, content) bot_global.user_card_list_lock.release() reply(bot, context, msg, atPeople=False) elif content == '!updateall': reply(bot, context, '开始全体更新打图记录', atPeople=False) bot_global.user_card_list_lock.acquire() msg = bot_card.allUserUpdate(user_card_list) bot_global.user_card_list_lock.release() reply(bot, context, msg, atPeople=False) elif '!update' in content: bot_global.user_card_list_lock.acquire() msg = bot_card.certainUserUpdate(user_card_list, content) bot_global.user_card_list_lock.release() reply(bot, context, msg, atPeople=False) elif '!unbind' in content: bot_global.sql_action_lock.acquire() msg = bot_osu.unsetSQL(content) bot_global.sql_action_lock.release() reply(bot, context, msg, atPeople=False) elif '!stop_mie' in content: game_member = 0 msg = '咩羊游戏解除' reply(bot, context, msg, atPeople=False) elif '!测试' in content: msg = '%s' % bot_msgcheck.getGroupMemberInfo( bot, context['group_id'], context['user_id']) reply(bot, context, msg, atPeople=False) elif context['message_type'] == 'group' and context[ 'group_id'] in bot_global.group_dog_list: if '!smoke' in content: (msg, success, user, smoke) = bot_msgcheck.sendSmoke(content) if success: bot.set_group_ban(group_id=context['group_id'], user_id=user, duration=smoke) reply(bot, context, msg, atPeople=False) elif '!unsmoke' in content: (msg, success, user) = bot_msgcheck.removeSmoke(content) if success: bot.set_group_ban(group_id=context['group_id'], user_id=user, duration=0) reply(bot, context, msg, atPeople=False) elif '!kill' in content: msg = bot_msgcheck.sendKill(bot, bot_global.kill_list, context['group_id'], content) reply(bot, context, msg, atPeople=False) elif '!stop_k' in content: msg = bot_msgcheck.stopKill(bot_global.kill_list, context['group_id'], content) reply(bot, context, msg, atPeople=False) # 需要管理员身份的群聊指令 if context['message_type'] == 'group' and context[ 'group_id'] in bot_global.group_dog_list: if content == '!cnm': smoke = random.randint(5, 100) bot.set_group_ban(group_id=context['group_id'], user_id=context['user_id'], duration=smoke) msg = '操作执行成功: %s秒' % smoke reply(bot, context, msg, atPeople=True) elif content == '!rest': bot.set_group_ban(group_id=context['group_id'], user_id=context['user_id'], duration=3600) msg = '操作执行成功: 1小时' reply(bot, context, msg, atPeople=True) elif content == '!sleep': bot.set_group_ban(group_id=context['group_id'], user_id=context['user_id'], duration=21600) msg = '操作执行成功: 6小时' reply(bot, context, msg, atPeople=True) elif '!afk' in content: (smoke, msg1, msg2) = bot_msgcheck.afk(context['group_id'], context['user_id'], content) if msg1: msg = msg1 else: bot.set_group_ban(group_id=context['group_id'], user_id=context['user_id'], duration=smoke) msg = '操作执行成功: %s' % msg2 reply(bot, context, msg, atPeople=True) # 超星检测 if context['message_type'] == 'group' and context[ 'group_id'] in bot_global.group_main_list: if context['user_id'] == 2680306741: max_diff = bot_superstar.maxDiffCheck(context['group_id']) (now_diff, user_qq) = bot_superstar.nowDiffCheck(content) if now_diff > max_diff: smoke = min(2591940, (now_diff - max_diff) * 5 * 60) msg = '核能侦测启动成功: %s秒' % smoke bot.set_group_ban(group_id=context['group_id'], user_id=user_qq, duration=smoke) reply(bot, context, msg, atPeople=False) # 主群chart活动 if context['message_type'] == 'group' and context[ 'group_id'] in bot_global.group_chart_list: if content == '!chart': msg = bot_chart.getChart() reply(bot, context, msg, atPeople=False) elif content == '!submit': bot_global.sql_action_lock.acquire() # msg = '本期chart已经结束' msg = bot_chart.submitChart(context['user_id']) bot_global.sql_action_lock.release() reply(bot, context, msg, atPeople=True) elif content == '!mychart': bot_global.sql_action_lock.acquire() chartinfo = bot_chart.myChart(context['user_id'], getMsg=True) bot_global.sql_action_lock.release() reply(bot, context, chartinfo['msg'], atPeople=True) elif '!chart_top' in content: bot_global.sql_action_lock.acquire() msg = bot_chart.rankChart(content) bot_global.sql_action_lock.release() reply(bot, context, msg, atPeople=False) # 新人群彩蛋 ''' if context['message_type'] == 'group' and context['group_id'] in bot_global.group_main_list: for egg in egg_list: if '[CQ:' not in content: check_egg = re.match(r'%s' % egg['expression'], content) if check_egg: reply(bot, context, egg['reply'], atPeople=False) bot_global.sql_action_lock.acquire() if not egg['unlock_qq']: egg['unlock_name'] = bot_osu.searchUserInfo(context['user_id'])['name'] egg['unlock_qq'] = context['user_id'] if egg['unlock_name'] and egg['unlock_name'] != '0': msg = '大伙注意啦, %s解锁了%s号彩蛋' % (egg['unlock_name'], egg['id']) msg1 = '全部彩蛋解锁完毕,恭喜%s得到撒泼特一个月' % egg['unlock_name'] else: msg = '大伙注意啦, QQ号%s解锁了%s号彩蛋' % (egg['unlock_qq'], egg['id']) msg1 = '全部彩蛋解锁完毕,恭喜QQ号%s得到撒泼特一个月' % egg['unlock_qq'] bot_IOfile.write_pkl_data(egg_list, 'data/data_egg_list.pkl') reply(bot, context, msg, atPeople=False) all_unlock = True for eggs in egg_list: if not eggs['unlock_qq']: all_unlock = False break if all_unlock: reply(bot, context, msg1, atPeople=False) bot_global.sql_action_lock.release() break ''' # 健康系统计算 if context['message_type'] == 'group' and context[ 'user_id'] in health_list: t_hour = int(time.strftime('%H', time.localtime(time.time()))) t_minute = int(time.strftime('%M', time.localtime(time.time()))) if 0 <= t_hour <= 6: smoke = 6 * 60 * 60 - t_hour * 60 * 60 - t_minute * 60 bot.set_group_ban(group_id=context['group_id'], user_id=context['user_id'], duration=smoke) msg = '现在是半夜,请睡觉了' if context['user_id'] == game_member: game_member = 0 msg = msg + '\n您的咩羊游戏被强制解除' reply(bot, context, msg, atPeople=True) # 咩羊游戏计算 if context['user_id'] == game_member: bot_global.game_mie_lock.acquire() (msg1, msg2, gg) = bot_miegame.one_plus_one_check(game_content, content, game_diff) bot_global.game_mie_lock.release() reply(bot, context, msg1, atPeople=True) if msg2: reply(bot, context, msg2, atPeople=True) if gg == 1: game_member = 0 msg = '解除成功,游戏结束' reply(bot, context, msg, atPeople=False) # 复读触发 if context['message_type'] == 'group' and context[ 'group_id'] in bot_global.group_total_list: group_i = bot_global.group_total_list.index( context['group_id']) if '!' in content or '!' in content or '~' in content or '~' in content or '[CQ:' in content: pass elif bot_global.repeat_num[group_i] >= 100: pass else: bot_global.noise_list_lock.acquire() t = bot_noise.check(group_i, bot_global.repeat_list, bot_global.repeat_num, content) bot_global.noise_list_lock.release() if t == 2: reply(bot, context, content, atPeople=False) # 私聊解禁 if context['message_type'] == 'private' and '!remove' in content: (msg, remove_group_i) = bot_msgcheck.remove(content) if remove_group_i > -1: if bot_global.group_total_list[ remove_group_i] not in bot_global.group_dog_list: msg = '臣妾做不到啊(不是管理员)' else: bot.set_group_ban(group_id=bot_global. group_total_list[remove_group_i], user_id=context['user_id'], duration=0) reply(bot, context, msg, atPeople=False) # 群发公告 if context['message_type'] == 'private' and '!send' in content: if context['user_id'] in bot_global.dog_list: (msg, success) = bot_msgcheck.getMsgSend(content) else: msg = '你不是我的master!' success = False if success: for group_id in bot_global.group_total_list: try: bot.send_group_msg(group_id=group_id, message=msg) except: reply(bot, context, '群号%s出现发送异常' % group_id, atPeople=False) else: reply(bot, context, msg, atPeople=False) # 主群超限检测 if context['message_type'] == 'group' and context[ 'group_id'] in bot_global.group_main_list: if not bot_superstar.ignoreUserCheck(bot, context): bot_global.sql_action_lock.acquire() (out_pp, max_pp, step_pp) = bot_superstar.maxPPCheck(context['group_id']) now_user_info = bot_osu.searchUserInfo(context['user_id'], update=False) bot_global.sql_action_lock.release() msg = '' if not now_user_info['sql']: msg = '请绑定本bot以便获取更好的服务\n指令格式为!myid x (x为您的osu!账号)' elif not now_user_info['uid']: pass elif now_user_info['pp'] < 0.1: msg = '您的pp低于0.1,请先进行一次游戏' elif now_user_info['pp'] > out_pp: days = max((max_pp - now_user_info['pp']) // step_pp + 1, 1) bot_global.super_star_lock.acquire() msg = bot_superstar.checkout(context['group_id'], context['user_id'], now_user_info['uid'], now_user_info['name'], days) bot_global.super_star_lock.release() bot_global.user_check_in_list.append(context['user_id']) bot_IOfile.write_pkl_data(bot_global.user_check_in_list, 'data/data_check_in_list.pkl') else: bot_global.user_check_in_list.append(context['user_id']) bot_IOfile.write_pkl_data(bot_global.user_check_in_list, 'data/data_check_in_list.pkl') if msg: reply(bot, context, msg, atPeople=True)
def bpCareCenter(bot, maxcount): count = 0 newstart = True while count < maxcount: time.sleep(30) print('定时bp监视任务触发') if bot_global.bp_watch: count = count + 1 msg = '开始查询BP\n本次为bot启动后第%s次查询' % count print(msg) bot_global.user_bp_list_lock.acquire() # 列表上锁 for num in range(len(bot_global.user_bp_list)): user = bot_global.user_bp_list[num] user_id = user[20]["user_id"] score_mode = user[20]["user_mode"] group_list = user[20]["user_group"] new_bp = bot_osu.getUserBp(user_id, score_mode, max_num=20) if new_bp: for i in range(0, 20): if new_bp[i] != user[i]: msg = '某人bp%s有变化,但是细节查询失败,将等待至下次查询' % (i + 1) (a1, user_name, a3, a4, a5, a6, a7) = bot_osu.getUserInfo(user_id, score_mode, type_mode='id') mode_name = bot_osu.getMode(score_mode) if float(user[i]["pp"]) > float(new_bp[i]["pp"]): map_id = user[i]["beatmap_id"] map_info = bot_osu.getMapInfo( map_id, score_mode) score_mod = bot_osu.getMod( user[i]["enabled_mods"]) old_pp = float(user[i]["pp"]) new_pp = float( bot_osu.getMapPlay(user_id, map_id, score_mode)) if user_name and map_info and new_pp: msg = '%s倒刷了一张图 (%s)\n谱面bid: %s\n%s\nMod: %s\n倒刷前的pp: %.2f\n现在的pp: %.2f'\ % (user_name, mode_name, map_id, map_info, score_mod, old_pp, new_pp) update_bp = new_bp[0:20] update_bp.append({ "user_id": user_id, "user_name": user_name, "user_mode": score_mode, "user_group": group_list }) bot_global.user_bp_list[num] = update_bp bot_IOfile.write_pkl_data( bot_global.user_bp_list, 'data/data_bp_care_list.pkl') else: map_id = new_bp[i]["beatmap_id"] map_info = bot_osu.getMapInfo( map_id, score_mode) score_rank = bot_osu.getRank(new_bp[i]["rank"]) score_acc = bot_osu.getAcc( new_bp[i]["count300"], new_bp[i]["count100"], new_bp[i]["count50"], new_bp[i]["countmiss"]) score_mod = bot_osu.getMod( new_bp[i]["enabled_mods"]) score_pp = float(new_bp[i]["pp"]) if user_name and map_info: msg = '%s更新了bp%s (%s)\n谱面bid: %s\n%s\n评分: %s\nAcc: %s%%\nMod: %s\npp: %.2f'\ % (user_name, i+1, mode_name, map_id, map_info, score_rank, score_acc, score_mod, score_pp) update_bp = new_bp[0:20] update_bp.append({ "user_id": user_id, "user_name": user_name, "user_mode": score_mode, "user_group": group_list }) bot_global.user_bp_list[num] = update_bp bot_IOfile.write_pkl_data( bot_global.user_bp_list, 'data/data_bp_care_list.pkl') if not newstart: for group in group_list: try: bot.send_group_msg(group_id=group, message=msg) except BaseException: print('群发消息出错, 群号: %s' % group) break bot_global.user_bp_list_lock.release() # 列表解锁 print('本轮查询结束') time.sleep(450) newstart = False else: time.sleep(30) newstart = True
def pickall(card_member, list_c): for i in range(len(list_c)): if card_member == list_c[i]['qq']: if list_c[i]['money_now'] < 100: msg = '金币数量低于100! 快去打图' else: num_all = [0, 0, 0, 0, 0] num_new = [0, 0, 0, 0, 0] pick_time = list_c[i]['money_now'] // 100 list_c[i][ 'money_now'] = list_c[i]['money_now'] - pick_time * 100 msg = '%s次11连结果:' % pick_time card_set = list_c[i]['card'] this_getR = False # 这一轮11连是不是抽到了R以上 total_getR = True # 这次全抽是不是有一轮抽到了R以上 for times in range(pick_time * 11): if times % 11 == 0: this_getR = False (rare_code, new_card) = choose() if rare_code < 4: this_getR = True if times % 11 == 10 and not this_getR: total_getR = False num_all[rare_code] = num_all[rare_code] + 1 getNew = True for j in range(len( card_set[rare_code])): # 如果这张卡不是首次抽到...... if new_card == card_set[rare_code][j]['card_name']: getNew = False card_set[rare_code][j]['card_number'] = card_set[ rare_code][j]['card_number'] + 1 break if getNew: # 如果这张卡是首次抽到...... num_new[rare_code] = num_new[rare_code] + 1 card_set[rare_code].append({ 'card_name': new_card, 'card_number': 1 }) for xx in range(5): msg = msg + '\n【%s系列】获得%s(%s)张卡' % ( rare_name[xx], num_all[xx], num_new[xx]) msg = msg + '\n括号内数字代表图鉴新解锁数量' new_unlock = medalUnlock(card_set) if list_c[i]['medal'][9] == 100 or not total_getR: new_unlock[9] = 100 new_pt = check_pt(card_set, list_c[i]['pt_bonus'], new_unlock) medal_msg = medalUpdate(list_c[i]['medal'], new_unlock) msg = msg + '\n金币数变更: %s → %s' % (list_c[i]['money_now'] + pick_time * 100, list_c[i]['money_now']) msg = msg + '\n机票数变更: %s → %s' % (flyNumCal(list_c[i]['fly']), flyNumCal(list_c[i]['fly'] + pick_time * 10)) msg = msg + '\n活动pt变更: %s → %s' % (list_c[i]['pt_total'], new_pt) if medal_msg: msg = msg + '\n解锁隐藏成就:' + medal_msg list_c[i]['fly'] = list_c[i]['fly'] + pick_time * 10 list_c[i]['card'] = card_set list_c[i]['pt_total'] = new_pt list_c[i]['medal'] = new_unlock list_c[i]['num_pick'] = list_c[i]['num_pick'] + pick_time * 11 (lucky, lucky_rate) = European(list_c[i]) list_c[i]['lucky'] = lucky list_c[i]['lucky_rate'] = lucky_rate bot_IOfile.write_pkl_data(list_c, 'data/data_card_game_list.pkl') return msg msg = '此玩家并未参与活动' return msg
for user in user_list: user_number = user_number + 1 uid = user['uid'] user_pp = user['pp'] result = bot_osu.getUserBp(uid, 0) if not result: error_list.append(user) print('%s. %s的成绩获取失败' % (user_number, uid)) elif len(result) < 35: print('%s. %s的bp数少于35个' % (user_number, uid)) else: bp_rank = 0 for bp_msg in result: bp_rank = bp_rank + 1 if bp_rank > 35: break bid = int(bp_msg['beatmap_id']) mod = int(bp_msg['enabled_mods']) score_acc = bot_osu.getAcc(bp_msg["count300"], bp_msg["count100"], bp_msg["count50"], bp_msg["countmiss"]) score_pp = int(float(bp_msg['pp'])) (new_mod, new_pp) = get_mod(mod, score_pp) sql = 'INSERT INTO bpmsg_mode0 VALUES (%d, %d, %d, %d, %d, %s, %d, %d, %d)' % ( uid, bp_rank, bid, mod, score_pp, score_acc, new_mod, new_pp, user_pp) bot_SQL.action(sql) print('CN %s/%s: %s的bp记录完毕' % (user_number, total_number, uid)) bot_IOfile.write_pkl_data( error_list, 'D:\Python POJ\lxybot_v2\data\data_error_CN_list.pkl') time.sleep(30)
def setCare(list_b, content, group): if content == '!set_bp': msg = '倒是告诉我id啊' elif '!set_bp ' in content: check_id = re.match(r'^!set_bp (.*),([0123])$', content) if check_id: osu_name = check_id.group(1) osu_mode = check_id.group(2) else: check_id = re.match(r'^!set_bp (.*)$', content) if check_id: osu_name = check_id.group(1) osu_mode = '0' else: msg = '您的!set_bp指令使用错误' return msg (osu_id, real_name, pp, pc, tth, acc, sec) = getUserInfo(osu_name, osu_mode) if not osu_id: msg = '查不到这个人哎' elif pp < 500: msg = '该号pp较低, 不进行监视' elif pp > 3000 and group == bot_global.group_total_list[0]: msg = '新人群主群不允许监视pp超过3000的玩家' elif pp > 5000 and group == bot_global.group_total_list[1]: msg = '新人群主群不允许监视pp超过3000的玩家' else: member_exist = False # 列表内是否已经存在这个人 for user in list_b: if user[20]['user_id'] == osu_id and user[20][ 'user_mode'] == osu_mode: member_exist = True if group in user[20]['user_group']: break else: user[20]['user_group'].append(group) msg = '添加%s的本群bp监视成功!' % real_name bot_IOfile.write_pkl_data( list_b, 'data/data_bp_care_list.pkl') return msg if not member_exist: # 全新添加 if len(list_b) > 79: msg = '太……太多人了,bot要承受不住了!' else: bp_msg = getUserBp(osu_id, osu_mode) if len(bp_msg) > 19: new_bp_msg = [] for i in range(20): new_bp_msg.append(bp_msg[i]) user_msg = { 'user_id': osu_id, 'user_name': real_name, 'user_mode': osu_mode, 'user_group': [group] } new_bp_msg.append(user_msg) list_b.append(new_bp_msg) msg = '添加%s的本群bp监视成功!' % real_name bot_IOfile.write_pkl_data( list_b, 'data/data_bp_care_list.pkl') else: msg = 'bp数量低于20个,不进行监视' else: msg = '已经存在此id,无需重复添加' else: msg = '无法识别,bot猜测您是想使用指令!set_bp x(x为参数)' return msg