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

48 lines
944 B
Go
Raw Normal View History

2016-02-09 15:00:50 +00:00
package main
import (
"flag"
2016-02-10 14:31:53 +00:00
"github.com/boltdb/bolt"
2016-02-09 15:00:50 +00:00
"github.com/hamcha/clessy/tg"
)
2016-02-10 14:31:53 +00:00
func assert(err error) {
if err != nil {
panic(err)
}
}
var db *bolt.DB
2016-09-01 12:05:32 +00:00
var chatID *int64
2016-02-10 14:31:53 +00:00
2016-02-09 15:00:50 +00:00
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)
2016-02-09 15:00:50 +00:00
}
func main() {
brokerAddr := flag.String("broker", "localhost:7314", "Broker address:port")
2016-02-11 10:00:35 +00:00
webBind := flag.String("webserver", "localhost:7315", "Address to bind webserver to")
2016-02-10 14:31:53 +00:00
boltdbFile := flag.String("boltdb", "stats.db", "BoltDB database file")
2016-09-01 12:05:32 +00:00
chatID = flag.Int64("chatid", -14625256, "Telegram Chat ID to count stats for")
2016-02-09 15:00:50 +00:00
flag.Parse()
var err error
db, err = bolt.Open(*boltdbFile, 0600, nil)
2016-02-10 14:31:53 +00:00
assert(err)
defer db.Close()
loadUsers()
2016-02-10 14:31:53 +00:00
loadStats()
2016-02-11 10:00:35 +00:00
go startWebServer(*webBind)
2016-02-10 14:31:53 +00:00
err = tg.CreateBrokerClient(*brokerAddr, process)
assert(err)
2016-02-09 15:00:50 +00:00
}