Add !version, remove !source

This commit is contained in:
Ryan Cavicchioni 2022-08-07 07:13:17 -05:00
parent 1643fef377
commit bbdbe1e926
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
3 changed files with 48 additions and 38 deletions

View File

@ -33,8 +33,8 @@ var (
command.NewPingHandler(),
command.NewRollHandler(),
command.NewRouletteHandler(),
command.NewSourceHandler(),
command.NewTimeHandler(),
command.NewVersionHandler("version"),
command.NewWeatherHandler(),
}
)

View File

@ -1,37 +0,0 @@
package command
import (
"strings"
"github.com/bwmarrin/discordgo"
)
const (
SourceURI = "https://git.kill0.net/chill9/bb"
)
type (
SourceHandler struct {
config Config
}
)
func NewSourceHandler() *SourceHandler {
return new(SourceHandler)
}
func (h *SourceHandler) SetConfig(config Config) {
h.config = config
}
func (h *SourceHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID {
return
}
if !strings.HasPrefix(m.Content, "!source") {
return
}
s.ChannelMessageSend(m.ChannelID, SourceURI)
}

47
command/version.go Normal file
View File

@ -0,0 +1,47 @@
package command
import (
"fmt"
"runtime"
"github.com/bwmarrin/discordgo"
)
const (
SourceURI = "https://git.kill0.net/chill9/bb"
)
type (
VersionHandler struct {
config Config
Name string
}
)
func NewVersionHandler(s string) *VersionHandler {
h := new(VersionHandler)
h.Name = s
return h
}
func (h *VersionHandler) SetConfig(config Config) {
h.config = config
}
func (h *VersionHandler) Handle(s *discordgo.Session, m *discordgo.MessageCreate) {
if m.Author.ID == s.State.User.ID {
return
}
if !HasCommand(m.Content, h.config.Prefix, h.Name) {
return
}
s.ChannelMessageSend(m.ChannelID, fmt.Sprintf(
"go version: %s\nplatform: %s\nos: %s\nsource: %s\n",
runtime.Version(),
runtime.GOARCH,
runtime.GOOS,
SourceURI,
))
}