async def onCommand(app: App, e: GroupMessageRecvEvent): groupId = e.group.id argument = str(e.msg).strip() if e.group.permission == PermissionType.Member: return if not existElem(settings['enabled_groups'], groupId): return if len(argument) == 0: app.sendGroupMessage( groupId, Message.phrase(RefMsg(target=e.sender.id), ("欢迎来玩转轮手枪~\n" "嘎嘎嘎~这是一个恐怖的游戏!\n" f"{app.nickname}会为一把六发左轮的弹舱随机装入一发弹药\n" f"使用“{app.commandHead}扣扳机”来参加比赛 嘻嘻嘻\n" "与赛的各位,依次把枪口调向自己,扣动扳机,直到...砰——子弹出膛!"))) if groupInfo[groupId.id].idle: app.sendGroupMessage( groupId, Message.phrase(RefMsg(target=e.sender.id), "已经重新装填弹药咯!")) else: app.sendGroupMessage( groupId, Message.phrase(RefMsg(target=e.sender.id), "本轮比赛还没有结束哟~"))
async def groupViewTrees(app: App, e: GroupMessageRecvEvent): name = '你' msg = e.msg msg.chain() record = userdb(userid=e.sender.id) empty = True if len(record) > 0: reply = "你的树林里有以下树木👇\n" bag = record[0]['bag'] ids = list(bag.keys()) ids.sort(reverse=True) for treeId in bag: cnt = bag[treeId] if cnt > 0: empty = False item = getItemDetail(treeId) reply += f" 【{getQualityDescription(item['quality'])}】{item['name']}×{cnt}\n" reply = reply[:-1] if empty: app.sendGroupMessage( e.group.id, Message.phrase(RefMsg(target=e.sender.id), "哎呀,你的树林空空如也呢,快去种树吧~")) else: app.sendGroupMessage(e.group.id, Message.phrase(RefMsg(target=e.sender.id), reply))
async def plantCommand(app: App, e: GroupMessageRecvEvent): groupId = e.group.id masterId = settings['master'] if not existElem(settings['enabled_groups'], groupId): return if e.group.permission == PermissionType.Member: app.sendGroupMessage( groupId, Message.phrase(RefMsg(target=e.sender.id), " 需要管理员权限才能执行该指令嗷~")) return if (masterId == 0 and e.sender.permission == PermissionType.Member) \ or (masterId != 0 and masterId != e.sender.id): app.sendGroupMessage( groupId, Message.phrase(RefMsg(target=e.sender.id), " 你没有权限哟~")) return if len(e.msg.msgChain) == 0: app.sendGroupMessage( groupId, Message.phrase(RefMsg(target=e.sender.id), " 格式是\"赐名 @成员 头衔\"哦~")) return atCodes = e.msg.getAtCodes() if (len(atCodes) != 1): app.sendGroupMessage( groupId, Message.phrase(RefMsg(target=e.sender.id), " 格式不对喔~")) return app.setSpecialTitle(groupId, atCodes[0].target, str(e.msg.msgChain[2]).strip()) app.sendGroupMessage(groupId, Message.phrase(RefMsg(target=e.sender.id), " 操作成功~"))
async def Solo(app: App, e: GroupMessageRecvEvent): arguments = str(e.msg).strip() if len(arguments) == 0: app.sendGroupMessage( e.group, Message.phrase(RefMsg(target=e.sender.id), ("" "")))
async def wrapper(app: App, e: GroupMessageRecvEvent): groupId = e.group.id if not existElem(settings['enabled_groups'], groupId): return if not await func(app, e): app.sendGroupMessage( groupId, Message.phrase(RefMsg(target=e.sender.id), ( "使用方法: .(google | baidu | github | bilibili) search_string" )))
def plantComplete(app: App, groupId: int, memberId: int, type: str = 'success'): info = db(groupId=groupId, memberId=memberId)[0] if type == 'success': proc = info['duration'] / settings['max_time'] * 100 treeId, quality = lottery(proc) app.sendGroupMessage( groupId, Message.phrase( RefMsg(target=memberId), "的树长大啦!\n" f"{getCongratulations(quality)}" f"你获得了“{getQualityDescription(quality)}”品质的" f"{getItemDetail(treeId)['name']}~")) record = userdb(userid=memberId) if len(record) != 0: record = record[0] if treeId not in record['bag']: record['bag'][treeId] = 1 else: record['bag'][treeId] += 1 record['accumulate'] += info['duration'] else: userdb.insert(userid=memberId, bag={treeId: 1}, accumulate=info['duration']) userdb.commit() elif type == 'cancel': app.sendGroupMessage( groupId, Message.phrase(RefMsg(target=memberId), "取消了种树,树枯萎了...")) app.unmute(groupId, memberId) else: return del db[info['__id__']]
async def Solo(app: App, e: GroupMessageRecvEvent): arguments = str(e.msg).strip() if len(arguments) == 0: app.sendGroupMessage( e.group, Message.phrase(RefMsg(target=e.sender.id), ("欢迎来玩拼点~\n" "“拼点@对方”可以下达战书或者应战\n" "“不拼@对方”可以拒绝对方的挑战\n" "“弃拼”可以放弃挑战\n" "“查战书”可以查看有谁向你发起了挑战\n" "“大拼点n倍@对方”可以向对方发起赌上尊严的挑战(倍率为n哦)!\n" "【注意】已经有等待对方接受的战书后,就不能再发战书了哦~\n" "【注意】大拼点会占用拼点的战书槽,且要用“大拼点@对方”进行应战")))
async def unplantCommand(app: App, e: ContactMessageRecvEvent): async def sessionHandler(app: App, e: ContactMessageRecvEvent): sender = e.sender contactId = e.sender.id message = str(e.msg).strip() session = sessions.getSession(contactId) step = session.step() if step == 1: options = session.get('options') optionCnt = session.get('optionCnt') if str.isdigit(message): id = int(message) if 1 <= id <= optionCnt: app.replyContactMessage(sender, ("你确定嘛?\n" "输入“确定”放弃种树,输入其他内容取消操作")) session.set('groupId', options[id]) session.next() else: app.replyContactMessage(sender, "范围要正确哦~") elif message == "取消": app.replyContactMessage(sender, "取消啦~") sessions.closeSession(contactId) app.unredirect(str(contactId)) else: app.replyContactMessage(sender, "输入的内容不正确~") elif step == 2: if message == "确定": app.replyContactMessage(sender, "臭水群怪,给你解除禁言了喔~") groupId = session.get('groupId') plantComplete(app, groupId, contactId, type='cancel') sessions.closeSession(contactId) app.unredirect(str(contactId)) crontab.remove(f'{groupId}.{contactId}') else: app.replyContactMessage(sender, "未输入确定,操作取消啦~继续专注喔~") sessions.closeSession(contactId) app.unredirect(str(contactId)) sender = e.sender contactId = e.sender.id session = sessions.createSession(contactId) records = db(memberId=contactId) if len(records) == 0: app.replyContactMessage(sender, "你没有在种的树哦~") return options: Dict[int, int] = {} reply = '' optCnt = 0 for r in records: optCnt += 1 options[optCnt] = r['groupId'] reply += f'{optCnt}. {r["groupName"]}\n' session.set('options', options) session.set('optionCnt', optCnt) session.next() app.replyContactMessage( sender, Message.phrase(("你有以下几个正在种树的群\n" + reply + "请输入序号(仅数字)\n" "输入“取消”继续种树"))) guid = str(contactId) app.redirectContact(guid, contactId, sessionHandler)
async def plantCommand(app: App, e: GroupMessageRecvEvent): groupId = e.group.id memberId = e.sender.id message = str(e.msg).strip() if e.group.permission == PermissionType.Member: return if not existElem(settings['enabled_groups'], groupId): return if len(str(message).strip()) == 0: app.sendGroupMessage( groupId, Message.phrase(RefMsg(target=memberId), ("欢迎使用种树功能\n" "不 要 挑 战 自 制 力!\n" f"如果无法专注忍不住想水群,就让{app.nickname}来帮助你吧!\n" "使用\n" f"{app.commandHead}种树{{时间}}min\n" f"{app.commandHead}种树{{时间}}h\n" f"{app.commandHead}种树{{时间}}d\n" f"{app.commandHead}种树{{时间}}s\n" "给自己安排对应时长的禁言w\n" f"时长需要在{formatTime(settings['min_time'])}" f"到{formatTime(settings['max_time'])}之间\n" f"私聊我,使用“{app.commandHead}放弃种树”指令可以放弃~\n" f"私聊或者在群中使用“{app.commandHead}逛树林”可以查看自己拥有的树喔~\n" "种树结束会获得一颗树哦,种树时间越久越容易出现珍稀品种~"))) return m = re.match(r'^(\d+(\.\d+)?)\s*(h|d|min|s)$', message) if m is None: app.sendGroupMessage( groupId, Message.phrase(RefMsg(target=memberId), (f"格式不对哦,使用 {app.commandHead[0]}种树 查看帮助"))) return num = float(m.group(1)) unit = str(m.group(3)) sec: int if unit == 'min': sec = minToSec(num) elif unit == 'h': sec = hourToSec(num) elif unit == 'd': sec = dayToSec(num) elif unit == 's': sec = int(num) if sec > settings['max_time'] or sec < settings['min_time']: app.sendGroupMessage( groupId, Message.phrase(RefMsg(target=memberId), (f"你输入的是{formatTime(sec)}\n" "种树时间不可取喔~\n" f"需要在{formatTime(settings['min_time'])}" f"到{formatTime(settings['max_time'])}之间~"))) return app.mute(groupId, memberId, sec) app.sendGroupMessage( groupId, Message.phrase(RefMsg(target=memberId), (f"要专注哦~{app.nickname}为你加油!"))) rec = db(groupId=groupId, memberId=memberId) if len(rec) != 0: del db[rec[0]['__id__']] db.insert(groupId=groupId, memberId=memberId, groupName=e.group.name, duration=sec, endTime=round(time.time()) + sec) crontab.add(f'{groupId}.{memberId}', sec, plantComplete, (app, groupId, memberId))