From b852b02aed4e20a2e874ec21c08da5487a2b09a9 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Fri, 5 Aug 2022 10:04:04 -0500 Subject: [PATCH] Added !source command --- cmd/bb/main.go | 1 + command/source.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 command/source.go diff --git a/cmd/bb/main.go b/cmd/bb/main.go index 67e06d3..4f51863 100644 --- a/cmd/bb/main.go +++ b/cmd/bb/main.go @@ -33,6 +33,7 @@ var ( command.NewPingHandler(), command.NewRollHandler(), command.NewRouletteHandler(), + command.NewSourceHandler(), command.NewTimeHandler(), command.NewWeatherHandler(), } diff --git a/command/source.go b/command/source.go new file mode 100644 index 0000000..98104bc --- /dev/null +++ b/command/source.go @@ -0,0 +1,37 @@ +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) +}