From bcb54734ef5e685ed5b4cca6e79c61f4c19696c9 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Sun, 7 Aug 2022 07:13:17 -0500 Subject: [PATCH] Add !version, remove !source --- command/source.go | 37 ------------------------------------ command/version.go | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 37 deletions(-) delete mode 100644 command/source.go create mode 100644 command/version.go diff --git a/command/source.go b/command/source.go deleted file mode 100644 index 98104bc..0000000 --- a/command/source.go +++ /dev/null @@ -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) -} diff --git a/command/version.go b/command/version.go new file mode 100644 index 0000000..8917055 --- /dev/null +++ b/command/version.go @@ -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, + )) +}