Пример #1
0
async def broadcast(session: CommandSession):
    msg = session.current_arg
    if not ' ' in msg:
        await session.send(f'请输入服务名,全群广播则输入all')
        return
    args = msg.split(' ',1)
    bc_sv_name =  args[0]
    bc_msg = args[1]
    svs = Service.get_loaded_services()
    if bc_sv_name not in svs and bc_sv_name != 'all':
        await session.send(f'未找到该服务,请输入正确的服务')
        return
    sid = list(hoshino.get_self_ids())[0]
    if bc_sv_name == 'all':
        gl = await session.bot.get_group_list(self_id=sid)
        gl = [ g['group_id'] for g in gl ]
    else:
        enable_groups = await svs[bc_sv_name].get_enable_groups()
        gl = enable_groups.keys()
    for sid in hoshino.get_self_ids():
        for g in gl:
            await asyncio.sleep(0.5)
            try:
                msg_obj = await session.bot.send_group_msg(self_id=sid, group_id=g, message=bc_msg)
                with await lock:
                    broadcast_record.append(msg_obj['message_id'])
                hoshino.logger.info(f'群{g} 投递广播成功')
            except Exception as e:
                hoshino.logger.error(f'群{g} 投递广播失败:{type(e)}')
                try:
                    await session.send(f'群{g} 投递广播失败:{type(e)}')
                except Exception as e:
                    hoshino.logger.critical(f'向广播发起者进行错误回报时发生错误:{type(e)}')
    await session.send(f'广播完成!')
    await asyncio.sleep(120)
    with await lock:
        broadcast_record.clear()
Пример #2
0
async def auth_status_chat(session):
    if session.event.user_id not in hoshino.config.SUPERUSERS:
        return
    for sid in hoshino.get_self_ids():
        sgl = set(g['group_id']
                  for g in await session.bot.get_group_list(self_id=sid))
        frl = set(f['user_id']
                  for f in await session.bot.get_friend_list(self_id=sid))
    # 直接从service里抄了, 面向cv编程才是真
    gp_num = len(sgl)
    fr_num = len(frl)
    key_num = len(util.get_key_list())
    agp_num = len(util.get_authed_group_list())
    msg = f'Bot账号:{sid}\n所在群数:{gp_num}\n好友数:{fr_num}\n授权群数:{agp_num}\n未使用卡密数:{key_num}'
    await session.send(msg)
Пример #3
0
async def billing(session: CommandSession):
    bot = session.bot
    args = session.current_arg_text.split()
    try:
        for i in range(0, len(args), 2):
            args[i] = int(args[i])
            assert re.fullmatch(r'\d{4}-\d{2}-\d{2}',
                                args[i + 1]), f"{args[i + 1]}不是合法日期"
    except (ValueError, AssertionError) as e:
        await session.finish(str(e))

    try:
        sid_group = {}
        for sid in hoshino.get_self_ids():
            gs = await bot.get_group_list(self_id=sid)
            sid_group[sid] = [g['group_id'] for g in gs]
    except CQHttpError as e:
        await session.finish(str(e))

    failed = []
    not_found = []
    for i in range(0, len(args), 2):
        gid = args[i]
        date = args[i + 1]
        bill_sent_flag = False
        for sid, groups in sid_group.items():
            if gid in groups:
                msg = f"本群bot将于/已于{date}到期,请及时联系{hoshino.config.SUPERUSERS[0]}续费,以免影响使用!"
                oid = await get_group_owner_id(bot, sid, gid)
                if oid:
                    msg = str(ms.at(oid)) + msg
                try:
                    await bot.send_group_msg(self_id=sid,
                                             group_id=gid,
                                             message=msg)
                    bill_sent_flag = True
                except CQHttpError:
                    failed.append(gid)
                    try:
                        await session.send(f"bot{sid} 向 群{gid} 发送billing失败!")
                    except CQHttpError:
                        hoshino.logger.critical(
                            (f"bot{sid} 向 群{gid} 发送billing失败!且回报SUPERUSER失败!"))
        if not bill_sent_flag and gid not in failed:
            not_found.append(gid)

    msg = f"发送bill完毕!\n失败{len(failed)}:{failed}\n未找到{len(not_found)}:{not_found}"
    await session.send(msg)
Пример #4
0
    async def get_enable_groups(self) -> dict:
        """获取所有启用本服务的群

        @return { group_id: [self_id1, self_id2] }
        """
        gl = defaultdict(list)
        for sid in hoshino.get_self_ids():
            sgl = set(g['group_id']
                      for g in await self.bot.get_group_list(self_id=sid))
            if self.enable_on_default:
                sgl = sgl - self.disable_group
            else:
                sgl = sgl & self.enable_group
            for g in sgl:
                gl[g].append(sid)
        return gl
Пример #5
0
async def broadcast(session: CommandSession):
    msg = session.current_arg
    for sid in hoshino.get_self_ids():
        gl = await session.bot.get_group_list(self_id=sid)
        gl = [g['group_id'] for g in gl]
        for g in gl:
            await asyncio.sleep(0.5)
            try:
                await session.bot.send_group_msg(self_id=sid, group_id=g, message=msg)
                hoshino.logger.info(f'群{g} 投递广播成功')
            except Exception as e:
                hoshino.logger.error(f'群{g} 投递广播失败:{type(e)}')
                try:
                    await session.send(f'群{g} 投递广播失败:{type(e)}')
                except Exception as e:
                    hoshino.logger.critical(f'向广播发起者进行错误回报时发生错误:{type(e)}')
    await session.send(f'广播完成!')
Пример #6
0
async def broadcast(session: CommandSession):
    msg = session.current_arg.split(' ')
    try:
        target = int(msg[0])
    except Exception as e:
        hoshino.logger.error(f'投递分群广播失败:{type(e)}')
        try:
            await session.send(f'投递分群广播失败:{type(e)}')
        except Exception as e:
            hoshino.logger.critical(f'向广播发起者进行错误回报时发生错误:{type(e)}')
        return

    new_msg = ' '.join(msg[1:])

    for sid in hoshino.get_self_ids():
        gl = await session.bot.get_group_list(self_id=sid)
        gl = [g['group_id'] for g in gl]
        if target not in gl:
            hoshino.logger.error('不在群中')
            try:
                await session.send('不在群中')
            except Exception as e:
                hoshino.logger.critical(f'向广播发起者进行错误回报时发生错误:{type(e)}')
            continue

        try:
            await session.bot.send_group_msg(self_id=sid,
                                             group_id=target,
                                             message=new_msg)
            hoshino.logger.info('分群投递广播成功')
        except Exception as e:
            hoshino.logger.error(f'分群投递广播失败:{type(e)}')
            try:
                await session.send(f'分群投递广播失败:{type(e)}')
            except Exception as e:
                hoshino.logger.critical(f'向广播发起者进行错误回报时发生错误:{type(e)}')

    await session.send(f'广播完成!')