diff --git a/main/config.json b/main/config.json index e98da5c1..63b9862b 100644 --- a/main/config.json +++ b/main/config.json @@ -1 +1 @@ -{"debug":true,"maxerror":4,"maxwit":1,"maxspam":30,"maxbored":300,"maxspoiltime":15,"maxpmlines":5,"maxquotelines":50,"maxmarkovlines":100,"maxsearchresults":10,"defaultmarkovlines":30,"maxshutup":10,"commandperduration":3,"commandmaxduration":30,"statusdelaytime":10,"maxraidtime":180,"raidsize":3,"emotes":["canada","BlockJuice","octybelleintensifies","angstybloom","alltheclops","bob","darklelicious","flutterbutts","doitfor24","allthetables","ave","sbrapestare","gak","beforetacoswerecool","bigenough","juice"],"boredlines":["bored triggered"],"spoilers":{"testspoiler2":true},"witty":{"beep boop":"[](/sbload)"},"schedule":null,"statuses":[],"bucket":{"a horse":true},"maxbucket":4,"groups":{"blah":{"95585199324143616":true,"98605232707080192":true},"bronycon":{"95585199324143616":true,"98605232707080192":true},"test":{"95585199324143616":true}}} \ No newline at end of file +{"debug":true,"maxerror":4,"maxwit":1,"maxspam":30,"maxbored":300,"maxspoiltime":15,"maxpmlines":5,"maxquotelines":50,"maxmarkovlines":100,"maxsearchresults":10,"defaultmarkovlines":30,"maxshutup":10,"commandperduration":3,"commandmaxduration":30,"statusdelaytime":10,"maxraidtime":180,"raidsize":3,"emotes":["canada","BlockJuice","octybelleintensifies","angstybloom","alltheclops","bob","darklelicious","flutterbutts","doitfor24","allthetables","ave","sbrapestare","gak","beforetacoswerecool","bigenough","juice"],"boredlines":["bored triggered"],"spoilers":{"testspoiler2":true},"witty":{"beep boop":"[](/sbload)"},"schedule":null,"statuses":[],"bucket":{"blah":true},"maxbucket":4,"maxbucketlength":100,"maxfighthp":300,"maxfightdamage":60,"groups":{"blah":{"95585199324143616":true,"98605232707080192":true},"bronycon":{"95585199324143616":true,"98605232707080192":true},"test":{"95585199324143616":true}}} \ No newline at end of file diff --git a/sweetiebot/bucket_command.go b/sweetiebot/bucket_command.go index a310f61f..92b3feee 100644 --- a/sweetiebot/bucket_command.go +++ b/sweetiebot/bucket_command.go @@ -3,6 +3,7 @@ package sweetiebot import ( "github.com/bwmarrin/discordgo" "strings" + "strconv" "math/rand" ) @@ -20,7 +21,11 @@ func (c *GiveCommand) Process(args []string, msg *discordgo.Message) (string, bo return "```I don't have a bucket right now.```", false } - arg := strings.Join(args, " ") + arg := ExtraSanitize(strings.Join(args, " ")) + if len(arg) > sb.config.MaxBucketLength { + return "```That's too big! Give me something smaller!'```", false + } + if len(sb.config.Bucket) <= 0 { sb.config.Bucket = make(map[string]bool) } @@ -114,4 +119,58 @@ func (c *ListCommand) Usage() string { } func (c *ListCommand) UsageShort() string { return "Lists everything sweetie has." } func (c *ListCommand) Roles() []string { return []string{} } -func (c *ListCommand) Channels() []string { return []string{} } \ No newline at end of file +func (c *ListCommand) Channels() []string { return []string{} } + +type FightCommand struct { + monster string + hp int +} + +func (c *FightCommand) Name() string { + return "Fight"; +} +func (c *FightCommand) Process(args []string, msg *discordgo.Message) (string, bool) { + things := MapToSlice(sb.config.Bucket) + if len(things) == 0 { + return "```I have nothing to fight with!```", false + } + if len(c.monster) > 0 && len(args) > 0 { + return "I'm already fighting " + c.monster + ", I have to defeat them first!", false + } + if len(c.monster) == 0 { + if len(args) > 0 { + c.monster = strings.Join(args, " ") + } else { + c.monster = sb.db.GetRandomSpeaker() + } + c.hp = 10 + rand.Intn(sb.config.MaxFightHP) + return "```I have engaged " + c.monster + ", who has " + strconv.Itoa(c.hp) + " HP!```", false + } + + damage := 1 + rand.Intn(sb.config.MaxFightDamage) + c.hp -= damage + end := " and deal " + strconv.Itoa(damage) + " damage!" + monster := c.monster + if c.hp <= 0 { + end += " " + monster + " has been defeated!" + c.monster = "" + } + end += "```" + thing := things[rand.Intn(len(things))] + switch rand.Intn(7) { + case 0: return "```I throw " + BucketDropRandom() + " at " + monster + end, false + case 1: return "```I stab " + monster + " with " + thing + end, false + case 2: return "```I use " + thing + " on " + monster + end, false + case 3: return "```I summon " + thing + end, false + case 4: return "```I cast " + thing + end, false + case 5: return "```I parry a blow and counterattack with " + thing + end, false + case 6: return "```I detonate a " + thing + end, false + } + return "```Stuff happens" + end, false +} +func (c *FightCommand) Usage() string { + return FormatUsage(c, "[name]", "Fights a random pony, or [name] if it is provided.") +} +func (c *FightCommand) UsageShort() string { return "Fights a random pony." } +func (c *FightCommand) Roles() []string { return []string{} } +func (c *FightCommand) Channels() []string { return []string{"mylittlebot", "bot-debug"} } \ No newline at end of file diff --git a/sweetiebot/sweetiebot.go b/sweetiebot/sweetiebot.go index 28877995..0a072717 100644 --- a/sweetiebot/sweetiebot.go +++ b/sweetiebot/sweetiebot.go @@ -66,6 +66,9 @@ type BotConfig struct { Statuses []string `json:"statuses"` Bucket map[string]bool `json:"bucket"` MaxBucket int `json:"maxbucket"` + MaxBucketLength int `json:"maxbucketlength"` + MaxFightHP int `json:"maxfighthp"` + MaxFightDamage int `json:"maxfightdamage"` Groups map[string]map[string]bool `json:"groups"` } @@ -173,6 +176,14 @@ func SanitizeOutput(message string) string { message = sb.emotemodule.emoteban.ReplaceAllStringFunc(message, sbemotereplace) return message; } +func ExtraSanitize(s string) string { + s = strings.Replace(s,"`","",-1) + s = strings.Replace(s, "[](/", "[\u200B](/", -1) + s = strings.Replace(s, "http://", "http\u200B://", -1) + s = strings.Replace(s, "https://", "https\u200B://", -1) + return s +} + func (sbot *SweetieBot) SendMessage(channelID string, message string) { sbot.dg.ChannelMessageSend(channelID, SanitizeOutput(message)); } @@ -298,7 +309,8 @@ func AttachToGuild(g *discordgo.Guild) { sb.AddCommand(&DropCommand{}) sb.AddCommand(&GiveCommand{}) sb.AddCommand(&ListCommand{}) - + sb.AddCommand(&FightCommand{"",0}) + sb.aliases = make(map[string]string) sb.aliases["listgroups"] = "listgroup" @@ -573,6 +585,9 @@ func Initialize(Token string) { initialized: false, } + rand.Intn(10) + for i := 0; i < 20 + rand.Intn(20); i++ { rand.Intn(50) } + errjson := json.Unmarshal(config, &sb.config) if errjson != nil { fmt.Println("Error reading config file: ", errjson.Error()) } //fmt.Println("Config settings: ", sb.config)