misc improvements
added self reference, allowing the bot to accrue currency messed about with some messages (removed swears, changed 'schlorped', etc) improved send output regular wattery to make 'wat' interesting
This commit is contained in:
parent
30d5e6f076
commit
2b1c9889e5
4
main.go
4
main.go
@ -1,15 +1,17 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
import "crypto/tls"
|
||||||
|
|
||||||
import "github.com/go-irc/irc"
|
import "github.com/go-irc/irc"
|
||||||
import "github.com/namsral/flag"
|
import "github.com/namsral/flag"
|
||||||
import "crypto/tls"
|
|
||||||
|
|
||||||
import "git.circuitco.de/self/watbot/wat"
|
import "git.circuitco.de/self/watbot/wat"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
pass := flag.String("pass", "", "password")
|
pass := flag.String("pass", "", "password")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
fmt.Printf("PASS len %d\n", len(*pass))
|
||||||
config := irc.ClientConfig {
|
config := irc.ClientConfig {
|
||||||
Nick: "watt",
|
Nick: "watt",
|
||||||
Pass: *pass,
|
Pass: *pass,
|
||||||
|
14
wat/bot.go
14
wat/bot.go
@ -35,7 +35,6 @@ func CleanNick(nick string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *WatBot) HandleIrcMsg(c *irc.Client, m *irc.Message) {
|
func (w *WatBot) HandleIrcMsg(c *irc.Client, m *irc.Message) {
|
||||||
fmt.Println(m)
|
|
||||||
switch cmd := m.Command; cmd {
|
switch cmd := m.Command; cmd {
|
||||||
case "PING":
|
case "PING":
|
||||||
w.write("PONG", m.Params[0])
|
w.write("PONG", m.Params[0])
|
||||||
@ -64,11 +63,12 @@ func (w *WatBot) Msg(m *irc.Message) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure there's actually some text to process
|
||||||
if len(m.Params[1]) == 0 {
|
if len(m.Params[1]) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fieldsfunc allows you to obtain rune separated fields/args
|
||||||
args := strings.FieldsFunc(m.Params[1], func(c rune) bool {return c == ' '})
|
args := strings.FieldsFunc(m.Params[1], func(c rune) bool {return c == ' '})
|
||||||
|
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
@ -76,9 +76,13 @@ func (w *WatBot) Msg(m *irc.Message) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if w.Admin(m) {
|
if w.Admin(m) {
|
||||||
// Do a special admin command and return, or continue
|
// allow impersonation of the robot from anywhere
|
||||||
if args[0] == "imp" && len(args) > 2 {
|
if args[0] == "imp" && len(args) > 2 {
|
||||||
w.write(args[1], args[2:]...)
|
if args[1] == "PRIVMSG" {
|
||||||
|
w.write(args[1], strings.Join(args[2:], " "))
|
||||||
|
} else {
|
||||||
|
w.write(args[1], args[2:]...)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,7 +112,7 @@ func (w *WatBot) Run() {
|
|||||||
defer w.conn.Close()
|
defer w.conn.Close()
|
||||||
err := w.client.Run()
|
err := w.client.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println("Error returned while running client: " + err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
54
wat/game.go
54
wat/game.go
@ -23,12 +23,13 @@ func NewWatGame(bot *WatBot, db *WatDb) *WatGame {
|
|||||||
g.commands = map[string](func(*Player,[]string)(string)) {
|
g.commands = map[string](func(*Player,[]string)(string)) {
|
||||||
"wat": g.megaWat,
|
"wat": g.megaWat,
|
||||||
"watch": g.Watch,
|
"watch": g.Watch,
|
||||||
"watcoin": g.Balance,
|
"coins": g.Balance,
|
||||||
"send": g.Send,
|
"send": g.Send,
|
||||||
"rest": g.Rest,
|
"rest": g.Rest,
|
||||||
"leech": g.Leech,
|
"leech": g.Leech,
|
||||||
"roll": g.Roll,
|
"roll": g.Roll,
|
||||||
"dice": g.Dice,
|
"dice": g.Dice,
|
||||||
|
"mine": g.Mine,
|
||||||
}
|
}
|
||||||
g.lifeCommands = map[string](func(*Player, []string)(string)) {
|
g.lifeCommands = map[string](func(*Player, []string)(string)) {
|
||||||
"steal": g.Steal,
|
"steal": g.Steal,
|
||||||
@ -53,6 +54,7 @@ func (g *WatGame) Msg(m *irc.Message, player *Player, fields []string) {
|
|||||||
if g.commands[fields[0]] != nil {
|
if g.commands[fields[0]] != nil {
|
||||||
reply = g.commands[fields[0]](player, fields)
|
reply = g.commands[fields[0]](player, fields)
|
||||||
} else {
|
} else {
|
||||||
|
// one liners
|
||||||
switch strings.ToLower(fields[0]) {
|
switch strings.ToLower(fields[0]) {
|
||||||
case "rules":
|
case "rules":
|
||||||
reply = rules
|
reply = rules
|
||||||
@ -60,12 +62,9 @@ func (g *WatGame) Msg(m *irc.Message, player *Player, fields []string) {
|
|||||||
reply = helpText
|
reply = helpText
|
||||||
case "topten":
|
case "topten":
|
||||||
reply = fmt.Sprintf("%s holders: %s", currency, g.TopTen())
|
reply = fmt.Sprintf("%s holders: %s", currency, g.TopTen())
|
||||||
case "mine":
|
|
||||||
reply = g.Mine(player)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if g.lifeCommands[fields[0]] != nil {
|
if g.lifeCommands[fields[0]] != nil {
|
||||||
// Nothing was handled. Maybe this is an action that requires consciousness.
|
|
||||||
if !player.Conscious() {
|
if !player.Conscious() {
|
||||||
reply = unconscious
|
reply = unconscious
|
||||||
} else {
|
} else {
|
||||||
@ -104,7 +103,7 @@ func (g *WatGame) Roll(player *Player, fields []string) string {
|
|||||||
}
|
}
|
||||||
amount, e := g.Int(fields[1])
|
amount, e := g.Int(fields[1])
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return "wat kinda numba is that"
|
return "wat kinda number is that"
|
||||||
}
|
}
|
||||||
if amount > player.Coins {
|
if amount > player.Coins {
|
||||||
return "wat? brokeass"
|
return "wat? brokeass"
|
||||||
@ -132,15 +131,17 @@ func (g *WatGame) Punch(player *Player, fields []string) string {
|
|||||||
}
|
}
|
||||||
chance := rand.Int63n(6)+1
|
chance := rand.Int63n(6)+1
|
||||||
dmg := rand.Int63n(6)+1
|
dmg := rand.Int63n(6)+1
|
||||||
ret := fmt.Sprintf("%s rolls a d6 to punch %s: It's a %d! %s ", player.Nick, target.Nick, chance, player.Nick)
|
ret := fmt.Sprintf("%s rolls a d6... %s ", player.Nick, player.Nick)
|
||||||
if chance <3 {
|
if chance > 3 {
|
||||||
dmg += player.Level(player.Anarchy)
|
dmg += player.Level(player.Anarchy)
|
||||||
ret += fmt.Sprintf("hits %s right in the torso for %d points of damage!", target.Nick, dmg)
|
ret += fmt.Sprintf("hits %s for %d points of damage!", target.Nick, dmg)
|
||||||
target.Health -= dmg
|
target.Health -= dmg
|
||||||
g.db.Update(target)
|
g.db.Update(target)
|
||||||
|
if target.Health <= 0 {
|
||||||
|
ret += target.Nick + " has fallen unconscious."
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
dmg += target.Anarchy
|
ret += fmt.Sprintf("fumbles, and punches themselves in confusion! %d self-damage. ", dmg)
|
||||||
ret += fmt.Sprintf("fumbles, and punches themselves in confusion! %d self-damage! ", dmg)
|
|
||||||
player.Health -= dmg
|
player.Health -= dmg
|
||||||
if player.Health <= 0 {
|
if player.Health <= 0 {
|
||||||
ret += player.Nick + " has fallen unconscious."
|
ret += player.Nick + " has fallen unconscious."
|
||||||
@ -174,7 +175,6 @@ func (g *WatGame) Frame(player *Player, fields []string) string {
|
|||||||
ret += fmt.Sprintf("You frame %s for a minor crime. They pay me %d.", target.Nick, amount)
|
ret += fmt.Sprintf("You frame %s for a minor crime. They pay me %d.", target.Nick, amount)
|
||||||
player.Anarchy += 1
|
player.Anarchy += 1
|
||||||
target.Coins -= amount
|
target.Coins -= amount
|
||||||
// bot gets coins
|
|
||||||
} else {
|
} else {
|
||||||
ret += fmt.Sprintf("You were caught and pay them %d. %s gets the rest.", (amount/2), g.bot.Nick)
|
ret += fmt.Sprintf("You were caught and pay them %d. %s gets the rest.", (amount/2), g.bot.Nick)
|
||||||
player.Coins -= amount
|
player.Coins -= amount
|
||||||
@ -203,19 +203,21 @@ func (g *WatGame) Steal(player *Player, fields []string) string {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if target.Coins < amount {
|
if target.Coins < amount {
|
||||||
return fmt.Sprintf("wat? %s is a poor fuck and doesn't have that much to steal.", target.Nick)
|
return fmt.Sprintf("wat? %s is poor and doesn't have that much to steal. (%d %s)", target.Nick, target.Coins, currency)
|
||||||
}
|
}
|
||||||
n := rand.Int63n(6)+1
|
n := rand.Int63n(6)+1
|
||||||
ret := fmt.Sprintf("%s is trying to steal %d %s from %s... ", player.Nick, amount, currency, target.Nick)
|
ret := fmt.Sprintf("%s is trying to steal %d %s from %s... ", player.Nick, amount, currency, target.Nick)
|
||||||
if n < 3 {
|
if n < 3 {
|
||||||
ret += "! You snuck it! Sneaky bastard!"
|
ret += "You did it! Sneaky bastard!"
|
||||||
player.Coins += amount
|
player.Coins += amount
|
||||||
player.Anarchy += 1
|
player.Anarchy += 1
|
||||||
target.Coins -= amount
|
target.Coins -= amount
|
||||||
g.db.Update(target)
|
g.db.Update(target)
|
||||||
} else {
|
} else {
|
||||||
ret += fmt.Sprintf("... You were caught and I took %d %s from your pocket.", (amount*2), currency)
|
ret += fmt.Sprintf("You were caught and I took %d %s from your pocket.", (amount*2), currency)
|
||||||
player.Coins -= amount*2
|
player.Coins -= amount*2
|
||||||
|
g.me.Coins += amount*2
|
||||||
|
g.db.Update(g.me)
|
||||||
}
|
}
|
||||||
g.db.Update(player)
|
g.db.Update(player)
|
||||||
return ret
|
return ret
|
||||||
@ -227,7 +229,7 @@ func (g *WatGame) GetTarget(player, target string) (*Player, string) {
|
|||||||
return nil, "Who? wat?"
|
return nil, "Who? wat?"
|
||||||
}
|
}
|
||||||
if t.Nick == player {
|
if t.Nick == player {
|
||||||
return nil, "You can't do that to yourself, dummy."
|
return nil, "You can't do that to yourself, silly."
|
||||||
}
|
}
|
||||||
return &t, ""
|
return &t, ""
|
||||||
}
|
}
|
||||||
@ -235,11 +237,11 @@ func (g *WatGame) GetTarget(player, target string) (*Player, string) {
|
|||||||
func (g *WatGame) Leech(player *Player, fields []string) string {
|
func (g *WatGame) Leech(player *Player, fields []string) string {
|
||||||
divisor := int64(10)
|
divisor := int64(10)
|
||||||
if len(fields) < 3 {
|
if len(fields) < 3 {
|
||||||
return fmt.Sprintf("leech <nick> <%s> - using your wealth, you steal the life force of another player. this will probably backfire and kill you.", currency)
|
return fmt.Sprintf("leech <nick> <%s> - using your wealth, you steal the life force of another player", currency)
|
||||||
}
|
}
|
||||||
amount, er := g.Int(fields[2])
|
amount, er := g.Int(fields[2])
|
||||||
if amount < divisor {
|
if amount < divisor {
|
||||||
return fmt.Sprintf("wat?? can't try to leech with less than %d %s, what do you think this is, free?", divisor, currency)
|
return fmt.Sprintf("wat? its %d %s for 1 hp", divisor, currency)
|
||||||
}
|
}
|
||||||
if player.Coins < amount || er != nil {
|
if player.Coins < amount || er != nil {
|
||||||
return "wat great fortune do you think you have? poor wats shouldn't be doing this, wat a waste..."
|
return "wat great fortune do you think you have? poor wats shouldn't be doing this, wat a waste..."
|
||||||
@ -255,7 +257,8 @@ func (g *WatGame) Leech(player *Player, fields []string) string {
|
|||||||
if r < 5 {
|
if r < 5 {
|
||||||
target.Health -= hpDown
|
target.Health -= hpDown
|
||||||
player.Health += hpDown
|
player.Health += hpDown
|
||||||
reply += fmt.Sprintf("The deal is done, you schlorped %d HP from %s. They now have %d HP, you have %d.", hpDown, target.Nick, target.Health, player.Health)
|
player.Anarchy += 1
|
||||||
|
reply += fmt.Sprintf("The deal is done, you took %d HP from %s. They now have %d HP, you have %d.", hpDown, target.Nick, target.Health, player.Health)
|
||||||
} else {
|
} else {
|
||||||
reply += "The gods do not smile upon you this waturday. Your money vanishes and nothing happens."
|
reply += "The gods do not smile upon you this waturday. Your money vanishes and nothing happens."
|
||||||
}
|
}
|
||||||
@ -263,7 +266,7 @@ func (g *WatGame) Leech(player *Player, fields []string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *WatGame) Rest(player *Player, fields []string) string {
|
func (g *WatGame) Rest(player *Player, fields []string) string {
|
||||||
minRest := int64(86400)
|
minRest := int64(43200)
|
||||||
delta := time.Now().Unix() - player.LastRested
|
delta := time.Now().Unix() - player.LastRested
|
||||||
ret := ""
|
ret := ""
|
||||||
if player.LastRested == 0 {
|
if player.LastRested == 0 {
|
||||||
@ -272,7 +275,7 @@ func (g *WatGame) Rest(player *Player, fields []string) string {
|
|||||||
} else if delta < minRest {
|
} else if delta < minRest {
|
||||||
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 := rand.Int63n(20)+1
|
value := rand.Int63n(10)+1
|
||||||
ret = fmt.Sprintf("wat a nap - have back a random amount of hitpoints (this time it's %d)", value)
|
ret = fmt.Sprintf("wat a nap - have back a random amount of hitpoints (this time it's %d)", value)
|
||||||
}
|
}
|
||||||
player.LastRested = time.Now().Unix()
|
player.LastRested = time.Now().Unix()
|
||||||
@ -294,7 +297,7 @@ func (g *WatGame) Send(player *Player, fields []string) string {
|
|||||||
return fields[2] + " is not an integer, wat?"
|
return fields[2] + " is not an integer, wat?"
|
||||||
}
|
}
|
||||||
if int64(amount) > player.Coins {
|
if int64(amount) > player.Coins {
|
||||||
return "wat? you poor fuck, you don't have enough!"
|
return "wat? you're too poor!"
|
||||||
}
|
}
|
||||||
target, str := g.GetTarget(player.Nick, fields[1])
|
target, str := g.GetTarget(player.Nick, fields[1])
|
||||||
if target == nil {
|
if target == nil {
|
||||||
@ -304,10 +307,10 @@ func (g *WatGame) Send(player *Player, fields []string) string {
|
|||||||
target.Coins += int64(amount)
|
target.Coins += int64(amount)
|
||||||
g.db.Update(player)
|
g.db.Update(player)
|
||||||
g.db.Update(target)
|
g.db.Update(target)
|
||||||
return fmt.Sprintf("%s sent %s %d %s", player.Nick, target.Nick, amount, currency)
|
return fmt.Sprintf("%s sent %s %d %s has %d watcoin, %s has %d watcoin ", player.Nick, target.Nick, amount, currency, player.Nick, player.Coins, target.Nick, target.Coins)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *WatGame) Mine(player *Player) string {
|
func (g *WatGame) Mine(player *Player, _ []string) string {
|
||||||
delta := time.Now().Unix() - player.LastMined
|
delta := time.Now().Unix() - player.LastMined
|
||||||
if delta < 1800 {
|
if delta < 1800 {
|
||||||
return fmt.Sprintf("wat? 2 soon (%d)", delta)
|
return fmt.Sprintf("wat? 2 soon (%d)", delta)
|
||||||
@ -375,6 +378,7 @@ func PrintTwo(nick string, value int64) string {
|
|||||||
func (g *WatGame) megaWat(player *Player, _ []string) string {
|
func (g *WatGame) megaWat(player *Player, _ []string) string {
|
||||||
mega := rand.Int63n(1000000)+1
|
mega := rand.Int63n(1000000)+1
|
||||||
kilo := rand.Int63n(1000)+1
|
kilo := rand.Int63n(1000)+1
|
||||||
|
ten := rand.Int63n(10)+1
|
||||||
reply := ""
|
reply := ""
|
||||||
if mega == 23 {
|
if mega == 23 {
|
||||||
player.Coins += 1000000
|
player.Coins += 1000000
|
||||||
@ -384,6 +388,10 @@ func (g *WatGame) megaWat(player *Player, _ []string) string {
|
|||||||
player.Coins += 1000
|
player.Coins += 1000
|
||||||
reply = fmt.Sprintf("OMGWAT! %s has won the KiloWat lottery and gains 1000 %s!", player.Nick, currency)
|
reply = fmt.Sprintf("OMGWAT! %s has won the KiloWat lottery and gains 1000 %s!", player.Nick, currency)
|
||||||
}
|
}
|
||||||
|
if ten == 10 {
|
||||||
|
player.Coins += 10
|
||||||
|
reply = fmt.Sprintf("%s won the regular wattery. This one only pays 10 %s.", player.Nick, currency)
|
||||||
|
}
|
||||||
player.Watting += 1
|
player.Watting += 1
|
||||||
g.db.Update(player)
|
g.db.Update(player)
|
||||||
return reply
|
return reply
|
||||||
|
Loading…
Reference in New Issue
Block a user