Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoshinonyaruko committed Nov 2, 2023
1 parent c16e1af commit ec7863d
Show file tree
Hide file tree
Showing 113 changed files with 658 additions and 321 deletions.
5 changes: 3 additions & 2 deletions Processor/ProcessC2CMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/hoshinonyaruko/gensokyo/echo"
"github.com/hoshinonyaruko/gensokyo/handlers"
"github.com/hoshinonyaruko/gensokyo/idmap"
"github.com/hoshinonyaruko/gensokyo/mylog"
"github.com/tencent-connect/botgo/dto"
"github.com/tencent-connect/botgo/websocket/client"
)
Expand Down Expand Up @@ -103,13 +104,13 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
//映射str的userid到int
userid64, err := idmap.StoreIDv2(data.Author.ID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
//映射str的messageID到int
messageID64, err := idmap.StoreIDv2(data.ID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
messageID := int(messageID64)
Expand Down
11 changes: 6 additions & 5 deletions Processor/ProcessChannelDirectMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hoshinonyaruko/gensokyo/echo"
"github.com/hoshinonyaruko/gensokyo/handlers"
"github.com/hoshinonyaruko/gensokyo/idmap"
"github.com/hoshinonyaruko/gensokyo/mylog"

"github.com/tencent-connect/botgo/dto"
"github.com/tencent-connect/botgo/websocket/client"
Expand Down Expand Up @@ -47,7 +48,7 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
//将channelid写入数据库,可取出guild_id
ChannelID64, err := idmap.StoreIDv2(data.ChannelID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
//转成int再互转
Expand Down Expand Up @@ -123,7 +124,7 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
//映射str的userid到int
userid64, err := idmap.StoreIDv2(data.Author.ID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
//OnebotChannelMessage
Expand Down Expand Up @@ -189,7 +190,7 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
//将channelid写入bolt,可取出guild_id
ChannelID64, err := idmap.StoreIDv2(data.ChannelID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
//转成int再互转 适用于群场景私聊
Expand All @@ -203,14 +204,14 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
//映射str的userid到int
userid64, err := idmap.StoreIDv2(data.Author.ID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
//userid := int(userid64)
//映射str的messageID到int
messageID64, err := idmap.StoreIDv2(data.ID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
messageID := int(messageID64)
Expand Down
6 changes: 3 additions & 3 deletions Processor/ProcessGroupMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package Processor

import (
"fmt"
"log"
"strconv"
"time"

"github.com/hoshinonyaruko/gensokyo/config"
"github.com/hoshinonyaruko/gensokyo/echo"
"github.com/hoshinonyaruko/gensokyo/handlers"
"github.com/hoshinonyaruko/gensokyo/idmap"
"github.com/hoshinonyaruko/gensokyo/mylog"

"github.com/tencent-connect/botgo/dto"
"github.com/tencent-connect/botgo/websocket/client"
Expand Down Expand Up @@ -39,14 +39,14 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
// 映射str的userid到int
userid64, err := idmap.StoreIDv2(data.Author.ID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}

//映射str的messageID到int
messageID64, err := idmap.StoreIDv2(data.ID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
messageID := int(messageID64)
Expand Down
10 changes: 5 additions & 5 deletions Processor/ProcessGuildATMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package Processor

import (
"fmt"
"log"
"strconv"
"time"

"github.com/hoshinonyaruko/gensokyo/config"
"github.com/hoshinonyaruko/gensokyo/echo"
"github.com/hoshinonyaruko/gensokyo/handlers"
"github.com/hoshinonyaruko/gensokyo/idmap"
"github.com/hoshinonyaruko/gensokyo/mylog"

"github.com/tencent-connect/botgo/dto"
"github.com/tencent-connect/botgo/websocket/client"
Expand All @@ -35,7 +35,7 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
//映射str的userid到int
userid64, err := idmap.StoreIDv2(data.Author.ID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
// 如果在Array模式下, 则处理Message为Segment格式
Expand Down Expand Up @@ -109,7 +109,7 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
//将channelid写入ini,可取出guild_id
ChannelID64, err := idmap.StoreIDv2(data.ChannelID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
//转成int再互转
Expand All @@ -123,14 +123,14 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
//映射str的userid到int
userid64, err := idmap.StoreIDv2(data.Author.ID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
//userid := int(userid64)
//映射str的messageID到int
messageID64, err := idmap.StoreIDv2(data.ID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
messageID := int(messageID64)
Expand Down
10 changes: 5 additions & 5 deletions Processor/ProcessGuildNormalMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package Processor

import (
"fmt"
"log"
"strconv"
"time"

"github.com/hoshinonyaruko/gensokyo/config"
"github.com/hoshinonyaruko/gensokyo/echo"
"github.com/hoshinonyaruko/gensokyo/handlers"
"github.com/hoshinonyaruko/gensokyo/idmap"
"github.com/hoshinonyaruko/gensokyo/mylog"
"github.com/tencent-connect/botgo/dto"
"github.com/tencent-connect/botgo/websocket/client"
)
Expand All @@ -34,7 +34,7 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
//映射str的userid到int
userid64, err := idmap.StoreIDv2(data.Author.ID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
// 如果在Array模式下, 则处理Message为Segment格式
Expand Down Expand Up @@ -108,7 +108,7 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
//将channelid写入ini,可取出guild_id
ChannelID64, err := idmap.StoreIDv2(data.ChannelID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
//转成int再互转
Expand All @@ -122,14 +122,14 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
//映射str的userid到int
userid64, err := idmap.StoreIDv2(data.Author.ID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
//userid := int(userid64)
//映射str的messageID到int
messageID64, err := idmap.StoreIDv2(data.ID)
if err != nil {
log.Printf("Error storing ID: %v", err)
mylog.Printf("Error storing ID: %v", err)
return nil
}
messageID := int(messageID64)
Expand Down
7 changes: 4 additions & 3 deletions Processor/Processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/hoshinonyaruko/gensokyo/callapi"
"github.com/hoshinonyaruko/gensokyo/config"
"github.com/hoshinonyaruko/gensokyo/mylog"
"github.com/hoshinonyaruko/gensokyo/wsclient"
"github.com/tencent-connect/botgo/dto"
"github.com/tencent-connect/botgo/openapi"
Expand Down Expand Up @@ -140,7 +141,7 @@ func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error {
// context.Background(), dm, toCreate,
// )
// if err != nil {
// log.Println("Error sending default reply:", err)
// mylog.Println("Error sending default reply:", err)
// return nil
// }

Expand All @@ -157,15 +158,15 @@ func PrintStructWithFieldNames(v interface{}) {

// 确保我们传入的是一个结构体
if typ.Kind() != reflect.Struct {
fmt.Println("Input is not a struct")
mylog.Println("Input is not a struct")
return
}

// 迭代所有的字段并打印字段名和值
for i := 0; i < typ.NumField(); i++ {
field := typ.Field(i)
value := val.Field(i)
fmt.Printf("%s: %v\n", field.Name, value.Interface())
mylog.Printf("%s: %v\n", field.Name, value.Interface())
}
}

Expand Down
2 changes: 1 addition & 1 deletion botgo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func main() {

// 监听哪类事件就需要实现哪类的 handler,定义:websocket/event_handler.go
var atMessage websocket.ATMessageEventHandler = func(event *dto.WSPayload, data *dto.WSATMessageData) error {
fmt.Println(event, data)
log.Println(event, data)
return nil
}
intent := websocket.RegisterHandlers(atMessage)
Expand Down
4 changes: 2 additions & 2 deletions botgo/event/register_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package event

import (
"fmt"
"log"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -22,7 +22,7 @@ func TestRegisterHandlers(t *testing.T) {
t.Run(
"test intent", func(t *testing.T) {
i := RegisterHandlers(guild, message, audio)
fmt.Println(i)
log.Println(i)
assert.Equal(t, dto.IntentGuildMessages, i&dto.IntentGuildMessages)
assert.Equal(t, dto.IntentGuilds, i&dto.IntentGuilds)
assert.Equal(t, dto.IntentAudio, i&dto.IntentAudio)
Expand Down
4 changes: 2 additions & 2 deletions botgo/examples/apitest/message_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package apitest

import (
"fmt"
"log"
"testing"

"github.com/tencent-connect/botgo/dto/keyboard"
Expand Down Expand Up @@ -85,7 +85,7 @@ func TestMessage(t *testing.T) {
}

message, err := api.Message(ctx, testChannelID, index[0])
fmt.Println(message)
log.Println(message)
},
)
}
Expand Down
4 changes: 2 additions & 2 deletions botgo/examples/receive-and-send/forum.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"fmt"
"log"

"github.com/tencent-connect/botgo/dto"
"github.com/tencent-connect/botgo/event"
Expand All @@ -10,7 +10,7 @@ import (
// ThreadEventHandler 论坛主贴事件
func ThreadEventHandler() event.ThreadEventHandler {
return func(event *dto.WSPayload, data *dto.WSThreadData) error {
fmt.Println(event, data)
log.Println(event, data)
return nil
}
}
12 changes: 6 additions & 6 deletions botgo/examples/receive-and-send/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,47 +108,47 @@ func ATMessageEventHandler() event.ATMessageEventHandler {
// GuildEventHandler 处理频道事件
func GuildEventHandler() event.GuildEventHandler {
return func(event *dto.WSPayload, data *dto.WSGuildData) error {
fmt.Println(data)
log.Println(data)
return nil
}
}

// ChannelEventHandler 处理子频道事件
func ChannelEventHandler() event.ChannelEventHandler {
return func(event *dto.WSPayload, data *dto.WSChannelData) error {
fmt.Println(data)
log.Println(data)
return nil
}
}

// MemberEventHandler 处理成员变更事件
func MemberEventHandler() event.GuildMemberEventHandler {
return func(event *dto.WSPayload, data *dto.WSGuildMemberData) error {
fmt.Println(data)
log.Println(data)
return nil
}
}

// DirectMessageHandler 处理私信事件
func DirectMessageHandler() event.DirectMessageEventHandler {
return func(event *dto.WSPayload, data *dto.WSDirectMessageData) error {
fmt.Println(data)
log.Println(data)
return nil
}
}

// CreateMessageHandler 处理消息事件
func CreateMessageHandler() event.MessageEventHandler {
return func(event *dto.WSPayload, data *dto.WSMessageData) error {
fmt.Println(data)
log.Println(data)
return nil
}
}

// InteractionHandler 处理内联交互事件
func InteractionHandler() event.InteractionEventHandler {
return func(event *dto.WSPayload, data *dto.WSInteractionData) error {
fmt.Println(data)
log.Println(data)
return processor.ProcessInlineSearch(data)
}
}
Expand Down
Loading

0 comments on commit ec7863d

Please sign in to comment.