commit 7061028af37ec542f6e74c28519a5889b487613b Author: mimu Date: Sun Oct 9 07:32:56 2022 +0200 test cmd diff --git a/commands/hello.go b/commands/hello.go new file mode 100644 index 0000000..993a421 --- /dev/null +++ b/commands/hello.go @@ -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) + } + }, +} diff --git a/commands/pinned.go b/commands/pinned.go new file mode 100644 index 0000000..42ec14b --- /dev/null +++ b/commands/pinned.go @@ -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) { + + }, +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..61f0262 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module hal + +go 1.19 + +require github.com/Amatsagu/Tempest v1.0.1 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f64f810 --- /dev/null +++ b/go.sum @@ -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= diff --git a/main.go b/main.go new file mode 100644 index 0000000..edd4329 --- /dev/null +++ b/main.go @@ -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) + } +} diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..44db0b2 --- /dev/null +++ b/readme.md @@ -0,0 +1 @@ +# Hal