From 50574a164f556e440fb6ffd434fe09c4e0ef0015 Mon Sep 17 00:00:00 2001 From: Tippi Fifestarr <62179036+tippi-fifestarr@users.noreply.github.com> Date: Fri, 7 Jan 2022 11:20:13 -0600 Subject: [PATCH 1/2] Gaslit a classic 8Ball resp Added a missing and important standard 8ball response --- plugins/8ball.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/8ball.go b/plugins/8ball.go index d6bf42b..a5c24d3 100644 --- a/plugins/8ball.go +++ b/plugins/8ball.go @@ -34,7 +34,7 @@ func eightball(msg onelib.Message, sender onelib.Sender) { "You may rely on it", "Reply hazy, try again", "Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again", "Don't count on it", "My reply is no", "My sources say no", "Outlook not so good", - "Very doubtful"} + "Very doubtful", "Never ask that again"} randn := rand.Intn(len(eightballAnswers)) text = eightballAnswers[randn] + "." formattedText = text From 7715153664d44b078d511a8c04eba6c4ee7bb16d Mon Sep 17 00:00:00 2001 From: Tippi Fifestarr <62179036+tippi-fifestarr@users.noreply.github.com> Date: Fri, 6 Oct 2023 09:02:20 -0500 Subject: [PATCH 2/2] Update 8ball.go 1. Moved the eightballAnswers slice to the package level so it can be modified by the eightball function. 2. Added logic to the eightball function to handle "add " and "remove " prefixes in the message text. If the message starts with "add ", the rest of the message is added as a new response. If the message starts with "remove ", the rest of the message is removed from the list of responses if it exists. Now, users can add or remove custom responses by sending messages like "add My custom response" or "remove My custom response". --- plugins/8ball.go | 49 ++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/plugins/8ball.go b/plugins/8ball.go index a5c24d3..13820c1 100644 --- a/plugins/8ball.go +++ b/plugins/8ball.go @@ -6,65 +6,70 @@ import ( "fmt" "github.com/TheDiscordian/onebot/onelib" "math/rand" + "strings" ) const ( - // NAME is same as filename, minus extension - NAME = "8ball" - // LONGNAME is what's presented to the user + NAME = "8ball" LONGNAME = "8Ball Plugin" - // VERSION of the plugin - VERSION = "v0.0.0" + VERSION = "v0.0.1" ) -// Load returns the Plugin object. -func Load() onelib.Plugin { - return new(EightBallPlugin) +var eightballAnswers = []string{ + "As I see it, yes", "It is certain", "It is decidedly so", "Most likely", + "Outlook good", "Signs point to yes", "Without a doubt", "Yes", "Yes, definitely", + "You may rely on it", "Reply hazy, try again", "Ask again later", + "Better not tell you now", "Cannot predict now", "Concentrate and ask again", + "Don't count on it", "My reply is no", "My sources say no", "Outlook not so good", + "Very doubtful", "Never ask that question again" } func eightball(msg onelib.Message, sender onelib.Sender) { var formattedText string text := msg.Text() - if len(text) < 3 { + + if strings.HasPrefix(text, "add ") { + newAnswer := strings.TrimPrefix(text, "add ") + eightballAnswers = append(eightballAnswers, newAnswer) + text = "Added new response." + } else if strings.HasPrefix(text, "remove ") { + remAnswer := strings.TrimPrefix(text, "remove ") + for i, answer := range eightballAnswers { + if answer == remAnswer { + eightballAnswers = append(eightballAnswers[:i], eightballAnswers[i+1:]...) + text = "Removed response." + break + } + } + } else if len(text) < 3 { text = fmt.Sprintf("Predicts the future. Usage: %s8ball ``", onelib.DefaultPrefix) formattedText = fmt.Sprintf("Predicts the future. Usage: %s8ball <y/n question>", onelib.DefaultPrefix) } else { - eightballAnswers := []string{"As I see it, yes", "It is certain", "It is decidedly so", "Most likely", - "Outlook good", "Signs point to yes", "Without a doubt", "Yes", "Yes, definitely", - "You may rely on it", "Reply hazy, try again", "Ask again later", - "Better not tell you now", "Cannot predict now", "Concentrate and ask again", - "Don't count on it", "My reply is no", "My sources say no", "Outlook not so good", - "Very doubtful", "Never ask that again"} randn := rand.Intn(len(eightballAnswers)) text = eightballAnswers[randn] + "." - formattedText = text } + + formattedText = text sender.Location().SendFormattedText(text, formattedText) } -// EightBallPlugin is an object for satisfying the Plugin interface. type EightBallPlugin int -// Name returns the name of the plugin, usually the filename. func (eb *EightBallPlugin) Name() string { return NAME } -// LongName returns the display name of the plugin. func (eb *EightBallPlugin) LongName() string { return LONGNAME } -// Version returns the version of the plugin, usually in the format of "v0.0.0". func (eb *EightBallPlugin) Version() string { return VERSION } -// Implements returns a map of commands and monitor the plugin implements. func (eb *EightBallPlugin) Implements() (map[string]onelib.Command, *onelib.Monitor) { return map[string]onelib.Command{"8b": eightball, "8ball": eightball}, nil } -// Remove is necessary to satisfy the Plugin interface, it does nothing. func (eb *EightBallPlugin) Remove() { }