initial commit
This commit is contained in:
parent
85ff6578e8
commit
379891b2d0
10
go.mod
Normal file
10
go.mod
Normal file
@ -0,0 +1,10 @@
|
||||
module git.circuitco.de/self/watbot
|
||||
|
||||
go 1.15
|
||||
|
||||
require (
|
||||
github.com/go-irc/irc v2.1.0+incompatible
|
||||
github.com/namsral/flag v1.7.4-pre
|
||||
gorm.io/driver/sqlite v1.1.4
|
||||
gorm.io/gorm v1.20.11
|
||||
)
|
16
go.sum
Normal file
16
go.sum
Normal file
@ -0,0 +1,16 @@
|
||||
github.com/go-irc/irc v1.3.0 h1:IMD+d/+EzY51ecMLOz73r/NXTZrEp8khrePxRCvX71M=
|
||||
github.com/go-irc/irc v2.1.0+incompatible h1:pg7pMVq5OYQbqTxceByD/EN8VIsba7DtKn49rsCnG8Y=
|
||||
github.com/go-irc/irc v2.1.0+incompatible/go.mod h1:jJILTRy8s/qOvusiKifAEfhQMVwft1ZwQaVJnnzmyX4=
|
||||
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
|
||||
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
|
||||
github.com/jinzhu/now v1.1.1 h1:g39TucaRWyV3dwDO++eEc6qf8TVIQ/Da48WmqjZ3i7E=
|
||||
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/mattn/go-sqlite3 v1.14.5 h1:1IdxlwTNazvbKJQSxoJ5/9ECbEeaTTyeU7sEAZ5KKTQ=
|
||||
github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI=
|
||||
github.com/namsral/flag v1.7.4-pre h1:b2ScHhoCUkbsq0d2C15Mv+VU8bl8hAXV8arnWiOHNZs=
|
||||
github.com/namsral/flag v1.7.4-pre/go.mod h1:OXldTctbM6SWH1K899kPZcf65KxJiD7MsceFUpB5yDo=
|
||||
gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM=
|
||||
gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw=
|
||||
gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
|
||||
gorm.io/gorm v1.20.11 h1:jYHQ0LLUViV85V8dM1TP9VBBkfzKTnuTXDjYObkI6yc=
|
||||
gorm.io/gorm v1.20.11/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
|
10
main.go
10
main.go
@ -15,15 +15,13 @@ func main() {
|
||||
config := irc.ClientConfig{
|
||||
Nick: "watt",
|
||||
Pass: *pass,
|
||||
User: "wat/tripsit",
|
||||
User: "wat",
|
||||
Name: "wat",
|
||||
}
|
||||
watConfig := wat.WatConfig{
|
||||
PermittedChannels: []string{
|
||||
"##wat",
|
||||
"##test",
|
||||
"##sweden",
|
||||
"##freedom",
|
||||
"#lucy",
|
||||
"#sweden",
|
||||
},
|
||||
IgnoredHosts: []string{
|
||||
"tripsit/user/creatonez",
|
||||
@ -32,7 +30,7 @@ func main() {
|
||||
tcpConf := &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
conn, err := tls.Dial("tcp", "127.0.0.1:9696", tcpConf)
|
||||
conn, err := tls.Dial("tcp", "127.0.0.1:6697", tcpConf)
|
||||
if err != nil {
|
||||
fmt.Println("err " + err.Error())
|
||||
return
|
||||
|
@ -45,7 +45,7 @@ func (w *WatBot) HandleIrcMsg(c *irc.Client, m *irc.Message) {
|
||||
}
|
||||
|
||||
func (w *WatBot) Admin(m *irc.Message) bool {
|
||||
return m.Prefix.Host == "tripsit/operator/hibs"
|
||||
return m.Prefix.Host == "mph.monster"
|
||||
}
|
||||
|
||||
func (w *WatBot) Allowed(c string, r []string) bool {
|
||||
@ -64,9 +64,9 @@ func (w *WatBot) CanRespond(m *irc.Message) bool {
|
||||
if w.Allowed(m.Prefix.Host, w.c.IgnoredHosts) {
|
||||
return false
|
||||
}
|
||||
if !strings.Contains(m.Prefix.Host, "tripsit") {
|
||||
return false
|
||||
}
|
||||
// if !strings.Contains(m.Prefix.Host, "") {
|
||||
// return false
|
||||
// }
|
||||
if !w.Allowed(m.Params[0], w.c.PermittedChannels) {
|
||||
return false
|
||||
}
|
||||
|
14
wat/db.go
14
wat/db.go
@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/driver/sqlite"
|
||||
)
|
||||
|
||||
type Player struct {
|
||||
@ -15,7 +15,7 @@ type Player struct {
|
||||
Watting int64
|
||||
Anarchy int64
|
||||
Trickery int64
|
||||
Coins uint64 `gorm:"default:'100'"`
|
||||
Coins uint64 `gorm:"default:100"`
|
||||
Health int64
|
||||
LastMined int64
|
||||
LastRested int64
|
||||
@ -54,12 +54,12 @@ type WatDb struct {
|
||||
|
||||
func NewWatDb() *WatDb {
|
||||
w := WatDb{}
|
||||
var err error
|
||||
w.db, err = gorm.Open("sqlite3", "wat.db")
|
||||
var err error
|
||||
w.db, err = gorm.Open(sqlite.Open("wat.db"), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
w.db.AutoMigrate(&Action{}, &Player{})
|
||||
w.db.AutoMigrate(&Action{}, &Player{})
|
||||
return &w
|
||||
}
|
||||
|
||||
@ -102,7 +102,7 @@ func (w *WatDb) LastActed(player *Player, actionType ActionType) int64 {
|
||||
|
||||
func (w *WatDb) Act(player *Player, actionType ActionType) {
|
||||
action := Action{player.Model.ID, actionType, time.Now().Unix()}
|
||||
if w.db.First(&action, "type = ? AND player_id = ?", actionType, player.ID).RecordNotFound() {
|
||||
if err := w.db.First(&action, "type = ? AND player_id = ?", actionType, player.Model.ID).Error; err != nil {
|
||||
w.db.Create(&action)
|
||||
} else {
|
||||
action.Performed = time.Now().Unix()
|
||||
|
@ -28,7 +28,7 @@ var unconscious = "wat, your hands fumble and fail you. try resting, weakling."
|
||||
|
||||
func NewWatGame(bot *WatBot, db *WatDb) *WatGame {
|
||||
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, "amia8t89xfp8y.liberta.casa", true)
|
||||
g.commands = map[string](func(*Player, []string) string){
|
||||
//"wat": g.megaWat,
|
||||
"steroid": g.Steroid,
|
||||
|
Loading…
Reference in New Issue
Block a user