This repository has been archived on 2023-07-05. You can view files and clone it, but cannot push or open issues or pull requests.
clessy/stats/main.go

47 lines
944 B
Go

package main
import (
"flag"
"github.com/boltdb/bolt"
"github.com/hamcha/clessy/tg"
)
func assert(err error) {
if err != nil {
panic(err)
}
}
var db *bolt.DB
var chatID *int64
func process(broker *tg.Broker, update tg.APIMessage) {
// Process messages from marked chat only
if update.Chat.ChatID != *chatID {
return
}
getNick(update.User)
updateStats(update)
}
func main() {
brokerAddr := flag.String("broker", "localhost:7314", "Broker address:port")
webBind := flag.String("webserver", "localhost:7315", "Address to bind webserver to")
boltdbFile := flag.String("boltdb", "stats.db", "BoltDB database file")
chatID = flag.Int64("chatid", -14625256, "Telegram Chat ID to count stats for")
flag.Parse()
var err error
db, err = bolt.Open(*boltdbFile, 0600, nil)
assert(err)
defer db.Close()
loadUsers()
loadStats()
go startWebServer(*webBind)
err = tg.CreateBrokerClient(*brokerAddr, process)
assert(err)
}