Skip to content

Commit

Permalink
Fix bucket and add fight command because WHY NOT
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik McClure committed Jun 7, 2016
1 parent 74114c0 commit 8f92873
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
2 changes: 1 addition & 1 deletion main/config.json
Original file line number Diff line number Diff line change
@@ -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}}}
{"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}}}
63 changes: 61 additions & 2 deletions sweetiebot/bucket_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sweetiebot
import (
"github.com/bwmarrin/discordgo"
"strings"
"strconv"
"math/rand"
)

Expand All @@ -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)
}
Expand Down Expand Up @@ -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{} }
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"} }
17 changes: 16 additions & 1 deletion sweetiebot/sweetiebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8f92873

Please sign in to comment.