コード例 #1
0
def makeMessageTitle(ctx: Event):
    items = ctx.items()

    _time = time.localtime(ctx.get('time'))
    _time = time.strftime("%Y-%m-%d %H:%M:%S", _time)

    # 获取发送者信息
    sender = ctx.get('sender')
    user_id = sender['user_id']
    nickname = sender['nickname']
    # 获取信息
    result_message = f"{_time}\nQQ名称:{nickname}\nQQ号:{user_id}\n"

    return result_message
コード例 #2
0
 async def create(bot: NoneBot, event: CQEvent) -> 'SenderRoles':
     """constructor to create a SenderRoles object from an event"""
     # same approach as vanilla permission checker
     sender_info = await _get_member_info(bot, event.self_id,
         event.group_id, event.user_id) \
         if event.get('message_type') == 'group' else None
     return SenderRoles(bot, event, sender_info)
コード例 #3
0
ファイル: permission.py プロジェクト: nonebot/nonebot
    async def create(bot: NoneBot, event: CQEvent) -> 'SenderRoles':
        """
        构造 `SenderRoles`。

        参数:
            bot: 接收事件的 NoneBot 对象
            event: 上报事件

        用法:
            ```python
            sender = await SenderRoles.create(session.bot, session.event)
            if sender.is_groupchat:
                if sender.is_owner:
                    await process_owner(session)
                elif sender.is_admin:
                    await process_admin(session)
                else:
                    await process_member(session)
            ```

            根据发送者的身份决定相应命令处理方式。
        """
        # same approach as vanilla permission checker
        sender_info = await _get_member_info(bot, event.self_id,
            event.group_id, event.user_id) \
            if event.get('message_type') == 'group' else None
        return SenderRoles(bot, event, sender_info)
コード例 #4
0
async def show_group_reply(bot, event: Event):
    gid = event.get('group_id')
    try:
        page = int(event.raw_message.strip('查看问答'))
    except:
        page = 1
    records = {(m, n) : v for (m, n), v in RECORDS.items() if gid == n}
    reply, pages = show(records,page)
    await bot.send(event,reply.strip()+f'\n\n当前第{page}页,共{pages}页',at_sender=False)
コード例 #5
0
async def show_group_reply(bot, event: Event):
    gid = event.get('group_id')
    uid = event.user_id
    try:
        page = int(event.raw_message.strip('查看我问'))
    except:
        page = 1
    records = {(m, n): v
               for (m, n), v in RECORDS.items()
               if gid == n and uid == RECORDS[(m, n)]['rec_maker']}
    reply, pages = show(records, page)
    await bot.send(event,
                   gfw.filter(reply.strip()) + f'\n\n当前第{page}页,共{pages}页',
                   at_sender=False)
コード例 #6
0
async def add_reply_for_self(bot, event: Event):
    uid = event['user_id']
    gid = event.get('group_id')
    user_priv = get_user_priv(event)
    user_quata = get_user_quota(user_priv)

    # mirai要下载图片
    await R.save_image(event)

    qu = event.raw_message.split('你答')[0].strip('我问').strip()
    ans = event.raw_message.split('你答')[1].strip()
    rec = Record(qu, ans, uid, gid, 0)

    if rec.count_user_records(uid) >= user_quata:
        await bot.send(event, '您的额度不足,请删除记录后再来', at_sender=True)
        return

    if rec.insert_database():
        await bot.send(event, '问答添加成功', at_sender=True)
        if rec.get_records:
            global RECORDS
            RECORDS = rec.get_records()
    else:
        await bot.send(event, '问答添加失败,问答不规范或者冲突', at_sender=True)