Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
# Conflicts:
#	api/api_bind.go
#	dice/builtin_commands.go
#	dice/config.go
#	dice/dice.go
#	dice/dice_censor.go
#	dice/dice_manager.go
#	dice/ext_coc7.go
#	dice/im_session.go
#	dice/platform_adapter_gocq.go
#	dice/platform_adapter_walleq.go
#	dice/rollvm.go
#	dice/utils.go
#	go.mod
#	go.sum
#	main.go
#	tray_windows.go
  • Loading branch information
JustAnotherID committed Oct 19, 2024
2 parents 0aee149 + a382281 commit d85f0f2
Show file tree
Hide file tree
Showing 65 changed files with 5,253 additions and 3,282 deletions.
5 changes: 5 additions & 0 deletions api/api_bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func forceStop(c echo.Context) error {
for _, i := range diceManager.Dice {
if i.IsAlreadyLoadConfig {
i.Config.BanList.SaveChanged(i)
i.AttrsManager.CheckForSave()
i.Save(true)
for _, j := range i.ExtList {
if j.Storage != nil {
Expand Down Expand Up @@ -603,6 +604,7 @@ func Bind(e *echo.Echo, _myDice *dice.DiceManager) {

e.GET(prefix+"/configs/customText", customText)
e.POST(prefix+"/configs/customText/save", customTextSave)
e.POST(prefix+"/configs/customText/preview-refresh", customTextPreviewRefresh)

e.GET(prefix+"/configs/custom_reply", customReplyGet)
e.POST(prefix+"/configs/custom_reply/save", customReplySave)
Expand All @@ -624,6 +626,9 @@ func Bind(e *echo.Echo, _myDice *dice.DiceManager) {
e.GET(prefix+"/dice/cmdList", DiceAllCommand)
e.POST(prefix+"/dice/upload_to_upgrade", DiceNewVersionUpload)

e.POST(prefix+"/dice/config/vm-version-for-reply-set", vmVersionForReplySet)
e.POST(prefix+"/dice/config/vm-version-for-deck-set", vmVersionForDeckSet)

e.POST(prefix+"/signin", doSignIn)
e.GET(prefix+"/signin/salt", doSignInGetSalt)
e.GET(prefix+"/checkSecurity", checkSecurity)
Expand Down
29 changes: 27 additions & 2 deletions api/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ func customText(c echo.Context) error {
}

return c.JSON(http.StatusOK, map[string]interface{}{
"texts": myDice.TextMapRaw,
"helpInfo": myDice.TextMapHelpInfo,
"texts": myDice.TextMapRaw,
"helpInfo": myDice.TextMapHelpInfo,
"previewInfo": &myDice.TextMapCompatible,
})
}

Expand All @@ -41,6 +42,30 @@ func customTextSave(c echo.Context) error {
dice.SetupTextHelpInfo(myDice, myDice.TextMapHelpInfo, myDice.TextMapRaw, "configs/text-template.yaml")
myDice.GenerateTextMap()
myDice.SaveText()

for k, v2 := range myDice.TextMapRaw[v.Category] {
dice.TextMapCompatibleCheck(myDice, v.Category, k, v2)
}

return c.String(http.StatusOK, "")
}
return c.String(430, "")
}

func customTextPreviewRefresh(c echo.Context) error {
if !doAuth(c) {
return c.JSON(http.StatusForbidden, nil)
}

// 按理说不该全部更新吧,但是 customTextSave 里没做区分,先保持一致,后续再看看
v := struct {
Category string `form:"category" json:"category"`
}{}
err := c.Bind(&v)
if err == nil {
for k, v2 := range myDice.TextMapRaw[v.Category] {
dice.TextMapCompatibleCheck(myDice, v.Category, k, v2)
}
return c.String(http.StatusOK, "")
}
return c.String(430, "")
Expand Down
35 changes: 35 additions & 0 deletions api/dice_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,38 @@ func DiceMailTest(c echo.Context) error {
}
return Success(&c, Response{})
}

func vmVersionForExtSetBase(c echo.Context, callback func(val string)) error {
if !doAuth(c) {
return c.JSON(http.StatusForbidden, nil)
}
if dm.JustForTest {
return Error(&c, "展示模式不支持该操作", Response{"testMode": true})
}

var data struct {
Value string `json:"value"`
}

err := c.Bind(&data)
if err != nil {
return Error(&c, err.Error(), nil)
}

callback(data.Value)
myDice.MarkModified()
myDice.Parent.Save()
return Success(&c, Response{})
}

func vmVersionForReplySet(c echo.Context) error {
return vmVersionForExtSetBase(c, func(val string) {
myDice.Config.VMVersionForReply = val
})
}

func vmVersionForDeckSet(c echo.Context) error {
return vmVersionForExtSetBase(c, func(val string) {
myDice.Config.VMVersionForDeck = val
})
}
11 changes: 7 additions & 4 deletions api/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (

func groupList(c echo.Context) error {
var items []*dice.GroupInfo
for groupID, item := range myDice.ImSession.ServiceAtNew {
// Pinenutn: Range模板 ServiceAtNew重构代码
myDice.ImSession.ServiceAtNew.Range(func(groupID string, item *dice.GroupInfo) bool {
// Pinenutn: ServiceAtNew重构
item.GroupID = groupID
if !strings.HasPrefix(item.GroupID, "PG-") {
if item != nil {
Expand All @@ -31,7 +33,8 @@ func groupList(c echo.Context) error {
}
}
}
}
return true
})

return c.JSON(http.StatusOK, map[string]interface{}{
"items": items,
Expand All @@ -56,7 +59,7 @@ func groupSetOne(c echo.Context) error {
err := c.Bind(&v)

if err == nil {
_, exists := myDice.ImSession.ServiceAtNew[v.GroupID]
_, exists := myDice.ImSession.ServiceAtNew.Load(v.GroupID)
if exists {
for _, ep := range myDice.ImSession.EndPoints {
// if ep.UserId == v.DiceId {
Expand Down Expand Up @@ -95,7 +98,7 @@ func groupQuit(c echo.Context) error {
}

// 不太好弄,主要会出现多个帐号在群的情况
group, exists := myDice.ImSession.ServiceAtNew[v.GroupID]
group, exists := myDice.ImSession.ServiceAtNew.Load(v.GroupID)
if !exists {
return c.String(430, "")
}
Expand Down
Loading

0 comments on commit d85f0f2

Please sign in to comment.