67 lines
1.3 KiB
Go
67 lines
1.3 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"git.massivebox.net/massivebox/go-catprinter"
|
||
|
"github.com/go-telegram-bot-api/telegram-bot-api/v5"
|
||
|
"log"
|
||
|
)
|
||
|
|
||
|
type Context struct {
|
||
|
Settings *Settings
|
||
|
Bot *tgbotapi.BotAPI
|
||
|
Client *catprinter.Client
|
||
|
Queue JobChan
|
||
|
Next NextChan
|
||
|
Projects map[int]*Project
|
||
|
PassedPasswordCheck []int64
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
|
||
|
log.Println("Starting...")
|
||
|
|
||
|
s := getSettings()
|
||
|
|
||
|
c, err := catprinter.NewClient()
|
||
|
if err != nil {
|
||
|
log.Fatalln("Error creating client", err)
|
||
|
}
|
||
|
|
||
|
log.Println("Connecting to printer...")
|
||
|
err = c.Connect(s.Mac)
|
||
|
if err != nil {
|
||
|
log.Fatalln("Error connecting to printer", err)
|
||
|
}
|
||
|
|
||
|
bot, err := tgbotapi.NewBotAPI(s.BotToken)
|
||
|
if err != nil {
|
||
|
log.Fatalln("Error creating bot API client", err)
|
||
|
}
|
||
|
|
||
|
u := tgbotapi.NewUpdate(0)
|
||
|
u.Timeout = 60
|
||
|
updates := bot.GetUpdatesChan(u)
|
||
|
|
||
|
c.Debug.DontPrint = s.DontPrint
|
||
|
|
||
|
ctx := &Context{
|
||
|
Settings: &s,
|
||
|
Bot: bot,
|
||
|
Client: c,
|
||
|
Queue: make(JobChan, s.MaxQueueLength),
|
||
|
Next: make(NextChan),
|
||
|
Projects: make(map[int]*Project),
|
||
|
PassedPasswordCheck: make([]int64, 0),
|
||
|
}
|
||
|
|
||
|
log.Println("Startup done. " +
|
||
|
"Listening for updates...")
|
||
|
|
||
|
go ctx.listenJobChannel()
|
||
|
|
||
|
for update := range updates {
|
||
|
go ctx.handleUpdate(update)
|
||
|
}
|
||
|
|
||
|
}
|