diff --git a/README.md b/README.md index 892649f..5451cdc 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ BirbMC Discord generi-bot. * `inspire` - Get a random "inspirational" message from [InspiroBot](https://inspirobot.me) * `dad` - Get a random dad joke from [icanhazdadjoke](https://icanhazdadjoke.com) * `insult` - The fan favorite returns +* `compliment` - The other fan favorite returns * `names [<01/02/2006>]` - Minecraft name history (optionally at a specific time) ### Moderation diff --git a/config/config.go b/config/config.go index 8ea5ca6..8f45f89 100644 --- a/config/config.go +++ b/config/config.go @@ -29,6 +29,11 @@ type Config struct { Adjectives []string `toml:"adjectives"` Nouns []string `toml:"nouns"` } `toml:"insult"` + Compliment struct { + Verbs []string `toml:"verbs"` + Nouns []string `toml:"nouns"` + MinorThings []string `toml:"minor_things"` + } `toml:"compliment"` } type MessageRole struct { diff --git a/discord/compliment.go b/discord/compliment.go new file mode 100644 index 0000000..3df9afa --- /dev/null +++ b/discord/compliment.go @@ -0,0 +1,42 @@ +package discord + +import ( + "fmt" + "strings" +) + +func init() { + commands["compliment"] = command{ + validate: func(cmd commandInit) bool { + return true + }, + run: func(cmd commandInit) (string, error) { + if !memeRateLimit.Try() { + return "", nil + } + + fields := strings.Fields(cmd.message.Content) + + var target string + if len(fields) > 1 { + target = strings.Join(fields[1:], " ") + } else if cmd.message.Member.Nick != "" { + target = cmd.message.Member.Nick + } else { + target = cmd.message.Author.Username + } + + compliment := fmt.Sprintf("%s, I would %s my %s just to %s.", + target, + random(cmd.config.Compliment.Verbs), + random(cmd.config.Compliment.Nouns), + random(cmd.config.Compliment.MinorThings), + ) + + sendMessage(cmd.session, cmd.message.ChannelID, compliment, true) + + return "", nil + }, + help: "Compliment someone!", + } +} diff --git a/discord/discord.go b/discord/discord.go index 6a8c093..3a3e5ea 100644 --- a/discord/discord.go +++ b/discord/discord.go @@ -74,7 +74,7 @@ func sendMessage(s *discordgo.Session, channelID, content string, scrub bool) *d var err error if scrub { msg, err = s.ChannelMessageSendComplex(channelID, &discordgo.MessageSend{ - Content: content, + Content: content, AllowedMentions: &discordgo.MessageAllowedMentions{}, }) } else { diff --git a/discord/insult.go b/discord/insult.go index f0ee2d9..ad85472 100644 --- a/discord/insult.go +++ b/discord/insult.go @@ -2,9 +2,7 @@ package discord import ( "fmt" - r "math/rand" "strings" - "time" ) func init() { @@ -43,16 +41,3 @@ func init() { help: "Insult someone!", } } - -var rand = r.New(r.NewSource(time.Now().Unix())) - -func random(list []string) string { - size := len(list) - if size == 0 { - return "" - } else if size == 1 { - return list[0] - } - idx := rand.Intn(size) - return list[idx] -} diff --git a/discord/utils.go b/discord/utils.go index c6582b2..7406bbb 100644 --- a/discord/utils.go +++ b/discord/utils.go @@ -1,6 +1,7 @@ package discord import ( + r "math/rand" "time" ) @@ -24,3 +25,16 @@ func (r *rateLimit) Try() bool { } return false } + +var rand = r.New(r.NewSource(time.Now().Unix())) + +func random(list []string) string { + size := len(list) + if size == 0 { + return "" + } else if size == 1 { + return list[0] + } + idx := rand.Intn(size) + return list[idx] +} diff --git a/sedbot.example.toml b/sedbot.example.toml index ad890ba..da547da 100644 --- a/sedbot.example.toml +++ b/sedbot.example.toml @@ -36,6 +36,13 @@ comparisons = [] adjectives = [] nouns = [] +# compliments +# , I would my just to . +[compliment] +verbs = [] +nouns = [] +minor_things = [] + # echoes are any basic command -> message [[echoes]] name = "discord"