예제 #1
0
 def mapList2Redis(self, bids, groupid, qqid):
     rds = interRedis.connect('inter4')
     key = 'RECORD_MAPLIST:{groupid}:{qqid}'.format(groupid=groupid,
                                                    qqid=qqid)
     for bid in bids:
         rds.lpush(key, bid)
     return
예제 #2
0
def mybp(**kw):
    x = "1" if not kw['iargs'] else kw['iargs'][0]
    if int(x) < 0 or int(x) > 100:
        x = "1"
    b = botHandler.botHandler()
    osuinfo = b.getOsuInfo2(kw['qqid'])
    logging.info(osuinfo)
    if osuinfo:
        osuid = osuinfo['osuid']

        key = 'OSU2_USERBP:%s'
        rds = interRedis.connect('osu2')
        rdsRs = rds.get(key % osuid)
        if not rdsRs:
            recinfo = b.getRecBp(osuid, "100")
            rds.setex(key % osuid, json.dumps(recinfo), 900)
        else:
            recinfo = json.loads(rdsRs)

        if not recinfo:
            res = "别复读好马!"
        else:
            res, kv = b.getRctppRes(recinfo[int(x) - 1])
            # 执行管理逻辑
            b.rctppSmoke(kw["groupid"], kw["qqid"], kv)
    else:
        res = "你倒是绑定啊.jpg"
    return res
예제 #3
0
def filter_rec(uid, rec):
    # 返回入库bids
    rds = interRedis.connect()
    key = 'rec_%s' % uid
    ret = rds.get(key)
    bids = []
    # rec直接缓存
    if ret is None:
        indata = dict((r['beatmap_id'],r['date']) for r in rec)
        rds.setex(key, json.dumps(indata), 60 * 60 * 12)
        bids = [r['beatmap_id'] for r in rec]
    else:
        res = json.loads(ret)
        for r in rec:
            if r['beatmap_id'] in res:
                if r['date'] != res[r['beatmap_id']]:
                    res['beatmap_id'] = r['date']
                    bids.append(r['beatmap_id'])
                else:
                    break
            else:
                res[r['beatmap_id']] = r['date']
                bids.append(r['beatmap_id'])
        rds.setex(key, json.dumps(res), 60 * 60 * 12)
    # 测试
    if istest:
        rds.delete(key)
    return bids
예제 #4
0
 def collect_chat2redis(self):
     chat_Lst = self.get_random_db_chat()
     chat_str = json.dumps(chat_Lst)
     rds = interRedis.connect('osu2')
     rs = rds.setex(Config.CHAT_RANDOM_KEY, chat_str, 3600)
     logging.info("chat set to redis rs:%s", rs)
     return rs
예제 #5
0
 def recordRecMap(self, qqid, groupid):
     """开启记录推荐消息标记
     """
     rds = interRedis.connect('osu2')
     k = 'RECORD_MAP:{groupid}:{qqid}'.format(groupid=groupid, qqid=qqid)
     if rds.exists(k):
         return -1
     rds.setex(k, 1, 3600)
     return 1
예제 #6
0
 def random_chat(self):
     try:
         rds = interRedis.connect('osu2')
         rs = rds.get(Config.CHAT_RANDOM_KEY)
         chat_lst = json.loads(rs)
         msg = random.choice(chat_lst)
         return msg
     except:
         logging.exception("")
     return None
예제 #7
0
 def recordRecMapList(self, qqid, groupid):
     """查询推荐列表
     """
     rds = interRedis.connect('osu2')
     k = 'RECORD_MAPLIST:{groupid}:{qqid}'.format(groupid=groupid,
                                                  qqid=qqid)
     if not rds.exists(k):
         return -1
     r = rds.lrange(k, 0, -1)
     return r
예제 #8
0
def sttest_start(func, qqid, groupid, step):
    rds = interRedis.connect('inter1')
    key = Config.CMDSTEP_KEY.format(qq=qqid, groupid=groupid, func=func)
    rs = rds.incr(key)
    rds.expire(key, Config.CMDSTEP_KEY_EXPIRE_TIME)
    end = 0
    if rs >= 3:
        rds.delete(key)
        key2 = Config.FUNC_ACTIVE_KEY.format(qq=qqid, groupid=groupid)
        rds.srem(key2, func)
        end = 1
    return end
예제 #9
0
 def getFuncStep(self, func, qq, groupid, isinteractive):
     """取步数
     """
     if not isinteractive:
         return 0
     rds = interRedis.connect('inter1')
     key = Config.CMDSTEP_KEY.format(qq=qq, groupid=groupid, func=func)
     rs = rds.get(key)
     if not rs:
         return 0
     else:
         return rs
예제 #10
0
 def check_redis_is_selfchat(self, groupid, selfqq):
     """检测最后是不是自己消息
     """
     try:
         rds = interRedis.connect('osu2')
         key = 'chatlog_%s' % groupid
         chatlog = rds.get(key)
         chatlog = json.loads(chatlog) if chatlog else [{}]
         if int(chatlog[0].get('qq', 0)) == selfqq:
             return True
     except:
         logging.exception("")
     return False
예제 #11
0
 def interactiveFuncRef(self, qq, groupid, msg):
     """交互式映射,自动补充命令
         当超过2个时,变更为指定式
     """
     replyFlag = 0
     rds = interRedis.connect('inter1')
     key = Config.FUNC_ACTIVE_KEY.format(qq=qq, groupid=groupid)
     if '!' not in msg:
         activeCmds = rds.smembers(key)
         acs = len(activeCmds)
         if acs == 1:
             msg = '!%s %s' % (list(activeCmds)[0], msg)
         elif acs > 1:
             msg = '当前使用交互式命令>2,请选择指定命令交互!cmd content,当前绑定命令为%s' % activeCmds
             replyFlag = 1
     return replyFlag, msg
예제 #12
0
def boom_check(**kw):
    qqid = kw['qqid']
    atqq = kw['atqq']
    groupid = kw['groupid']
    # 群限定
    if int(groupid) != Config.GROUPID["XINRENQUN"]:
        return ''
    rds = interRedis.connect('osu2')
    key = f'SMOKE_TS_{groupid}|{atqq}'
    rs = rds.get(key)
    if not rs:
        return ''
    # 越狱概率
    if random.random() >= 0.5:
        rds.delete(key)
        return f'在{qqid}的帮助下{atqq}越狱成功!'
    
    v = json.loads(rs)
    nowts = time.time()
    ts = v['ts']
    endts = v['endts']
    # 已经释放出狱
    if nowts >= endts:
        return
    
    # 重新计算入狱时间
    leftts = endts - nowts
    ts = leftts + leftts*0.5
    endts += leftts*0.5
    v = json.dumps({'nowts': nowts, 'endts': endts, 'ts': ts})
    rds.setex(key, v, int(ts))
    rds.expire(key, int(ts))

    # 帮凶承担一半时间
    ts2 = ts * 0.5
    endts2 = nowts + ts2
    key2 =  f'SMOKE_TS_{groupid}|{qqid}'
    v2 = json.dumps({'nowts': nowts, 'endts': endts2, 'ts': ts2})
    rds.setex(key2, v2, int(ts2))
    rds.expire(key2, int(ts2))

    time.sleep(0.5)
    pushTools.pushSmokeCmd(groupid, atqq, ts)
    pushTools.pushSmokeCmd(groupid, qqid, ts2)

    s = f'检测到越狱行为,{qqid}尝试解救{atqq}失败,双双入狱'
    return s
예제 #13
0
    def stopRecordRecMap(self, qqid, groupid):
        """结束记录推荐消息标记,请求打包api
        """
        rds = interRedis.connect('osu2')
        k = 'RECORD_MAP:{groupid}:{qqid}'.format(groupid=groupid, qqid=qqid)
        k2 = 'RECORD_MAPLIST:{groupid}:{qqid}'.format(groupid=groupid,
                                                      qqid=qqid)
        # 取图链拼装请求
        bids = rds.lrange(k2, 0, -1)
        if not bids:
            return -1
        args = ','.join(bids)
        rs = self.getMapTarDownLink(args)
        if rs:
            rds.delete(k)
            rds.delete(k2)

        return rs
예제 #14
0
 def Chat2Redis(self, groupid, qq, message):
     try:
         rds = interRedis.connect('osu2')
         key = 'chatlog_%s' % groupid
         chatlog = rds.get(key)
         chatlog = json.loads(chatlog) if chatlog else []
         chat_msg = {
             'qq': qq,
             'content': message,
             'time': datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
         }
         chatlog.insert(0, chat_msg)
         if len(chatlog) > 50:
             chatlog.pop()
         rds.set(key, json.dumps(chatlog))
     except:
         logging.exception("")
     return
예제 #15
0
    def recordRecommendMap(self):
        """记录热推荐图任务
        说明:
            通过命令方式启动记录
            key1 记录 通行 incr实现
            key2 写 真实记录 list实现
        """
        qqid = self.context['user_id']
        groupid = self.context['group_id']
        rds = interRedis.connect('inter4')
        tagskey = 'RECORD_MAP:{groupid}:{qqid}'.format(groupid=groupid,
                                                       qqid=qqid)
        if not rds.exists(tagskey):
            return ''

        logging.info('存在记录key,进行推荐记录')
        bids = self.recommendMapFilter(self.context['message'])
        self.mapList2Redis(bids, groupid, qqid)
        return ''
예제 #16
0
def mybp(**kw):
    qqid = kw['qqid']
    if not kw['iargs']:
        x = 1  
    else:
        input0 = kw['iargs'][0]
        args0 = input0.replace(f'[CQ:at,qq={qqid}]', '')
        x = int(args0) if args0.isdigit() else 1

    if x < 0 or x > 100:
        x = 1
    b = botHandler.botHandler()
    osuid = kw['autoOusInfoKey']['osuid']
    osuname = kw['autoOusInfoKey']['osuname']
    smoke_res = None
    key = 'OSU2_USERBP:%s'
    rds = interRedis.connect('osu2')
    rdsRs = rds.get(key % osuid)
    if not rdsRs:
        recinfo = b.getRecBp(osuid, "100")
        rds.setex(key % osuid, json.dumps(recinfo), 900)
    else:
        recinfo = json.loads(rdsRs)

    if not recinfo:
        res = "别复读好马!"
    else:
        res, kv = b.getRctppResNew(recinfo[x-1])
        res = f"{osuname}\n{res}"
        # 执行管理逻辑
        smoke_res = b.rctppSmoke(kw["groupid"], kw["qqid"], kv, iswarn=1)
        if smoke_res:
            res += f'\n>>{smoke_res}<<'
    if smoke_res:
        return f'{osuname}\n由于触发本群限制,请私聊查询,触犯法律:{smoke_res}'
    return res
예제 #17
0
def mybpdraw(**kw):
    qqid = kw['qqid']
    if not kw['iargs']:
        x = 1  
    else:
        input0 = kw['iargs'][0]
        args0 = input0.replace(f'[CQ:at,qq={qqid}]', '')
        x = int(args0) if args0.isdigit() else 1

    if x < 0 or x > 100:
        x = 1
    b = botHandler.botHandler()
    osuid = kw['autoOusInfoKey']['osuid']
    osuname = kw['autoOusInfoKey']['osuname']
    smoke_res = None

    key = 'OSU2_USERBP:%s'
    rds = interRedis.connect('osu2')
    rdsRs = rds.get(key % osuid)
    if not rdsRs:
        recinfo = b.getRecBp(osuid, "100")
        rds.setex(key % osuid, json.dumps(recinfo), 900)
    else:
        recinfo = json.loads(rdsRs)

    if not recinfo:
        res = "别复读好马!"
    else:
        p, kv = b.drawRctpp(osuid, osuname, recinfo=recinfo[x-1], bestinfo=recinfo[x-1])
        res = "[CQ:image,cache=0,file=http://interbot.cn/itbimage/tmp/%s]" % p
        # 执行管理逻辑
        smoke_res = b.rctppSmoke(kw["groupid"], kw["qqid"], kv, iswarn=1)

    if smoke_res:
        return f'{osuname}\n由于触发本群限制,请私聊查询,触犯法律:{smoke_res}'
    return res
예제 #18
0
    def autoApi(self, msg, replyFlag):
        """api检测,自动调用
        Args:
            replyFlag 直接出参代替调用
        """
        cmd = self.extractCmd(msg)
        res = self.getCmdRef(cmd)

        # 直接回复
        if replyFlag:
            return self.returnHandler(msg, ['*at'], self.context)

        logging.info('提取的cmd[%s]', cmd)

        if not res:
            return ''

        # 权限控制
        s, r = self.checkPermission(cmd)
        if s < 0:
            return r

        # 帮助选项
        if '*h' in msg or not res['location']:
            return res['reply']

        apiUrl = '{location}{api}'.format(location=res['location'],
                                          api=res['url'])

        # 参数提取
        iargs = self.extractArgs(msg, cmd)
        # 选项提取
        opts = self.extractOptions(msg)
        atqq = self.extractAtqqid(msg)

        qqid = self.context['user_id']
        groupid = self.context['group_id']

        # 配置回复选项
        if res['at']:
            opts.append('*at')

        if res['toprivate']:
            opts.append('*toprivate')

        if res['image']:
            opts.append('*image')
            if res['image'] == 'bg':
                opts.append('*bg')
            if res['image'] == 'stat':
                opts.append('*stat')

        isInteractive = res['interactive']
        # 交互式命令判断
        step = self.getFuncStep(res['url'][1:], qqid, groupid, isInteractive)
        # 写入命令列表
        if isInteractive:
            rds = interRedis.connect('inter1')
            key = Config.FUNC_ACTIVE_KEY.format(qq=qqid, groupid=groupid)
            rds.sadd(key, cmd[1:])

        # 调用核心
        res = requests.post(apiUrl,
                            data={
                                "iargs": json.dumps(iargs),
                                "qqid": qqid,
                                "groupid": groupid,
                                "atqq": atqq,
                                "step": step
                            })
        if res.status_code == 200 and res.text:
            return self.returnHandler(res.text, opts, self.context)
        elif res.status_code != 200:
            logging.info('调用[%s]异常' % apiUrl)
        return ''