From 1f954f301cdbb1d5b78acecfd604d3726c636f3c Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Wed, 3 Feb 2021 20:57:58 -0500 Subject: [PATCH] fuck: refactor by removal --- main.go | 2 -- plugins/fuck/fuck.go | 83 -------------------------------------------- 2 files changed, 85 deletions(-) delete mode 100644 plugins/fuck/fuck.go diff --git a/main.go b/main.go index cef8f22..d745a91 100644 --- a/main.go +++ b/main.go @@ -39,7 +39,6 @@ import ( "github.com/velour/catbase/plugins/emojifyme" "github.com/velour/catbase/plugins/fact" "github.com/velour/catbase/plugins/first" - "github.com/velour/catbase/plugins/fuck" "github.com/velour/catbase/plugins/git" "github.com/velour/catbase/plugins/impossible" "github.com/velour/catbase/plugins/inventory" @@ -121,7 +120,6 @@ func main() { b.AddPlugin(emojifyme.New(b)) b.AddPlugin(first.New(b)) b.AddPlugin(leftpad.New(b)) - b.AddPlugin(fuck.New(b)) b.AddPlugin(talker.New(b)) b.AddPlugin(dice.New(b)) b.AddPlugin(picker.New(b)) diff --git a/plugins/fuck/fuck.go b/plugins/fuck/fuck.go deleted file mode 100644 index 4171757..0000000 --- a/plugins/fuck/fuck.go +++ /dev/null @@ -1,83 +0,0 @@ -package fuck - -import ( - "bytes" - "fmt" - "strings" - - "github.com/chrissexton/gofuck" - "github.com/rs/zerolog/log" - - "github.com/velour/catbase/bot" - "github.com/velour/catbase/bot/msg" - "github.com/velour/catbase/config" -) - -type Fuck struct { - b bot.Bot - c *config.Config -} - -func New(b bot.Bot) *Fuck { - f := &Fuck{ - b: b, - c: b.Config(), - } - - b.Register(f, bot.Help, f.help) - b.Register(f, bot.Message, f.message) - - return f -} - -func (p *Fuck) help(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool { - helpMsg := "Run brainfuck with: `!fuck `````` `\n\nFor example:\n> !fuck ```,[.,]``` hello" - p.b.Send(c, bot.Message, message.Channel, helpMsg) - return true -} - -func (p *Fuck) message(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool { - lowerBody := strings.ToLower(message.Body) - if message.Command && strings.HasPrefix(lowerBody, "fuck") { - fields := strings.Split(message.Body, "```") - if len(fields) < 2 { - return false - } - - pgm := fields[1] - in := strings.Join(fields[2:], "```") - - log.Debug(). - Str("pgm", pgm). - Str("in", in). - Msg("Asked to fuck hard") - - stdin := bytes.NewBufferString(in) - stdout := &bytes.Buffer{} - - m := gofuck.New(stdin, stdout) - - m.InstructionLimit = p.c.GetInt("fuck.limit.instr", 100000) - if m.InstructionLimit < 1 { - m.InstructionLimit = 1 - } - maxOut := p.c.GetInt("fuck.limit.output", 1000) - - err := m.Run([]byte(pgm)) - if stdout.Len() > maxOut { - stdout.Truncate(maxOut) - } - if err != nil { - p.b.Send(c, bot.Message, message.Channel, fmt.Sprintf("Error running program: %s", err)) - if stdout.Len() > 0 { - p.b.Send(c, bot.Message, message.Channel, - fmt.Sprintf("Here's the output so far:\n%s", stdout.String())) - } - return true - } - - p.b.Send(c, bot.Message, message.Channel, stdout.String()) - return true - } - return false -}