2018-08-14 09:25:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-09-17 16:35:48 +00:00
|
|
|
"encoding/gob"
|
2018-09-19 09:26:36 +00:00
|
|
|
"errors"
|
2018-09-19 12:23:39 +00:00
|
|
|
"flag"
|
2018-08-14 09:25:34 +00:00
|
|
|
"log"
|
2018-09-19 09:26:36 +00:00
|
|
|
"os"
|
|
|
|
"path"
|
2018-08-14 09:25:34 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2018-09-20 17:14:08 +00:00
|
|
|
"git.trj.tw/golang/mtfosbot/module/apis/twitch"
|
2018-09-19 14:06:27 +00:00
|
|
|
"git.trj.tw/golang/mtfosbot/module/cmd"
|
2018-09-19 12:23:39 +00:00
|
|
|
"git.trj.tw/golang/mtfosbot/module/options"
|
2018-09-19 09:26:36 +00:00
|
|
|
"git.trj.tw/golang/mtfosbot/module/utils"
|
|
|
|
|
2018-08-14 09:25:34 +00:00
|
|
|
"git.trj.tw/golang/mtfosbot/model"
|
2018-09-10 10:13:27 +00:00
|
|
|
"git.trj.tw/golang/mtfosbot/module/background"
|
2018-08-22 09:20:12 +00:00
|
|
|
"git.trj.tw/golang/mtfosbot/module/config"
|
2018-09-13 10:18:59 +00:00
|
|
|
twitchirc "git.trj.tw/golang/mtfosbot/module/twitch-irc"
|
2018-08-14 09:25:34 +00:00
|
|
|
"git.trj.tw/golang/mtfosbot/router/routes"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
var server *gin.Engine
|
|
|
|
|
2018-09-19 12:23:39 +00:00
|
|
|
func init() {
|
|
|
|
options.RegFlag()
|
|
|
|
flag.Parse()
|
|
|
|
}
|
|
|
|
|
2018-08-14 09:25:34 +00:00
|
|
|
func main() {
|
2018-09-19 12:23:39 +00:00
|
|
|
runOptions := options.GetFlag()
|
|
|
|
|
|
|
|
if runOptions.Help {
|
|
|
|
flag.Usage()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
err := config.LoadConfig(runOptions.Config)
|
2018-08-22 09:20:12 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
2018-08-14 09:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// connect to database
|
2018-08-28 03:55:38 +00:00
|
|
|
db, err := model.NewDB()
|
2018-08-14 09:25:34 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2018-08-28 03:55:38 +00:00
|
|
|
defer db.Close()
|
2018-08-14 09:25:34 +00:00
|
|
|
|
2018-09-19 14:06:27 +00:00
|
|
|
if runOptions.DBTool {
|
|
|
|
cmd.DBTool()
|
|
|
|
}
|
|
|
|
|
|
|
|
registerTypes()
|
|
|
|
background.SetBackground()
|
|
|
|
|
|
|
|
// create http server
|
|
|
|
server = routes.NewServ()
|
|
|
|
routes.SetRoutes(server)
|
|
|
|
|
2018-09-15 15:48:40 +00:00
|
|
|
go twitchirc.InitIRC()
|
2018-09-13 10:18:59 +00:00
|
|
|
|
2018-09-19 09:26:36 +00:00
|
|
|
// create thumbnail directory
|
|
|
|
conf := config.GetConf()
|
|
|
|
if !utils.CheckExists(conf.ImageRoot, true) {
|
|
|
|
log.Fatal(errors.New("image root not exists"))
|
|
|
|
}
|
|
|
|
if !utils.CheckExists(path.Join(conf.ImageRoot, "thumbnail"), true) {
|
|
|
|
err = os.MkdirAll(path.Join(conf.ImageRoot, "thumbnail"), 0775)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
2018-10-01 16:11:32 +00:00
|
|
|
if !utils.CheckExists(conf.LogImageRoot, true) {
|
|
|
|
log.Fatal(errors.New("log image root not exists"))
|
|
|
|
}
|
2018-09-19 09:26:36 +00:00
|
|
|
|
2018-08-22 09:20:12 +00:00
|
|
|
server.Run(strings.Join([]string{":", strconv.Itoa(config.GetConf().Port)}, ""))
|
2018-08-14 09:25:34 +00:00
|
|
|
}
|
2018-09-17 16:35:48 +00:00
|
|
|
|
|
|
|
func registerTypes() {
|
|
|
|
gob.Register(model.Account{})
|
|
|
|
gob.Register(model.Commands{})
|
|
|
|
gob.Register(model.DonateSetting{})
|
|
|
|
gob.Register(model.FacebookPage{})
|
|
|
|
gob.Register(model.KeyCommands{})
|
|
|
|
gob.Register(model.LineGroup{})
|
|
|
|
gob.Register(model.LineMessageLog{})
|
|
|
|
gob.Register(model.LineUser{})
|
|
|
|
gob.Register(model.OpayDonateList{})
|
|
|
|
gob.Register(model.TwitchChannel{})
|
|
|
|
gob.Register(model.YoutubeChannel{})
|
2018-09-20 17:14:08 +00:00
|
|
|
gob.Register(twitch.TwitchTokenData{})
|
|
|
|
gob.Register(twitch.UserInfo{})
|
2018-09-17 16:35:48 +00:00
|
|
|
gob.Register(map[string]interface{}{})
|
|
|
|
}
|