Exemple #1
0
func main() {

	api := new(Api.Api)
	bot := new(IrcBot.Bot)
	dbase, _ := Db.NewDb()
	if _util == nil {
		_util = new(util.ConfImg)
	}
	conf.Fill(api)
	conf.Fill(bot)
	conf.Fill(_util)
	go api.Run()
	go bot.Run()

	bot.LinkChannel = make(chan IrcBot.Link)
	bot.DeleteImage = make(chan int64)
	bot.SendChannel = make(chan IrcBot.Send)
	go ircLoop(bot)
	for {
		select {
		case link := <-bot.LinkChannel:
			saveImage(link, dbase, bot)
		case id := <-bot.DeleteImage:
			dbase.DeleteImage(id)
			// TODO: delete images from harddrive
		}
	}
}
Exemple #2
0
func NewDb() (*Db, error) {
	var err error
	// singleton
	if _db == nil {
		_db = new(Db)
	}
	// get config
	tmpConf := new(DbConfig)
	conf.Fill(tmpConf)

	// set values from config.json
	_db.DbEngine = tmpConf.DbEngine
	_db.DbFile = tmpConf.DbFile
	_db.DbImageTable = tmpConf.TblImages

	// open connection, and create tables if needed.
	_db.conn, err = sql.Open(_db.DbEngine, _db.DbFile /*+":locked.sqlite?chache=shared&mode=rwc"*/)
	if err != nil {
		log.Printf("Db.NewDb: Failed to open %s via driver: %s. Error: %s\n", _db.DbFile, _db.DbEngine, err.Error())
		return nil, err
	}
	result, err := _db.tblImagesSetup() // setup image table
	if err != nil {
		log.Printf("Db.NewDb: %s\n", err.Error())
		return nil, err
	}
	if result != true {
		err = errors.New("Could not create table " + _db.DbImageTable)
		log.Printf("Db.NewDb: %s\n", err.Error())
		return nil, err
	}

	// setup other tables if needed.
	return _db, nil
}
Exemple #3
0
func init() {
	if _api == nil {
		_api = new(Api)
	}
	// conf foo here
	tmpApi := new(Api)
	conf.Fill(tmpApi)
	_api.Addr = tmpApi.Addr

}
Exemple #4
0
func init() {
	if _img == nil {
		_img = new(ConfImg)
	}
	tmpConf := new(ConfImg)
	conf.Fill(tmpConf)

	_img.Imagepath = tmpConf.Imagepath
	_img.Thumbpath = tmpConf.Thumbpath
}
Exemple #5
0
// If shit's broken this is probably the reason for it.
func init() {
	if _bot == nil {
		_bot = new(Bot)
	}
	tmpBot := new(Bot)
	conf.Fill(tmpBot)
	_bot.Nickname = tmpBot.Nickname
	_bot.Realname = tmpBot.Realname
	_bot.Connections = tmpBot.Connections
}
Exemple #6
0
func init() {
	if _util == nil {
		_util = new(ConfImg)
	}
	tmpConf := new(ConfImg)
	conf.Fill(tmpConf)

	_util.Imagepath = tmpConf.Imagepath
	_util.Thumbpath = tmpConf.Thumbpath
}