add log
This commit is contained in:
@@ -1,29 +0,0 @@
|
|||||||
package commands
|
|
||||||
|
|
||||||
import tempest "github.com/Amatsagu/Tempest"
|
|
||||||
|
|
||||||
var Hello tempest.Command = tempest.Command{
|
|
||||||
Name: "hello",
|
|
||||||
Description: "Some test command",
|
|
||||||
Options: []tempest.Option{
|
|
||||||
{
|
|
||||||
Name: "user",
|
|
||||||
Description: "user to greet",
|
|
||||||
Type: tempest.OPTION_USER,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
SlashCommandHandler: func(itx tempest.CommandInteraction) {
|
|
||||||
raw, available := itx.GetOptionValue("user")
|
|
||||||
|
|
||||||
if available {
|
|
||||||
user, err := itx.Client.FetchUser(tempest.StringToSnowflake(raw.(string)))
|
|
||||||
if err != nil {
|
|
||||||
itx.SendLinearReply(err.Error(), false)
|
|
||||||
}
|
|
||||||
|
|
||||||
itx.SendLinearReply("Hello " + user.Tag(), false)
|
|
||||||
} else {
|
|
||||||
itx.SendLinearReply("Hello " + itx.Member.User.Tag(), false)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
|
||||||
+7
-12
@@ -3,27 +3,28 @@ package commands
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
|
||||||
tempest "github.com/Amatsagu/Tempest"
|
tempest "github.com/Amatsagu/Tempest"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const timeout time.Duration = 10000000000
|
||||||
|
|
||||||
var Pinned tempest.Command = tempest.Command{
|
var Pinned tempest.Command = tempest.Command{
|
||||||
Name: "pinned",
|
Name: "pinned",
|
||||||
Description: "will show a random pinned message",
|
Description: "will show a random pinned message",
|
||||||
Options: []tempest.Option{},
|
Options: []tempest.Option{},
|
||||||
SlashCommandHandler: func(itx tempest.CommandInteraction) {
|
SlashCommandHandler: func(itx tempest.CommandInteraction) {
|
||||||
log.Print("inside pinned command")
|
|
||||||
|
_, close := itx.Client.AwaitComponent([]string{itx.Id.String()}, timeout)
|
||||||
|
|
||||||
messages, err := getPinnedMessages(itx.Client.Rest, itx.ChannelId.String())
|
messages, err := getPinnedMessages(itx.Client.Rest, itx.ChannelId.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to get messages: %s", err.Error())
|
|
||||||
itx.SendLinearReply(err.Error(), false)
|
itx.SendLinearReply(err.Error(), false)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Print("after get pinned messages")
|
|
||||||
|
|
||||||
messagesCount := len(messages)
|
messagesCount := len(messages)
|
||||||
|
|
||||||
@@ -34,21 +35,16 @@ var Pinned tempest.Command = tempest.Command{
|
|||||||
|
|
||||||
idx := rand.Intn(messagesCount)
|
idx := rand.Intn(messagesCount)
|
||||||
|
|
||||||
log.Printf("just before send message, %d, %d", idx, messagesCount)
|
if _, err = itx.Client.SendMessage(itx.ChannelId, messages[idx]); err != nil {
|
||||||
log.Printf("# selected message: %+v", messages[idx])
|
|
||||||
|
|
||||||
|
|
||||||
if err = itx.Client.CrosspostMessage(itx.ChannelId, messages[idx].Id); err != nil {
|
|
||||||
log.Printf("failed to send message: %s", err.Error())
|
|
||||||
itx.SendLinearReply(err.Error(), false)
|
itx.SendLinearReply(err.Error(), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
close()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
log.Printf("Route: %s", route)
|
|
||||||
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
|
||||||
@@ -56,7 +52,6 @@ func getPinnedMessages(rest tempest.Rest, channelID string) ([]tempest.Message,
|
|||||||
|
|
||||||
messages := []tempest.Message{}
|
messages := []tempest.Message{}
|
||||||
if err = json.Unmarshal(bytes, &messages); err != nil {
|
if err = json.Unmarshal(bytes, &messages); err != nil {
|
||||||
log.Printf("## error unmarshalling ## %s", err.Error())
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user