Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #163 from axiangcoding/develop
Browse files Browse the repository at this point in the history
代码结构优化
  • Loading branch information
axiangcoding committed Feb 21, 2023
2 parents b73d416 + ebb4af1 commit 4ca8c7e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api-system/cmd/cardfight/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/axiangcoding/antonstar-bot/pkg/cardfight"
)

// WIP 卡牌对战程序
// TODO 卡牌对战程序
func main() {
card99A := cardfight.InitCarItem("ZTZ99A", "用户一号", 10, 9, 7, 6)
cardL2A6 := cardfight.InitCarItem("豹2A6", "用户二号", 10, 7, 8, 6)
Expand Down
24 changes: 12 additions & 12 deletions api-system/internal/service/bot_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"
"github.com/axiangcoding/antonstar-bot/internal/data/display"
table2 "github.com/axiangcoding/antonstar-bot/internal/data/table"
"github.com/axiangcoding/antonstar-bot/internal/data/table"
"github.com/axiangcoding/antonstar-bot/pkg/bot"
"github.com/axiangcoding/antonstar-bot/pkg/cqhttp"
"github.com/axiangcoding/antonstar-bot/pkg/crawler"
Expand Down Expand Up @@ -70,21 +70,21 @@ func RefreshWTUserInfo(nickname string, sendForm cqhttp.SendGroupMsgForm) (*stri
SendForm: sendForm,
Nick: nickname,
}
if err := SubmitMissionWithDetail(missionId, table2.MissionTypeUserInfo, form); err != nil {
if err := SubmitMissionWithDetail(missionId, table.MissionTypeUserInfo, form); err != nil {
return nil, err
}
if err := ants.Submit(func() {
if err := crawler.GetProfileFromWTOfficial(nickname,
func(status int, user *table2.GameUser) {
func(status int, user *table.GameUser) {
switch status {
case crawler.StatusQueryFailed:
MustFinishMissionWithResult(missionId, table2.MissionStatusFailed, CrawlerResult{
MustFinishMissionWithResult(missionId, table.MissionStatusFailed, CrawlerResult{
Found: false,
Nick: nickname,
})
case crawler.StatusNotFound:
MustPutRefreshFlag(nickname)
MustFinishMissionWithResult(missionId, table2.MissionStatusSuccess, CrawlerResult{
MustFinishMissionWithResult(missionId, table.MissionStatusSuccess, CrawlerResult{
Found: false,
Nick: nickname,
})
Expand Down Expand Up @@ -115,7 +115,7 @@ func RefreshWTUserInfo(nickname string, sendForm cqhttp.SendGroupMsgForm) (*stri
logging.L().Warn("failed on update thunder skill profile. ", logging.Error(err))
}
MustPutRefreshFlag(nickname)
MustFinishMissionWithResult(missionId, table2.MissionStatusSuccess, CrawlerResult{
MustFinishMissionWithResult(missionId, table.MissionStatusSuccess, CrawlerResult{
Found: true,
Nick: nickname,
Data: *user},
Expand Down Expand Up @@ -300,7 +300,7 @@ func DoActionUnbinding(retMsgForm *cqhttp.SendGroupMsgForm) {
retMsgForm.Message = bot.SelectStaticMessage(retMsgForm.MessageTemplate).CommonResp.UnbindingSuccess
}

func DoActionManager(retMsgForm *cqhttp.SendGroupMsgForm, uc *table2.QQUserConfig, value string) {
func DoActionManager(retMsgForm *cqhttp.SendGroupMsgForm, uc *table.QQUserConfig, value string) {
// 只有超级管理员可以进行全局设置
if uc.SuperAdmin == nil || !*uc.SuperAdmin {
retMsgForm.Message = bot.SelectStaticMessage(retMsgForm.MessageTemplate).CommonResp.ConfNotPermit
Expand All @@ -315,16 +315,16 @@ func DoActionManager(retMsgForm *cqhttp.SendGroupMsgForm, uc *table2.QQUserConfi
keyUnsetAdmin := "解除管理员"
switch value {
case keyOpenResponse:
MustUpsertGlobalConfig(table2.ConfigStopAllResponse, "false")
MustUpsertGlobalConfig(table.ConfigStopAllResponse, "false")
retMsgForm.Message = bot.SelectStaticMessage(retMsgForm.MessageTemplate).CommonResp.ConfStartGlobalResponse
case keyCloseResponse:
MustUpsertGlobalConfig(table2.ConfigStopAllResponse, "true")
MustUpsertGlobalConfig(table.ConfigStopAllResponse, "true")
retMsgForm.Message = bot.SelectStaticMessage(retMsgForm.MessageTemplate).CommonResp.ConfStopGlobalResponse
case keyOpenQuery:
MustUpsertGlobalConfig(table2.ConfigStopQuery, "false")
MustUpsertGlobalConfig(table.ConfigStopQuery, "false")
retMsgForm.Message = bot.SelectStaticMessage(retMsgForm.MessageTemplate).CommonResp.ConfStartGlobalQuery
case keyCloseQuery:
MustUpsertGlobalConfig(table2.ConfigStopQuery, "true")
MustUpsertGlobalConfig(table.ConfigStopQuery, "true")
retMsgForm.Message = bot.SelectStaticMessage(retMsgForm.MessageTemplate).CommonResp.ConfStopGlobalQuery
case keySetAdmin:
// TODO
Expand All @@ -342,6 +342,6 @@ func DoActionManager(retMsgForm *cqhttp.SendGroupMsgForm, uc *table2.QQUserConfi
}
}

func DoActionGroupManager(retMsgForm *cqhttp.SendGroupMsgForm, uc *table2.QQUserConfig, value string) {
func DoActionGroupManager(retMsgForm *cqhttp.SendGroupMsgForm, uc *table.QQUserConfig, value string) {
// TODO 群管理
}
6 changes: 3 additions & 3 deletions api-system/internal/service/cqhttp_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"
"github.com/axiangcoding/antonstar-bot/internal/cache"
table2 "github.com/axiangcoding/antonstar-bot/internal/data/table"
"github.com/axiangcoding/antonstar-bot/internal/data/table"
"github.com/axiangcoding/antonstar-bot/pkg/bot"
"github.com/axiangcoding/antonstar-bot/pkg/cqhttp"
"github.com/axiangcoding/antonstar-bot/pkg/logging"
Expand Down Expand Up @@ -111,7 +111,7 @@ func handleCqHttpMessageEventGroup(event *cqhttp.CommonEvent) {
gc, err := FindGroupConfig(groupId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
defaultGC := table2.DefaultGroupConfig(groupId)
defaultGC := table.DefaultGroupConfig(groupId)
gc = &defaultGC
MustSaveGroupConfig(gc)
} else {
Expand All @@ -121,7 +121,7 @@ func handleCqHttpMessageEventGroup(event *cqhttp.CommonEvent) {
uc, err := FindUserConfig(userId)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
defaultUC := table2.DefaultUserConfig(userId)
defaultUC := table.DefaultUserConfig(userId)
uc = &defaultUC
MustSaveUserConfig(uc)
} else {
Expand Down
2 changes: 2 additions & 0 deletions api-system/pkg/cqhttp/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

// MustSendGroupMsg
// TODO 将配置项外移,不在最终方法中调用
// https://docs.go-cqhttp.org/api/#%E5%A4%84%E7%90%86%E5%8A%A0%E7%BE%A4%E8%AF%B7%E6%B1%82-%E9%82%80%E8%AF%B7
func MustSendGroupMsg(form SendGroupMsgForm) {
url := setting.C().App.Service.CqHttp.Url + "/send_group_msg"
Expand All @@ -33,6 +34,7 @@ func MustSendGroupMsg(form SendGroupMsgForm) {
}

// MustAcceptInviteToGroup
// TODO 将配置项外移,不在最终方法中调用
// https://docs.go-cqhttp.org/api/#%E5%A4%84%E7%90%86%E5%8A%A0%E7%BE%A4%E8%AF%B7%E6%B1%82-%E9%82%80%E8%AF%B7
func MustAcceptInviteToGroup(flag string, subType string, approve bool, reason string) {
url := setting.C().App.Service.CqHttp.Url + "/set_group_add_request"
Expand Down

0 comments on commit 4ca8c7e

Please sign in to comment.