test cmd
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
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)
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package commands
|
||||
|
||||
import tempest "github.com/Amatsagu/Tempest"
|
||||
|
||||
var Pinned tempest.Command = tempest.Command{
|
||||
Name: "pinned",
|
||||
Description: "will show a random pinned message",
|
||||
Options: []tempest.Option{},
|
||||
SlashCommandHandler: func(itx tempest.CommandInteraction) {
|
||||
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
module hal
|
||||
|
||||
go 1.19
|
||||
|
||||
require github.com/Amatsagu/Tempest v1.0.1 // indirect
|
||||
@@ -0,0 +1,2 @@
|
||||
github.com/Amatsagu/Tempest v1.0.1 h1:PgOPFLNbBevmWwBZuckjuNDuf/WRhVqwp2rjY6qsflE=
|
||||
github.com/Amatsagu/Tempest v1.0.1/go.mod h1:xlvyMhNWe2t/cbyS2pcxb+WR9qtxMvVs2tjmtvLPyLQ=
|
||||
@@ -0,0 +1,49 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hal/commands"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
tempest "github.com/Amatsagu/Tempest"
|
||||
)
|
||||
|
||||
const AppID tempest.Snowflake = 123
|
||||
const PublicKey string = "public_key"
|
||||
const Token string = "token"
|
||||
const Addr string = "0.0.0.0:8080"
|
||||
|
||||
func main() {
|
||||
client := tempest.CreateClient(tempest.ClientOptions{
|
||||
ApplicationId: AppID,
|
||||
PublicKey: PublicKey,
|
||||
Token: Token,
|
||||
PreCommandExecutionHandler: func(itx tempest.CommandInteraction) *tempest.ResponseData {
|
||||
log.Printf("running [%s] slash command", itx.Data.Name)
|
||||
return nil
|
||||
},
|
||||
Cooldowns: &tempest.ClientCooldownOptions{
|
||||
Duration: 5 * time.Second,
|
||||
Ephemeral: true,
|
||||
CooldownResponse: func(user tempest.User, timeLeft time.Duration) tempest.ResponseData {
|
||||
return tempest.ResponseData{
|
||||
Content: fmt.Sprintf("stop spamming, try again in %.2fs", timeLeft.Seconds()),
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
log.Printf("starting server at %s", Addr)
|
||||
|
||||
client.RegisterCommand(commands.Hello)
|
||||
client.RegisterCommand(commands.Pinned)
|
||||
|
||||
client.SyncCommands([]tempest.Snowflake{
|
||||
992760761812258868, // test server
|
||||
}, nil, false)
|
||||
|
||||
if err := client.ListenAndServe(Addr); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user