Skip to content

Commit

Permalink
Beta41 (#142)
Browse files Browse the repository at this point in the history
* beta41

* api add
  • Loading branch information
Hoshinonyaruko authored Nov 19, 2023
1 parent 0b2eb31 commit c309a23
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
40 changes: 36 additions & 4 deletions handlers/get_guild_channel_list.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package handlers

import (
"context"

"github.com/hoshinonyaruko/gensokyo/callapi"
"github.com/hoshinonyaruko/gensokyo/mylog"
"github.com/tencent-connect/botgo/openapi"
Expand All @@ -19,21 +21,51 @@ func init() {
}

func getGuildChannelList(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.OpenAPI, message callapi.ActionMessage) {

var response GuildChannelListResponse

response.Data = make([]interface{}, 0) // No data at the moment, but can be populated in the future
// 解析请求参数
guildID := message.Params.GuildID

// 根据请求参数调用API
channels, err := api.Channels(context.TODO(), guildID)
if err != nil {
// 如果发生错误,记录日志并返回null
mylog.Printf("Error fetching channels: %v", err)
client.SendMessage(map[string]interface{}{"data": nil})
return
}

// 构建响应数据
for _, channel := range channels {
channelInfo := map[string]interface{}{
"owner_guild_id": guildID,
"channel_id": channel.ID,
"channel_type": channel.Type,
"channel_name": channel.Name,
"create_time": 0, // Default value as actual value is not available
"creator_tiny_id": channel.OwnerID,
"talk_permission": channel.Permissions,
"visible_type": channel.Position,
"current_slow_mode": 0, // Default value as actual value is not available
}

// Append the channel information to the response data
response.Data = append(response.Data, channelInfo)
}

// Set other fields of the response
response.Message = ""
response.RetCode = 0
response.Status = "ok"
response.Echo = message.Echo

// Convert the members slice to a map
// Convert the response to a map for sending
outputMap := structToMap(response)

mylog.Printf("get_guild_channel_list: %s", outputMap)

err := client.SendMessage(outputMap) //发回去
// Send the response
err = client.SendMessage(outputMap)
if err != nil {
mylog.Printf("Error sending message via client: %v", err)
}
Expand Down
31 changes: 22 additions & 9 deletions handlers/get_guild_list.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package handlers

import (
"context"

"github.com/hoshinonyaruko/gensokyo/callapi"
"github.com/hoshinonyaruko/gensokyo/mylog"
"github.com/tencent-connect/botgo/dto"
"github.com/tencent-connect/botgo/openapi"
)

Expand All @@ -25,32 +28,42 @@ func init() {
}

func getGuildList(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.OpenAPI, message callapi.ActionMessage) {

var response GuildListResponse

// Assuming 'a' is some value you want to loop till.
a := 1 // Replace with appropriate value
// 创建一个 GuildPager 实例,设置 limit 为 10
pager := dto.GuildPager{Limit: "50", After: "0"} // 默认从0开始,取50个

// 调用 API 获取群组列表
guilds, err := api.MeGuilds(context.Background(), &pager)
if err != nil {
mylog.Printf("Error fetching guilds: %v", err)
return
}

for i := 1; i <= a; i++ {
// 将获取的群组数据添加到 response 中
for _, guild := range guilds {
guildData := GuildData{
GuildID: "0",
GuildName: "868858989",
GuildDisplayID: "868858989",
GuildID: guild.ID,
GuildName: guild.Name,
GuildDisplayID: guild.ID, // 或其他合适的字段
// ... 其他需要的字段
}
response.Data = append(response.Data, guildData)
}

// 设置 response 的其他属性
response.Message = ""
response.RetCode = 0
response.Status = "ok"
response.Echo = message.Echo

// Convert the members slice to a map
// Convert the response to a map (if needed)
outputMap := structToMap(response)

mylog.Printf("getGuildList(频道): %+v\n", outputMap)

err := client.SendMessage(outputMap)
// 发送消息
err = client.SendMessage(outputMap)
if err != nil {
mylog.Printf("Error sending message via client: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion silk/silk.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func encode(record []byte, tempName string) (silkWav []byte) {
}

// 使用临时文件执行silk_codec
cmd = exec.Command(tmpFile.Name(), "pts", "-i", pcmPath, "-o", silkPath, "-s", "24000")
cmd = exec.Command(tmpFile.Name(), "pts", "-i", pcmPath, "-o", silkPath, "-s", strconv.Itoa(sampleRate))
if err := cmd.Run(); err != nil {
mylog.Errorf("silk encode error: %v", err)
return nil
Expand Down

0 comments on commit c309a23

Please sign in to comment.