This commit is contained in:
alex 2019-06-28 18:54:32 +01:00
parent 3b9233307a
commit 62144ce8a1
4 changed files with 66 additions and 32 deletions

2
build Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
go build -o $HOME/go/bin/watbot main.go

View File

@ -21,7 +21,7 @@ func main() {
watConfig := wat.WatConfig{ watConfig := wat.WatConfig{
PermittedChannels: []string{ PermittedChannels: []string{
"##wat", "##wat",
//"##test", "##test",
"##sweden", "##sweden",
"##freedom", "##freedom",
}, },

View File

@ -111,15 +111,21 @@ func (w *WatDb) Act(player *Player, actionType ActionType) {
} }
func (w *WatDb) Strongest() []Player { func (w *WatDb) Strongest() []Player {
return w.GetTopColumn("anarchy")
}
func (w *WatDb) GetTopColumn(tipe string) []Player {
var user = make([]Player, 10) var user = make([]Player, 10)
w.db.Limit(10).Order("anarchy desc").Find(&user) w.db.Limit(10).Order(tipe + " desc").Find(&user)
return user return user
} }
func (w *WatDb) Healthiest() []Player {
return w.GetTopColumn("health")
}
func (w *WatDb) TopLost() []Player { func (w *WatDb) TopLost() []Player {
var user = make([]Player, 10) return w.GetTopColumn("coins_lost")
w.db.Limit(10).Order("coins_lost desc").Find(&user)
return user
} }
func (w *WatDb) TopTen() []Player { func (w *WatDb) TopTen() []Player {

View File

@ -18,6 +18,7 @@ type WatGame struct {
commands map[string](func(*Player, []string) string) commands map[string](func(*Player, []string) string)
aliases map[string](func(*Player, []string) string) aliases map[string](func(*Player, []string) string)
lifeCommands map[string](func(*Player, []string) string) lifeCommands map[string](func(*Player, []string) string)
simpleCommands []string
roid map[string]int roid map[string]int
} }
@ -26,7 +27,7 @@ var currencys = "watcoins"
var unconscious = "wat, your hands fumble and fail you. try resting, weakling." var unconscious = "wat, your hands fumble and fail you. try resting, weakling."
func NewWatGame(bot *WatBot, db *WatDb) *WatGame { func NewWatGame(bot *WatBot, db *WatDb) *WatGame {
g := WatGame{bot, db, Player{}, nil, nil, nil, map[string]int{}} g := WatGame{bot, db, Player{}, nil, nil, nil, nil, map[string]int{}}
g.me = g.db.User(bot.Nick, "tripsit/user/"+bot.Nick, true) g.me = g.db.User(bot.Nick, "tripsit/user/"+bot.Nick, true)
g.commands = map[string](func(*Player, []string) string){ g.commands = map[string](func(*Player, []string) string){
//"wat": g.megaWat, //"wat": g.megaWat,
@ -40,6 +41,7 @@ func NewWatGame(bot *WatBot, db *WatDb) *WatGame {
"dice": g.Dice, "dice": g.Dice,
"mine": g.Mine, "mine": g.Mine,
"bankrupt": g.Bankrupt, "bankrupt": g.Bankrupt,
"heal": g.Heal,
} }
g.aliases = map[string](func(*Player, []string) string){ g.aliases = map[string](func(*Player, []string) string){
"sleep": g.Rest, "sleep": g.Rest,
@ -48,11 +50,17 @@ func NewWatGame(bot *WatBot, db *WatDb) *WatGame {
g.lifeCommands = map[string](func(*Player, []string) string){ g.lifeCommands = map[string](func(*Player, []string) string){
"riot": g.Riot, "riot": g.Riot,
"bench": g.Bench, "bench": g.Bench,
"heal": g.Heal,
"steal": g.Steal, "steal": g.Steal,
"frame": g.Frame, "frame": g.Frame,
"punch": g.Punch, "punch": g.Punch,
} }
g.simpleCommands = []string{
"ping",
"strongest",
"healthiest",
"losers",
"richest",
}
return &g return &g
} }
@ -72,9 +80,11 @@ func (g *WatGame) Msg(m *irc.Message, player *Player, fields []string) {
reply = g.help() reply = g.help()
case "strongest": case "strongest":
reply = fmt.Sprintf("stronk: %s", g.Strongest()) reply = fmt.Sprintf("stronk: %s", g.Strongest())
case "toplost": case "healthiest":
reply = fmt.Sprintf("healthy: %s", g.Healthiest())
case "losers":
reply = fmt.Sprintf("%s losers: %s", currency, g.TopLost()) reply = fmt.Sprintf("%s losers: %s", currency, g.TopLost())
case "topten": case "richest":
reply = fmt.Sprintf("%s holders: %s", currency, g.TopTen()) reply = fmt.Sprintf("%s holders: %s", currency, g.TopTen())
case "source": case "source":
reply = "https://git.circuitco.de/self/watbot" reply = "https://git.circuitco.de/self/watbot"
@ -98,6 +108,7 @@ func (g *WatGame) help() string {
} }
ret += cmd ret += cmd
} }
ret += strings.Join(g.simpleCommands, ", ")
for cmd, _ := range g.lifeCommands { for cmd, _ := range g.lifeCommands {
if len(ret) > 0 { if len(ret) > 0 {
ret += ", " ret += ", "
@ -113,7 +124,7 @@ func (g *WatGame) RandInt(max int64) uint64 {
} }
func (g *WatGame) Heal(player *Player, fields []string) string { func (g *WatGame) Heal(player *Player, fields []string) string {
multiplier := int64(5) multiplier := int64(30)
if len(fields) < 3 { if len(fields) < 3 {
return "#heal <player> <coins> - sacrifice your money to me, peasant! i might heal someone!" return "#heal <player> <coins> - sacrifice your money to me, peasant! i might heal someone!"
} }
@ -177,24 +188,25 @@ func (g *WatGame) Int(str string) (uint64, error) {
func (g *WatGame) Roll(player *Player, fields []string) string { func (g *WatGame) Roll(player *Player, fields []string) string {
if len(fields) < 2 { if len(fields) < 2 {
return fmt.Sprintf("roll <%s> pls - u must score < 50 if u want 2 win", currency) return fmt.Sprintf("roll <%s> pls - u must score < 50 if u want 2 win. u can also pick the dice size", currency)
}
if player.Nick == "vlk" {
return "you've had enough rolling friend. unroll it."
} }
amount, e := g.Int(fields[1]) amount, e := g.Int(fields[1])
if e != nil { if e != nil {
return e.Error() return e.Error()
} }
dieSize := int64(100)
if len(fields) >= 3 {
userDieSize, e := g.Int(fields[2])
if e == nil && userDieSize >= 2 {
dieSize = int64(userDieSize)
}
}
if amount > player.Coins { if amount > player.Coins {
return "wat? brokeass" return "wat? brokeass"
} }
n := int64(g.RandInt(100)) + 1 n := int64(g.RandInt(dieSize)) + 1
ret := fmt.Sprintf("%s rolls the 100 sided die... %d! ", player.Nick, n) ret := fmt.Sprintf("%s rolls the %d sided die... %d! ", player.Nick, dieSize, n)
if player.Nick == "vlk" { if n < dieSize/2 {
n -= 5
}
if n < 50 {
player.Coins += amount player.Coins += amount
ret += fmt.Sprintf("You win! ◕ ◡ ◕ total: %d %s", player.Coins, currency) ret += fmt.Sprintf("You win! ◕ ◡ ◕ total: %d %s", player.Coins, currency)
} else { } else {
@ -387,9 +399,14 @@ func (g *WatGame) Rest(player *Player, fields []string) string {
ret = fmt.Sprintf("wat were you thinking, sleeping at a time like this (%d until next rest)", minRest-delta) ret = fmt.Sprintf("wat were you thinking, sleeping at a time like this (%d until next rest)", minRest-delta)
} else { } else {
value := g.RandInt(10) + 1 value := g.RandInt(10) + 1
ret = fmt.Sprintf("wat a nap - have back a random amount of hitpoints (this time it's %d)", value) if player.Health < -5 {
player.LastRested = time.Now().Unix() player.Health = 1
ret = fmt.Sprintf("wow ur beat up. i pity u, ur health is now 1.")
} else {
player.Health += int64(value) player.Health += int64(value)
ret = fmt.Sprintf("wat a nap - have back a random amount of hitpoints (this time it's %d, you've got %d hp)", value, player.Health)
}
player.LastRested = time.Now().Unix()
g.db.Update(player) g.db.Update(player)
} }
return ret return ret
@ -528,11 +545,11 @@ func (g *WatGame) Watch(player *Player, fields []string) string {
} }
player = maybePlayer player = maybePlayer
} }
return fmt.Sprintf("%s's Strength: %d (%d) / Trickery: %d (%d) / Coins: %d / Health: %d", player.Nick, player.Level(player.Anarchy), player.Anarchy, player.Trickery, player.Trickery, player.Coins, player.Health) return fmt.Sprintf("%s's Strength: %d (%d) / Coins: %d / Health: %d", player.Nick, player.Level(player.Anarchy), player.Anarchy, player.Coins, player.Health)
} }
func (g *WatGame) Balance(player *Player, fields []string) string { func (g *WatGame) Balance(player *Player, fields []string) string {
balStr := "%s's %s balance: %d. Mining time credit: %d. Total lost: %d." balStr := "%s's %s balance: %d. Mining time credit: %d. Total lost: %d. Bankrupt %d times."
balPlayer := player balPlayer := player
if len(fields) > 1 { if len(fields) > 1 {
var err string var err string
@ -541,7 +558,7 @@ func (g *WatGame) Balance(player *Player, fields []string) string {
return err return err
} }
} }
return fmt.Sprintf(balStr, balPlayer.Nick, currency, balPlayer.Coins, time.Now().Unix()-balPlayer.LastMined, balPlayer.CoinsLost) return fmt.Sprintf(balStr, balPlayer.Nick, currency, balPlayer.Coins, time.Now().Unix()-balPlayer.LastMined, balPlayer.CoinsLost, balPlayer.Bankrupcy)
} }
func (g *WatGame) Strongest() string { func (g *WatGame) Strongest() string {
@ -553,6 +570,15 @@ func (g *WatGame) Strongest() string {
return ret return ret
} }
func (g *WatGame) Healthiest() string {
players := g.db.Healthiest()
ret := ""
for _, p := range players {
ret += PrintTwo(p.Nick, uint64(p.Health))
}
return ret
}
func (g *WatGame) TopLost() string { func (g *WatGame) TopLost() string {
players := g.db.TopLost() players := g.db.TopLost()
ret := "" ret := ""