diff --git a/commands/hello.go b/commands/hello.go deleted file mode 100644 index 993a421..0000000 --- a/commands/hello.go +++ /dev/null @@ -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) - } - }, -} diff --git a/commands/pinned.go b/commands/pinned.go index fa1a04e..173ffe8 100644 --- a/commands/pinned.go +++ b/commands/pinned.go @@ -3,27 +3,28 @@ package commands import ( "encoding/json" "fmt" - "log" "math/rand" + "time" tempest "github.com/Amatsagu/Tempest" ) +const timeout time.Duration = 10000000000 + var Pinned tempest.Command = tempest.Command{ Name: "pinned", Description: "will show a random pinned message", Options: []tempest.Option{}, 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()) if err != nil { - log.Printf("failed to get messages: %s", err.Error()) itx.SendLinearReply(err.Error(), false) return } - log.Print("after get pinned messages") messagesCount := len(messages) @@ -34,21 +35,16 @@ var Pinned tempest.Command = tempest.Command{ idx := rand.Intn(messagesCount) - log.Printf("just before send message, %d, %d", idx, messagesCount) - 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()) + if _, err = itx.Client.SendMessage(itx.ChannelId, messages[idx]); err != nil { itx.SendLinearReply(err.Error(), false) } + close() }, } func getPinnedMessages(rest tempest.Rest, channelID string) ([]tempest.Message, error) { route := fmt.Sprintf("/channels/%s/pins", channelID) - log.Printf("Route: %s", route) bytes, err := rest.Request("GET", route, nil) if err != nil { return nil, err @@ -56,7 +52,6 @@ func getPinnedMessages(rest tempest.Rest, channelID string) ([]tempest.Message, messages := []tempest.Message{} if err = json.Unmarshal(bytes, &messages); err != nil { - log.Printf("## error unmarshalling ## %s", err.Error()) return nil, err }