fix
This commit is contained in:
+33
-7
@@ -23,16 +23,23 @@ type PinnedData struct {
|
|||||||
// not ideal but good enough for this
|
// not ideal but good enough for this
|
||||||
var data map[string]*PinnedData = make(map[string]*PinnedData)
|
var data map[string]*PinnedData = make(map[string]*PinnedData)
|
||||||
|
|
||||||
func InitPinned(c tempest.Client, channelIDs []tempest.Snowflake) error {
|
func InitPinned(c tempest.Client, serverIDs []tempest.Snowflake) error {
|
||||||
for _, cid := range channelIDs {
|
for _, sid := range serverIDs {
|
||||||
messages, err := getPinnedMessages(c.Rest, cid.String())
|
channels, err := getChannels(c.Rest, sid.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
data[cid.String()] = &PinnedData{
|
for _, cid := range channels {
|
||||||
Messages: messages,
|
messages, err := getPinnedMessages(c.Rest, cid.ID.String())
|
||||||
Count: len(messages),
|
if err != nil {
|
||||||
|
fmt.Println("failed to get the pinned messages for channel", cid, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
data[cid.ID.String()] = &PinnedData{
|
||||||
|
Messages: messages,
|
||||||
|
Count: len(messages),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +56,6 @@ var Pinned tempest.Command = tempest.Command{
|
|||||||
itx.SendLinearReply("no data for this channel", false)
|
itx.SendLinearReply("no data for this channel", false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if channelData.Count == 0 {
|
if channelData.Count == 0 {
|
||||||
itx.SendLinearReply("no pinned messages", false)
|
itx.SendLinearReply("no pinned messages", false)
|
||||||
return
|
return
|
||||||
@@ -74,8 +80,25 @@ var Pinned tempest.Command = tempest.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getChannels(rest tempest.Rest, serverID string) ([]Channel, error) {
|
||||||
|
route := fmt.Sprintf("/guilds/%s/channels", serverID)
|
||||||
|
|
||||||
|
bytes, err := rest.Request("GET", route, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
channels := []Channel{}
|
||||||
|
if err = json.Unmarshal(bytes, &channels); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return channels, nil
|
||||||
|
}
|
||||||
|
|
||||||
func getPinnedMessages(rest tempest.Rest, channelID string) ([]tempest.Message, error) {
|
func getPinnedMessages(rest tempest.Rest, channelID string) ([]tempest.Message, error) {
|
||||||
route := fmt.Sprintf("/channels/%s/pins", channelID)
|
route := fmt.Sprintf("/channels/%s/pins", channelID)
|
||||||
|
|
||||||
bytes, err := rest.Request("GET", route, nil)
|
bytes, err := rest.Request("GET", route, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -89,3 +112,6 @@ func getPinnedMessages(rest tempest.Rest, channelID string) ([]tempest.Message,
|
|||||||
return messages, nil
|
return messages, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Channel struct {
|
||||||
|
ID tempest.Snowflake `json:"id"`
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
tempest "github.com/Amatsagu/Tempest"
|
tempest "github.com/Amatsagu/Tempest"
|
||||||
)
|
)
|
||||||
|
|
||||||
var channelIDs []tempest.Snowflake = []tempest.Snowflake{
|
var serverIDs []tempest.Snowflake = []tempest.Snowflake{
|
||||||
992760761812258868, // test server
|
992760761812258868, // test server
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ func main() {
|
|||||||
|
|
||||||
client.RegisterCommand(commands.Pinned)
|
client.RegisterCommand(commands.Pinned)
|
||||||
|
|
||||||
client.SyncCommands(channelIDs, nil, false)
|
client.SyncCommands(serverIDs, nil, false)
|
||||||
|
|
||||||
|
|
||||||
addr := fmt.Sprintf("%s:%s", env.Addr, env.Port)
|
addr := fmt.Sprintf("%s:%s", env.Addr, env.Port)
|
||||||
@@ -55,7 +55,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func initialize(c tempest.Client) error {
|
func initialize(c tempest.Client) error {
|
||||||
if err := commands.InitPinned(c, channelIDs); err != nil {
|
if err := commands.InitPinned(c, serverIDs); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ func getEnvVariables() Env {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Env{}
|
return LocalEnv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user