Example #1
0
async def add_member(bot: KokkoroBot, ev: EventInterface, args: ParseResult):
    bm = BattleMaster(ev.get_group_id())
    clan = _check_clan(bm)

    uid = args['@'] or args.uid
    name = args[''] or args.name
    author = ev.get_author()

    if uid == None:
        uid = ev.get_author_id()
    else:
        if uid != ev.get_author_id():
            _check_admin(ev, '才能添加其他人')
            #  if not ev.whether_user_in_group(uid):
            #  raise NotFoundError(f'Error: 无法获取该群员信息,请检查{uid}是否属于本群')
        ## if we can't get name from mentions
        # if not name and :
        #     m = await bot.get_group_member_info(self_id=ctx['self_id'], group_id=bm.group, user_id=uid)
        #     name = m['card'] or m['nickname'] or str(m['user_id'])

    name = name or author.get_nick_name() or author.get_name()

    mem = bm.get_member(uid, bm.group) or bm.get_member(uid, 0)  # 兼容cmdv1
    if mem:
        bm.mod_member(uid, mem['alt'], name, 1)
        await bot.kkr_send(ev, f'成员{bot.kkr_at(uid)}昵称已修改为{name}')
    else:
        bm.add_member(uid, bm.group, name, 1)
        await bot.kkr_send(
            ev, f"成员{bot.kkr_at(uid)}添加成功!欢迎{name}加入{clan['name']}")
Example #2
0
async def switch_service(bot, ev: EventInterface, turn_on: bool):
    action_tip = '启用' if turn_on else '禁用'

    names = ev.get_param().remain.split()
    if not names:
        await bot.kkr_send(ev, f"空格后接要{action_tip}的服务名", at_sender=True)
        return
    group_id = ev.get_group_id()
    svs = Service.get_loaded_services()
    succ, notfound = [], []
    for name in names:
        if name in svs:
            sv = svs[name]
            u_priv = priv.get_user_priv(ev.get_author())
            if u_priv >= sv.manage_priv:
                sv.set_enable(group_id) if turn_on else sv.set_disable(
                    group_id)
                succ.append(name)
            else:
                try:
                    await bot.kkr_send(
                        ev,
                        f'权限不足!{action_tip}{name}需要:{sv.manage_priv},您的:{u_priv}\n{PRIV_TIP}',
                        at_sender=True)
                except:
                    pass
        else:
            notfound.append(name)
    msg = []
    if succ:
        msg.append(f'已{action_tip}服务:' + ', '.join(succ))
    if notfound:
        msg.append('未找到服务:' + ', '.join(notfound))
    if msg:
        await bot.kkr_send(ev, '\n'.join(msg), at_sender=True)
Example #3
0
async def login(bot: KokkoroBot, ev: EventInterface, args: ParseResult):
    if False and "this message is from group":  # FIXME
        return '请私聊使用'

    wm = WebMaster()
    uid = ev.get_author_id()
    gid = ev.get_group_id()
    auth = ev.get_author().get_priv()

    member = wm.get_member(uid, gid)
    if member is None:
        await bot.kkr_send(ev, '请先加入公会')
        return
    member['authority_group'] = 100
    if auth == SUPERUSER:
        member['authority_group'] = 1
    elif auth == ADMIN:
        member['authority_group'] = 10
    wm.mod_member(member)

    user = wm.get_or_add_user(uid, rand_string(16))
    login_code = rand_string(6)
    user['login_code'] = login_code
    user['login_code_available'] = True
    user['login_code_expire_time'] = int(time.time()) + 60
    wm.mod_user(user)

    url = urljoin(
        config.PUBLIC_ADDRESS, '{}login/c/#uid={}&key={}'.format(
            config.PUBLIC_BASEPATH,
            user['uid'],
            login_code,
        ))
    await bot.kkr_send_dm(ev, url)
async def on_input_chara_name(bot: KokkoroBot, ev: EventInterface):
    gid = ev.get_group_id()
    uid = ev.get_author_id()
    if winner_judger.get_on_off_status(gid):
        s = ev.get_param().remain
        cid = chara.name2id(s)
        correct_id = winner_judger.get_result(gid)
        if cid != chara.UNKNOWN and cid == winner_judger.get_result(gid) and winner_judger.get_winner(gid) == None:
            winner_judger.record_winner(gid, uid)
            winning_counter = WinningCounter(DB_PATH)
            winning_counter._record_winning(gid, uid)
            winning_count = winning_counter._get_winning_number(gid, uid)
            nick = ev.get_author().get_nick_name()
            msg_part = f'{nick}猜对了,真厉害!TA已经猜对{winning_count}次了~'
            c = chara.fromid(correct_id)
            msg =  f'正确答案是: {c.name}'
            await bot.kkr_send(ev, msg)
            await bot.kkr_send(ev, c.icon)
            await bot.kkr_send(ev, msg_part)

            winner_judger.turn_off(gid)
Example #5
0
def _check_admin(ev: EventInterface, tip: str = '') -> bool:
    if not priv.check_priv(ev.get_author(), priv.ADMIN):
        raise PermissionDeniedError(ERROR_PERMISSION_DENIED + tip)
Example #6
0
async def send_report(bot:KokkoroBot, event:EventInterface, type=REPORT_UNDECLARED):

    if type not in (REPORT_RESIGN,REPORT_NORMAL):
        await bot.kkr_send(event, "类型错误!", at_sender=True)
        return

    uid = event.get_author_id()
    nickname = event.get_author().get_nick_name()
    gid = event.get_group_id()

    if not _lmt.check(uid):
        await bot.kkr_send(event, f'每{int(_time_limit/60)}分钟仅能生成一次报告', at_sender=True)
        return
    _lmt.start_cd(uid)

    now = datetime.datetime.now()
    year = now.year
    month = now.month-1
    if month==0:
        year -= 1
        month = 12
    constellation = b_constellations[month-1]

    try:
        clanname, challenges = get_person(gid,uid,month)
    except Exception as e:
        await bot.kkr_send(event, f"出现错误: {str(e)}\n请联系开发组调教。")
        return

    if challenges.shape[0] == 0:
        await bot.kkr_send(event, "您没有参加本次公会战。请再接再厉!", at_sender=True)
        return

    total_chl = 0
    miss_chl = 0
    damage_to_boss: list = [0 for i in range(5)]
    times_to_boss: list = [0 for i in range(5)]
    truetimes_to_boss: list = [0 for i in range(5)]
    total_damage = 0

    for idx,chl in challenges.iterrows():
        total_damage += chl['dmg']
        times_to_boss[chl['boss']-1] += 1
        if chl['flag'] == 0:
            damage_to_boss[chl['boss']-1] += chl['dmg']
            truetimes_to_boss[chl['boss']-1] += 1
        if chl['flag'] != 1:
            total_chl += 1
        if chl['dmg'] == 0:
        	miss_chl += 1

    avg_day_damage = int(total_damage/6)
    df=pd.DataFrame({'a':damage_to_boss,'b':truetimes_to_boss})
    result=(df.a/df.b).replace(np.inf,0).fillna(0)
    avg_boss_damage = list(result)
    if total_chl >= 18:
        disable_chl = 0
        attendance_rate = 100
    else:
        disable_chl = 18 - total_chl
        attendance_rate = round(total_chl/18*100,2)

    #日期转字符串
    year=str(year)
    month=str(month)
    
    #设置中文字体
    plt.rcParams['font.family'] = ['Microsoft YaHei']
    x = [f'{x}王' for x in range(1,6)]
    y = times_to_boss
    plt.figure(figsize=(4.3,2.8))
    ax = plt.axes()

    #设置标签大小
    plt.tick_params(labelsize=15)

    #设置y轴不显示刻度
    plt.yticks([])

    #绘制刀数柱状图
    recs = ax.bar(x,y,width=0.618,color=['#fd7fb0','#ffeb6b','#7cc6f9','#9999ff','orange'],alpha=0.4)

    #删除边框
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.spines['bottom'].set_visible(False)
    ax.spines['left'].set_visible(False)

    #设置数量显示
    for i in range(0,5):
        rec = recs[i]
        h = rec.get_height()
        plt.text(rec.get_x()+0.1, h, f'{int(times_to_boss[i])}刀',fontdict={"size":12})
    buf = BytesIO()
    plt.savefig(buf, format='png', transparent=True, dpi=120)
    bar_img1 = Image.open(buf)
    #清空图
    plt.clf()

    x = [f'{x}王' for x in range(1,6)]
    y = avg_boss_damage
    plt.figure(figsize=(4.3,2.8))
    ax = plt.axes()

    #设置标签大小
    plt.tick_params(labelsize=15)

    #设置y轴不显示刻度
    plt.yticks([])

    #绘制均伤柱状图
    recs = ax.bar(x,y,width=0.618,color=['#fd7fb0','#ffeb6b','#7cc6f9','#9999ff','orange'],alpha=0.4)

    #删除边框
    ax.spines['top'].set_visible(False)
    ax.spines['right'].set_visible(False)
    ax.spines['bottom'].set_visible(False)
    ax.spines['left'].set_visible(False)

    #设置数量显示
    for i in range(0,5):
        rec = recs[i]
        h = rec.get_height()
        plt.text(rec.get_x(), h, f'{int(avg_boss_damage[i]/10000)}万',fontdict={"size":12})

    buf = BytesIO()
    plt.savefig(buf, format='png', transparent=True, dpi=120)
    bar_img2 = Image.open(buf)

    #将饼图和柱状图粘贴到模板图,mask参数控制alpha通道,括号的数值对是偏移的坐标
    current_folder = os.path.dirname(__file__)
    img = background1.open() if type==REPORT_RESIGN else background2.open()
    R
    img.paste(bar_img1, (580,950), mask=bar_img1.split()[3])
    img.paste(bar_img2, (130,950), mask=bar_img2.split()[3])

    #添加文字到img
    row1 = f'''
    {total_chl}

    {disable_chl}

    {total_damage}
    '''
    row2 = f'''
    {attendance_rate}%

    {miss_chl}

    {avg_day_damage}
    '''
    
    add_text(img, row1, position=(380,630), textsize=35, textfill='black')
    add_text(img, row2, position=(833,630), textsize=35, textfill='black')
    add_text(img, year, position=(355,438), textsize=40, textfill='black')
    add_text(img, month, position=(565,438), textsize=40, textfill='black')
    add_text(img, constellation, position=(710,438), textsize=40, textfill='black')
    if len(clanname) <= 7:
        add_text(img, clanname, position=(300+(7-len(clanname))/2*40, 515), textsize=40, textfill='black')
    else:
        add_text(img, clanname, position=(300+(10-len(clanname))/2*30, 520), textsize=30, textfill='black')
    add_text(img, nickname, position=(280,365), textsize=35, textfill='white')
    #输出
    await bot.kkr_send(event, img)
    plt.close('all')
async def send_normal_report(bot:KokkoroBot, event:EventInterface):
    uid = event.get_author_id()
    nickname = event.get_author().get_nick_name()
    gid = event.get_group_id()
    report = gen_report(gid, uid, nickname, type=REPORT_NORMAL)
    await bot.kkr_send(event, report)