Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

提供一个获取群名片/昵称的函数 #13

Open
ExerciseBook opened this issue Feb 22, 2020 · 6 comments
Open

提供一个获取群名片/昵称的函数 #13

ExerciseBook opened this issue Feb 22, 2020 · 6 comments

Comments

@ExerciseBook
Copy link

1. 取群成员信息,如果失败跳到第四步
2. 如果群名片不为空,返回群名片
3. 返回昵称
4. 取陌生人信息,如果失败跳到第六步
5. 返回昵称
6. 返回QQ号形成的字符串
@ghost
Copy link

ghost commented Feb 22, 2020

auto get_private_display_nickname(const cq::MessageEvent &msg) -> string {
    try {
        auto stranger_info = cq::get_stranger_info(msg.user_id);
        return stranger_info.nickname;
    } catch (cq::ApiError &e) {}
    return std::to_string(msg.user_id);
}

auto get_display_nickname(const cq::GroupMessageEvent &msg) -> string {
    try {
        auto member_info = cq::get_group_member_info(msg.group_id, msg.user_id);
        if (!member_info.card.empty()) {
            return member_info.card;
        } else {
            return member_info.nickname;
        }
    } catch (cq::ApiError &e) {}
    return get_private_display_nickname(msg);
}

auto get_display_nickname(const cq::MessageEvent &msg) -> string {
    return get_private_display_nickname(msg);
}

我觉得我可能写错了

@ExerciseBook
Copy link
Author

@t532 光速实现,爱了。

@Mesimpler
Copy link

这个API有问题,当修改群名片后它依旧显示未修改前的名片。

@ExerciseBook
Copy link
Author

@QiJieH
image
由于手机版QQ不能实时刷新群名片信息,可手动指定nocache = true(危险慎用)或等待酷Q刷新缓存。

@Mesimpler
Copy link

@QiJieH
image
由于手机版QQ不能实时刷新群名片信息,可手动指定nocache = true(危险慎用)或等待酷Q刷新缓存。

可以实时获取名片了,为什么这个操作会有危险?

@ExerciseBook
Copy link
Author

ExerciseBook commented Mar 6, 2020

@QiJieH

不使用缓存的情况下请求是直接发给QQ的服务器的,在速度上肯定会差一点,用得多了还会引起风控。

如非必要尽量保持 cache 就好。

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants