mirror of https://github.com/velour/catbase.git
Added mgo dependencies, basis for database access among modules
This commit is contained in:
parent
4b9b8fa682
commit
e1c841ecae
15
bot/bot.go
15
bot/bot.go
|
@ -1,6 +1,8 @@
|
|||
package bot
|
||||
|
||||
import irc "github.com/fluffle/goirc/client"
|
||||
import "labix.org/v2/mgo"
|
||||
import "godeepintir/config"
|
||||
|
||||
// Bot type provides storage for bot-wide information, configs, and database connections
|
||||
type Bot struct {
|
||||
|
@ -8,6 +10,8 @@ type Bot struct {
|
|||
Users []User
|
||||
Conn *irc.Conn
|
||||
// mongodb connection will go here
|
||||
DbSession *mgo.Session
|
||||
Db *mgo.Database
|
||||
}
|
||||
|
||||
// User type stores user history. This is a vehicle that will follow the user for the active
|
||||
|
@ -27,11 +31,20 @@ type User struct {
|
|||
|
||||
// NewBot creates a Bot for a given connection and set of handlers. The handlers must not
|
||||
// require the bot as input for their creation (so use AddHandler instead to add handlers)
|
||||
func NewBot(c *irc.Conn, p ...Handler) *Bot {
|
||||
func NewBot(config *config.Config, c *irc.Conn, p ...Handler) *Bot {
|
||||
session, err := mgo.Dial(config.DbServer)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
db := session.DB(config.DbName)
|
||||
|
||||
return &Bot{
|
||||
Plugins: p,
|
||||
Users: make([]User, 10),
|
||||
Conn: c,
|
||||
DbSession: session,
|
||||
Db: db,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ import "io/ioutil"
|
|||
// Config stores any system-wide startup information that cannot be easily configured via
|
||||
// the database
|
||||
type Config struct {
|
||||
Dbname string
|
||||
Dbserver string
|
||||
DbName string
|
||||
DbServer string
|
||||
Channels []string
|
||||
Plugins []string
|
||||
Nick, Server, Pass string
|
||||
|
|
4
main.go
4
main.go
|
@ -3,8 +3,8 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"godeepintir/config"
|
||||
"godeepintir/bot"
|
||||
"godeepintir/config"
|
||||
"godeepintir/plugins"
|
||||
)
|
||||
import irc "github.com/fluffle/goirc/client"
|
||||
|
@ -41,7 +41,7 @@ func main() {
|
|||
c.AddHandler("disconnected",
|
||||
func(conn *irc.Conn, line *irc.Line) { quit <- true })
|
||||
|
||||
b := bot.NewBot(c)
|
||||
b := bot.NewBot(config, c)
|
||||
b.AddHandler(plugins.NewTestPlugin(b))
|
||||
|
||||
c.AddHandler("PRIVMSG", func(conn *irc.Conn, line *irc.Line) {
|
||||
|
|
Loading…
Reference in New Issue