Skip to content

Commit

Permalink
Add buttsbot
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascdev committed Sep 17, 2024
1 parent bac83da commit 41e960b
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
- Add join and part commands
- Add setlevel command
- Add setenabled command
- Add buttsbot
23 changes: 23 additions & 0 deletions command/buttsbot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package command

var buttsbot = Command{
Name: "buttsbot",
Aliases: []string{},
Usage: "send any message in chat",
Description: "Replaces random syllables with butt",
Cooldown: 5,
NoPrefix: true,
// TODO: this affects the probability, Buttify shoudn't have to run twice
NoPrefixShouldRun: func(message *Message, sender MessageSender, args []string) bool {
_, didButtify := sender.Buttify(message.Message)
return didButtify
},
CanDisable: false,
Execute: func(message *Message, sender MessageSender, args []string) error {
newSentence, didButtify := sender.Buttify(message.Message)
if didButtify {
sender.Say(message.Channel, newSentence)
}
return nil
},
}
4 changes: 4 additions & 0 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import (

type MessageSender interface {
Say(channel string, message string)

Join(channels ...string)
Part(channels ...string)

Buttify(message string) (string, bool)
}

type Command struct {
Expand Down Expand Up @@ -73,6 +76,7 @@ var Commands = []Command{
part,
setLevel,
setenabled,
buttsbot,
}

var (
Expand Down
4 changes: 4 additions & 0 deletions command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func (m *MockSender) Say(channel string, message string) {
func (m *MockSender) Join(channels ...string) {}
func (m *MockSender) Part(channels ...string) {}

func (m *MockSender) Buttify(message string) (string, bool) {
return message, true
}

func TestCommandMap(t *testing.T) {
expected, got := 0, len(commandMap)
for _, cmd := range Commands {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ require (
)

require (
github.com/douglascdev/buttifier v0.0.4 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/ncruces/go-sqlite3 v0.18.2 // indirect
github.com/ncruces/julianday v1.0.0 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/speedata/hyphenation v1.0.2 // indirect
github.com/tetratelabs/wazero v1.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
github.com/Potat-Industries/go-potatFilters v0.1.1 h1:QhVVRjvdyEPdWNyi9cgYIzxaRLErlahu2icsANVhm8w=
github.com/Potat-Industries/go-potatFilters v0.1.1/go.mod h1:sbz39k2QTCzF51Ar1FP/GfPMu2YvoCb4Xa1ytxZ9XZ4=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/douglascdev/buttifier v0.0.4 h1:CPeAOYdRPCwTpT5gI5P+6DQohkCOGUbiLqjC3QP6bkA=
github.com/douglascdev/buttifier v0.0.4/go.mod h1:NwWm2htIvguVOd+IJPZYlIH9Y5x6969bbswtFmPsZ0E=
github.com/gempir/go-twitch-irc/v4 v4.0.0 h1:sHVIvbWOv9nHXGEErilclxASv0AaQEr/r/f9C0B9aO8=
github.com/gempir/go-twitch-irc/v4 v4.0.0/go.mod h1:QsOMMAk470uxQ7EYD9GJBGAVqM/jDrXBNbuePfTauzg=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand All @@ -18,6 +20,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/speedata/hyphenation v1.0.2 h1:2rDCtAqNfbf+E56SsqbmNApsVx9CH+4fwIh1RZuu3B8=
github.com/speedata/hyphenation v1.0.2/go.mod h1:vwrKKvBvJWFll0sVZw99hyWS/+r4YlMI7MAYjnje0nM=
github.com/tetratelabs/wazero v1.8.0 h1:iEKu0d4c2Pd+QSRieYbnQC9yiFlMS9D+Jr0LsRmcF4g=
github.com/tetratelabs/wazero v1.8.0/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
13 changes: 13 additions & 0 deletions monkebot/monkebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"monkebot/twitchapi"
"time"

"github.com/douglascdev/buttifier"
"github.com/rs/zerolog/log"

"github.com/Potat-Industries/go-potatFilters"
Expand All @@ -19,14 +20,22 @@ type Monkebot struct {
TwitchClient *twitch.Client
Cfg config.Config
db *sql.DB
buttifier *buttifier.Buttifier
}

func NewMonkebot(cfg config.Config, db *sql.DB) (*Monkebot, error) {
client := twitch.NewClient(cfg.Login, "oauth:"+cfg.TwitchToken)

butt, err := buttifier.New()
if err != nil {
return nil, fmt.Errorf("failed to initialize buttifier: %w", err)
}

mb := &Monkebot{
TwitchClient: client,
Cfg: cfg,
db: db,
buttifier: butt,
}

client.OnPrivateMessage(func(message twitch.PrivateMessage) {
Expand Down Expand Up @@ -157,3 +166,7 @@ func (t *Monkebot) Say(channel string, message string) {
const invisPrefix = "󠀀�" // prevents command injection
t.TwitchClient.Say(channel, invisPrefix+message)
}

func (t *Monkebot) Buttify(message string) (string, bool) {
return t.buttifier.ButtifySentence(message)
}

0 comments on commit 41e960b

Please sign in to comment.