split the commands into individual files
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/discord/cmdhelp.go Sat Jun 08 03:46:31 2019 -0500
@@ -0,0 +1,31 @@
+ "github.com/alecthomas/kong" + Command []string `kong:"arg,optional,help='command to get help on'"` +func (c *HelpCmd) Run(g *Globals) error { + ctx, err := kong.Trace(g.ctx.Kong, c.Command) + err = ctx.PrintUsage(true) + fmt.Fprintln(g.ctx.Stdout) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/discord/cmdsetchannel.go Sat Jun 08 03:46:31 2019 -0500
@@ -0,0 +1,29 @@
+ "bitbucket.org/rw_grim/wasdead/database" +type SetChannelCmd struct{} +func (c *SetChannelCmd) Run(g *Globals) error { + guild, err := database.LoadGuild(g.msg.GuildID) + resp := fmt.Sprintf("<#%s> is already set as the announcement channel", g.msg.ChannelID) + if guild.Channel != g.msg.ChannelID { + guild.Channel = g.msg.ChannelID + resp = fmt.Sprintf("Set <#%s> as the announcement channel", g.msg.ChannelID) + g.client.sendChannel(g.msg.ChannelID, resp) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/discord/cmdshowconfig.go Sat Jun 08 03:46:31 2019 -0500
@@ -0,0 +1,35 @@
+ "github.com/bwmarrin/discordgo" + "bitbucket.org/rw_grim/wasdead/database" +type ShowConfigCmd struct{} +func (c *ShowConfigCmd) Run(g *Globals) error { + guild, err := database.LoadGuild(g.msg.GuildID) + channel, err := g.client.client.Channel(guild.Channel) + embed := &discordgo.MessageEmbed{ + Title: "@wasdead configuration", + Fields: []*discordgo.MessageEmbedField{ + &discordgo.MessageEmbedField{ + Name: "Announcement Channel", + Value: channel.Mention(), + g.client.sendEmbedChannel(g.msg.ChannelID, embed) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/discord/cmdstatus.go Sat Jun 08 03:46:31 2019 -0500
@@ -0,0 +1,45 @@
+ "github.com/bwmarrin/discordgo" + "bitbucket.org/rw_grim/wasdead/presence" + Target string `kong:"arg"` +func (c *StatusCmd) Run(g *Globals) error { + if strings.HasPrefix(c.Target, "<@") { + mentionID := c.Target[2 : len(c.Target)-1] + for _, mentioned := range g.msg.Mentions { + if mentioned.ID == mentionID { + p := g.client.getPresence(g.msg.GuildID, mentioned.ID) + if p != nil && p.Game != nil && p.Game.Type == discordgo.GameTypeStreaming { + return fmt.Errorf("%s is not currently streaming", c.Target) + uri = "https://twitch.tv/" + c.Target + presence, err := presence.GetPresence(uri) + return g.client.sendEmbedChannel(g.msg.ChannelID, presenceEmbed(presence)) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/discord/cmduptime.go Sat Jun 08 03:46:31 2019 -0500
@@ -0,0 +1,18 @@
+ "github.com/dustin/go-humanize" +func (c *UptimeCmd) Run(g *Globals) error { + fmt.Sprintf("Started %s", humanize.Time(g.client.started)), --- a/discord/commands.go Thu Jun 06 01:52:01 2019 -0500
+++ b/discord/commands.go Sat Jun 08 03:46:31 2019 -0500
@@ -6,10 +6,6 @@
"github.com/alecthomas/kong"
"github.com/bwmarrin/discordgo"
- "github.com/dustin/go-humanize"
- "bitbucket.org/rw_grim/wasdead/database"
- "bitbucket.org/rw_grim/wasdead/presence"
@@ -29,30 +25,6 @@
Uptime UptimeCmd `kong:"cmd,help='display how long the bot has been running for'"`
- Command []string `kong:"arg,optional,help='command to get help on'"`
-func (c *HelpCmd) Run(g *Globals) error {
- ctx, err := kong.Trace(g.ctx.Kong, c.Command)
- err = ctx.PrintUsage(true)
- fmt.Fprintln(g.ctx.Stdout)
func (c *Order66Cmd) Run(g *Globals) error {
@@ -60,102 +32,6 @@
-type SetChannelCmd struct{}
-func (c *SetChannelCmd) Run(g *Globals) error {
- guild, err := database.LoadGuild(g.msg.GuildID)
- resp := fmt.Sprintf("<#%s> is already set as the announcement channel", g.msg.ChannelID)
- if guild.Channel != g.msg.ChannelID {
- guild.Channel = g.msg.ChannelID
- resp = fmt.Sprintf("Set <#%s> as the announcement channel", g.msg.ChannelID)
- g.client.sendChannel(g.msg.ChannelID, resp)
-type ShowConfigCmd struct{}
-func (c *ShowConfigCmd) Run(g *Globals) error {
- guild, err := database.LoadGuild(g.msg.GuildID)
- channel, err := g.client.client.Channel(guild.Channel)
- embed := &discordgo.MessageEmbed{
- Title: "@wasdead configuration",
- Fields: []*discordgo.MessageEmbedField{
- &discordgo.MessageEmbedField{
- Name: "Announcement Channel",
- Value: channel.Mention(),
- g.client.sendEmbedChannel(g.msg.ChannelID, embed)
- Target string `kong:"arg"`
-func (c *StatusCmd) Run(g *Globals) error {
- if strings.HasPrefix(c.Target, "<@") {
- mentionID := c.Target[2 : len(c.Target)-1]
- for _, mentioned := range g.msg.Mentions {
- if mentioned.ID == mentionID {
- p := g.client.getPresence(g.msg.GuildID, mentioned.ID)
- if p != nil && p.Game != nil && p.Game.Type == discordgo.GameTypeStreaming {
- return fmt.Errorf("%s is not currently streaming", c.Target)
- uri = "https://twitch.tv/" + c.Target
- presence, err := presence.GetPresence(uri)
- return g.client.sendEmbedChannel(g.msg.ChannelID, presenceEmbed(presence))
-func (c *UptimeCmd) Run(g *Globals) error {
- fmt.Sprintf("Started %s", humanize.Time(g.client.started)),
func (c *DiscordClient) processCommand(args []string, m *discordgo.MessageCreate) error {