From 2f84401d75ab90edc3f8620bec0fe4a09071a9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=83=E6=A9=98=20=E9=9B=AB=E9=9C=9E?= Date: Tue, 22 Feb 2022 00:54:53 +0800 Subject: [PATCH 1/2] feat: set qq profile --- coolq/api.go | 26 ++++++++++++++++++++++++++ modules/api/api.go | 7 +++++++ 2 files changed, 33 insertions(+) diff --git a/coolq/api.go b/coolq/api.go index 35a5d1d81..d4b3c37c0 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -1969,6 +1969,32 @@ func (bot *CQBot) CQMarkMessageAsRead(msgID int32) global.MSG { return OK(nil) } +// CQSetQQProfile 设置 QQ 资料 +// +// @route(set_qq_profile) +func (bot *CQBot) CQSetQQProfile(nickname, company, email, college, personalNote string) global.MSG { + u := client.NewProfileDetailUpdate() + + if nickname != "" { + u.Nick(nickname) + } + if company != "" { + u.Company(company) + } + if email != "" { + u.Email(email) + } + if college != "" { + u.College(college) + } + if personalNote != "" { + u.PersonalNote(personalNote) + } + + bot.Client.UpdateProfile(u) + return OK(nil) +} + // CQReloadEventFilter 重载事件过滤器 // // @route(reload_event_filter) diff --git a/modules/api/api.go b/modules/api/api.go index 5ece47689..db6fe7164 100644 --- a/modules/api/api.go +++ b/modules/api/api.go @@ -304,6 +304,13 @@ func (c *Caller) call(action string, p Getter) global.MSG { p2 := p.Get("role_id").Uint() p3 := p.Get("users") return c.bot.CQSetGuildMemberRole(p0, p1, p2, p3) + case "set_qq_profile": + p0 := p.Get("nickname").String() + p1 := p.Get("company").String() + p2 := p.Get("email").String() + p3 := p.Get("college").String() + p4 := p.Get("personal_note").String() + return c.bot.CQSetQQProfile(p0, p1, p2, p3, p4) case "update_guild_role": p0 := p.Get("guild_id").Uint() p1 := p.Get("role_id").Uint() From 4087d5861c1b220653c3169ffbbbeb9972969ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=83=E6=A9=98=20=E9=9B=AB=E9=9C=9E?= Date: Tue, 22 Feb 2022 13:37:22 +0800 Subject: [PATCH 2/2] refactor: support empty field --- coolq/api.go | 25 ++++++++++--------------- modules/api/api.go | 10 +++++----- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/coolq/api.go b/coolq/api.go index e032f56be..621a666fa 100644 --- a/coolq/api.go +++ b/coolq/api.go @@ -1984,25 +1984,20 @@ func (bot *CQBot) CQMarkMessageAsRead(msgID int32) global.MSG { // CQSetQQProfile 设置 QQ 资料 // // @route(set_qq_profile) -func (bot *CQBot) CQSetQQProfile(nickname, company, email, college, personalNote string) global.MSG { +func (bot *CQBot) CQSetQQProfile(nickname, company, email, college, personalNote gjson.Result) global.MSG { u := client.NewProfileDetailUpdate() - if nickname != "" { - u.Nick(nickname) - } - if company != "" { - u.Company(company) - } - if email != "" { - u.Email(email) - } - if college != "" { - u.College(college) - } - if personalNote != "" { - u.PersonalNote(personalNote) + fi := func(f gjson.Result, do func(value string) client.ProfileDetailUpdate) { + if f.Exists() { + do(f.String()) + } } + fi(nickname, u.Nick) + fi(company, u.Company) + fi(email, u.Email) + fi(college, u.College) + fi(personalNote, u.PersonalNote) bot.Client.UpdateProfile(u) return OK(nil) } diff --git a/modules/api/api.go b/modules/api/api.go index db6fe7164..e936269ac 100644 --- a/modules/api/api.go +++ b/modules/api/api.go @@ -305,11 +305,11 @@ func (c *Caller) call(action string, p Getter) global.MSG { p3 := p.Get("users") return c.bot.CQSetGuildMemberRole(p0, p1, p2, p3) case "set_qq_profile": - p0 := p.Get("nickname").String() - p1 := p.Get("company").String() - p2 := p.Get("email").String() - p3 := p.Get("college").String() - p4 := p.Get("personal_note").String() + p0 := p.Get("nickname") + p1 := p.Get("company") + p2 := p.Get("email") + p3 := p.Get("college") + p4 := p.Get("personal_note") return c.bot.CQSetQQProfile(p0, p1, p2, p3, p4) case "update_guild_role": p0 := p.Get("guild_id").Uint()