Add compliment command and refactor (#7)
Update example config Signed-off-by: Etzelia <etzelia@hotmail.com> Add compliment command and refactor Signed-off-by: Etzelia <etzelia@hotmail.com> Reviewed-on: https://git.etztech.xyz/Etzelia/sedbot/pulls/7ban
parent
66a418261e
commit
f204ee6e37
|
@ -13,6 +13,7 @@ BirbMC Discord generi-bot.
|
||||||
* `inspire` - Get a random "inspirational" message from [InspiroBot](https://inspirobot.me)
|
* `inspire` - Get a random "inspirational" message from [InspiroBot](https://inspirobot.me)
|
||||||
* `dad` - Get a random dad joke from [icanhazdadjoke](https://icanhazdadjoke.com)
|
* `dad` - Get a random dad joke from [icanhazdadjoke](https://icanhazdadjoke.com)
|
||||||
* `insult` - The fan favorite returns
|
* `insult` - The fan favorite returns
|
||||||
|
* `compliment` - The other fan favorite returns
|
||||||
* `names <in-game name> [<01/02/2006>]` - Minecraft name history (optionally at a specific time)
|
* `names <in-game name> [<01/02/2006>]` - Minecraft name history (optionally at a specific time)
|
||||||
|
|
||||||
### Moderation
|
### Moderation
|
||||||
|
|
|
@ -29,6 +29,11 @@ type Config struct {
|
||||||
Adjectives []string `toml:"adjectives"`
|
Adjectives []string `toml:"adjectives"`
|
||||||
Nouns []string `toml:"nouns"`
|
Nouns []string `toml:"nouns"`
|
||||||
} `toml:"insult"`
|
} `toml:"insult"`
|
||||||
|
Compliment struct {
|
||||||
|
Verbs []string `toml:"verbs"`
|
||||||
|
Nouns []string `toml:"nouns"`
|
||||||
|
MinorThings []string `toml:"minor_things"`
|
||||||
|
} `toml:"compliment"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageRole struct {
|
type MessageRole struct {
|
||||||
|
|
|
@ -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!",
|
||||||
|
}
|
||||||
|
}
|
|
@ -74,7 +74,7 @@ func sendMessage(s *discordgo.Session, channelID, content string, scrub bool) *d
|
||||||
var err error
|
var err error
|
||||||
if scrub {
|
if scrub {
|
||||||
msg, err = s.ChannelMessageSendComplex(channelID, &discordgo.MessageSend{
|
msg, err = s.ChannelMessageSendComplex(channelID, &discordgo.MessageSend{
|
||||||
Content: content,
|
Content: content,
|
||||||
AllowedMentions: &discordgo.MessageAllowedMentions{},
|
AllowedMentions: &discordgo.MessageAllowedMentions{},
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -2,9 +2,7 @@ package discord
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
r "math/rand"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -43,16 +41,3 @@ func init() {
|
||||||
help: "Insult someone!",
|
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]
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package discord
|
package discord
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
r "math/rand"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -24,3 +25,16 @@ func (r *rateLimit) Try() bool {
|
||||||
}
|
}
|
||||||
return false
|
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]
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,13 @@ comparisons = []
|
||||||
adjectives = []
|
adjectives = []
|
||||||
nouns = []
|
nouns = []
|
||||||
|
|
||||||
|
# compliments
|
||||||
|
# <args>, I would <verb> my <noun> just to <minor thing>.
|
||||||
|
[compliment]
|
||||||
|
verbs = []
|
||||||
|
nouns = []
|
||||||
|
minor_things = []
|
||||||
|
|
||||||
# echoes are any basic command -> message
|
# echoes are any basic command -> message
|
||||||
[[echoes]]
|
[[echoes]]
|
||||||
name = "discord"
|
name = "discord"
|
||||||
|
|
Loading…
Reference in New Issue