-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: create command helpers also move _example to 0_example since gopls doesn't like the _example directory name. * doc comment + impl createOption on base type * generate create command helpers
- Loading branch information
PL Pery
authored
Jan 5, 2022
1 parent
82efc61
commit b03180c
Showing
20 changed files
with
727 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
.vscode/ | ||
.env | ||
.env* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"sync" | ||
|
||
"github.com/Karitham/corde" | ||
) | ||
|
||
var commands = corde.NewSlashCommand("todo", "view edit and remove todos", | ||
corde.NewSubcommand("list", "list todos"), | ||
corde.NewSubcommand("add", "add a todo", | ||
corde.NewStringOption("name", "todo name", true), | ||
corde.NewStringOption("value", "todo value", true), | ||
corde.NewUserOption("user", "assign it to a user", false), | ||
), | ||
corde.NewSubcommand("rm", "remove a todo", | ||
corde.NewStringOption("name", "todo name", true), | ||
), | ||
) | ||
|
||
func main() { | ||
token := os.Getenv("DISCORD_BOT_TOKEN") | ||
if token == "" { | ||
log.Fatalln("DISCORD_BOT_TOKEN not set") | ||
} | ||
appID := corde.SnowflakeFromString(os.Getenv("DISCORD_APP_ID")) | ||
if appID == 0 { | ||
log.Fatalln("DISCORD_APP_ID not set") | ||
} | ||
pk := os.Getenv("DISCORD_PUBLIC_KEY") | ||
if pk == "" { | ||
log.Fatalln("DISCORD_PUBLIC_KEY not set") | ||
} | ||
|
||
t := todo{ | ||
mu: sync.Mutex{}, | ||
list: make(map[string]todoItem), | ||
} | ||
|
||
m := corde.NewMux(pk, appID, token) | ||
m.Route("todo", func(m *corde.Mux) { | ||
m.Command("add", t.addHandler) | ||
m.Command("rm", t.removeHandler) | ||
m.Command("list", t.listHandler) | ||
}) | ||
|
||
g := corde.GuildOpt(corde.SnowflakeFromString(os.Getenv("DISCORD_GUILD_ID"))) | ||
if err := m.RegisterCommand(commands, g); err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
log.Println("serving on :8070") | ||
if err := m.ListenAndServe(":8070"); err != nil { | ||
log.Fatalln(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.