Implement Jeopardy cashout
This adds integration between Watbot and the Limnoria Jeopardy plugin. If a game of Jeopardy ends, Watbot will parse the finishers message and pay a small share of the Jeopardy price money in the form of Watcoins. To avoid abuse, only Jeopardy finishing messages from authorized bots are considered. An IRC user is considered an authorized bot if the hostmask matches one of the configured bot hostmasks, and if the nickname is configured for "jeopardy" in the newly introduced bot games configuration. Signed-off-by: Georg Pfuetzenreuter <mail@georg-pfuetzenreuter.net>
This commit is contained in:
parent
9e9347ade7
commit
b7f2ad6dcd
@ -6,6 +6,12 @@ watbot:
|
|||||||
name: watest
|
name: watest
|
||||||
nick: watest # nick is name by default
|
nick: watest # nick is name by default
|
||||||
user: watest # user is nick by default
|
user: watest # user is nick by default
|
||||||
|
bots: # optional, no default
|
||||||
|
games: # mapping of bot names to games
|
||||||
|
katyusha:
|
||||||
|
- jeopardy # currently jeopardy is the only integrated game
|
||||||
|
hosts: # hostmasks considered as valid bots
|
||||||
|
- bot.example.com
|
||||||
admins: # optional, no default
|
admins: # optional, no default
|
||||||
hosts:
|
hosts:
|
||||||
- admin.example.com
|
- admin.example.com
|
||||||
|
6
main.go
6
main.go
@ -24,6 +24,10 @@ type watConfig struct {
|
|||||||
Pass string `yaml:"pass"`
|
Pass string `yaml:"pass"`
|
||||||
User string `yaml:"user"`
|
User string `yaml:"user"`
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name"`
|
||||||
|
Bots struct {
|
||||||
|
Hosts []string `yaml:"hosts"`
|
||||||
|
Games wat.BotGameConfig `yaml:"games"`
|
||||||
|
} `yaml:"bots"`
|
||||||
Admins struct {
|
Admins struct {
|
||||||
Hosts []string `yaml:"hosts"`
|
Hosts []string `yaml:"hosts"`
|
||||||
} `yaml:"admins"`
|
} `yaml:"admins"`
|
||||||
@ -99,6 +103,8 @@ func main() {
|
|||||||
PermittedChannels: config.Channels.Permitted,
|
PermittedChannels: config.Channels.Permitted,
|
||||||
IgnoredHosts: config.Ignores.Hosts,
|
IgnoredHosts: config.Ignores.Hosts,
|
||||||
AdminHosts: config.Admins.Hosts,
|
AdminHosts: config.Admins.Hosts,
|
||||||
|
BotHosts: config.Bots.Hosts,
|
||||||
|
BotGames: config.Bots.Games,
|
||||||
}
|
}
|
||||||
tcpConf := &tls.Config{
|
tcpConf := &tls.Config{
|
||||||
InsecureSkipVerify: !config.Server.TlsVerify,
|
InsecureSkipVerify: !config.Server.TlsVerify,
|
||||||
|
61
wat/bot.go
61
wat/bot.go
@ -3,6 +3,7 @@ package wat
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-irc/irc"
|
"github.com/go-irc/irc"
|
||||||
@ -17,7 +18,16 @@ type WatBot struct {
|
|||||||
Nick string
|
Nick string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type BotGame struct {
|
||||||
|
Games []string
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
|
type BotGameConfig map[string][]string
|
||||||
|
|
||||||
type WatConfig struct {
|
type WatConfig struct {
|
||||||
|
BotHosts []string
|
||||||
|
BotGames BotGameConfig
|
||||||
AdminHosts []string
|
AdminHosts []string
|
||||||
IgnoredHosts []string
|
IgnoredHosts []string
|
||||||
AutoJoinChannels []string
|
AutoJoinChannels []string
|
||||||
@ -62,6 +72,20 @@ func (w *WatBot) Admin(m *irc.Message) bool {
|
|||||||
return w.Allowed(m.Prefix.Host, w.c.AdminHosts)
|
return w.Allowed(m.Prefix.Host, w.c.AdminHosts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *WatBot) Bot(m *irc.Message) (bool, []string) {
|
||||||
|
isBot := w.Allowed(m.Prefix.Host, w.c.BotHosts)
|
||||||
|
var games []string
|
||||||
|
if isBot {
|
||||||
|
for b, g := range w.c.BotGames {
|
||||||
|
if b == m.Prefix.Name {
|
||||||
|
games = g
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return isBot, games
|
||||||
|
}
|
||||||
|
|
||||||
func (w *WatBot) Allowed(c string, r []string) bool {
|
func (w *WatBot) Allowed(c string, r []string) bool {
|
||||||
for _, allowed := range r {
|
for _, allowed := range r {
|
||||||
if c == allowed {
|
if c == allowed {
|
||||||
@ -123,6 +147,43 @@ func (w *WatBot) Msg(m *irc.Message) {
|
|||||||
args = args[1:]
|
args = args[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// integration with games in other bots
|
||||||
|
isBot, games := w.Bot(m)
|
||||||
|
if isBot {
|
||||||
|
// Jeopardy
|
||||||
|
if args[0] == "Top" && args[1] == "finishers:" && w.Allowed("jeopardy", games) {
|
||||||
|
// hey, I avoided regex!
|
||||||
|
finisherPrizes := strings.Split(strings.Replace(strings.Replace(strings.Replace(strings.Replace(strings.Join(args[2:], " "), ") (", ";", -1), ": ", ":", -1), "(", "", 1), ")", "", 1), ";")
|
||||||
|
fmt.Printf("Processing Jeopardy: %s\n", finisherPrizes)
|
||||||
|
for _, pair := range finisherPrizes {
|
||||||
|
nameCoinPair := strings.Split(pair, ":")
|
||||||
|
coins, err := strconv.ParseUint(nameCoinPair[1], 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Invalid coins, cannot process pair for cashout: %s.\n", nameCoinPair)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
name := nameCoinPair[0]
|
||||||
|
// Jeopardy prizes are quite a lot of $$$, make it a bit more sane
|
||||||
|
coins = coins / 40
|
||||||
|
// name = we assume the Jeopardy player name to match a Watbot player name
|
||||||
|
// host = we could use some WHO logic to find the host, but assuming nickname lookup to be sufficient here
|
||||||
|
// create = based on the above, maybe rather not create Watbot players based on only a nick?
|
||||||
|
// but it expects someone to have played with Watbot before to be eligible for Jeopardy cashout ..
|
||||||
|
player := w.Db.User(name, "", false)
|
||||||
|
if player.Nick == "" {
|
||||||
|
fmt.Printf("Player %s does not exist in Watbot, skipping cashout.\n", name)
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
w.reply(m, fmt.Sprintf("smartass %s, gave u %d :)", player.Nick, coins))
|
||||||
|
player.Coins += coins
|
||||||
|
w.Db.Update(player)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// check if command char (or something weird) is present
|
// check if command char (or something weird) is present
|
||||||
if args[0] != "wat" && args[0][0] != '#' {
|
if args[0] != "wat" && args[0][0] != '#' {
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user