Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
107d90deb8 | |||
6f111a42e9 | |||
2aa043b5fc |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
tglistbot*
|
12
Makefile
Normal file
12
Makefile
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
VERSION = $(shell git describe --tags --abbrev=0)
|
||||||
|
|
||||||
|
build_release:
|
||||||
|
CGO_ENABLED=0 go build -buildmode=pie -ldflags "-X main.Version=$(VERSION)" -o tglistbot-$(VERSION)
|
||||||
|
|
||||||
|
release_check:
|
||||||
|
go list -m go.balki.me/tglistbot@$(VERSION)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -i tglistbot* || true
|
||||||
|
|
19
main.go
19
main.go
@ -22,14 +22,24 @@ import (
|
|||||||
"go.balki.me/tglistbot/glist"
|
"go.balki.me/tglistbot/glist"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Version will be set from build commandline
|
||||||
|
var Version string
|
||||||
var apiToken string
|
var apiToken string
|
||||||
|
|
||||||
|
var usage string = `Telegram List bot
|
||||||
|
Environment variables:
|
||||||
|
TGLB_API_TOKEN (required): See https://core.telegram.org/bots#how-do-i-create-a-bot
|
||||||
|
TGLB_PORT (default 28923): Set numerical port or unix//run/path.sock for unix socket
|
||||||
|
TGLB_DATA_PATH (default .): Directory path where list data is stored
|
||||||
|
`
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
apiToken = os.Getenv("TGLB_API_TOKEN")
|
apiToken = os.Getenv("TGLB_API_TOKEN")
|
||||||
|
|
||||||
if apiToken == "" {
|
if apiToken == "" {
|
||||||
log.Panicln("TG_API_TOKEN is empty")
|
log.Print(usage)
|
||||||
|
log.Panicln("TGLB_API_TOKEN is empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
port, unixSocketPath := func() (int, string) {
|
port, unixSocketPath := func() (int, string) {
|
||||||
@ -61,7 +71,10 @@ func main() {
|
|||||||
|
|
||||||
glist.DataPath = dataPath
|
glist.DataPath = dataPath
|
||||||
|
|
||||||
commit := func() string {
|
version := func() string {
|
||||||
|
if Version != "" {
|
||||||
|
return Version
|
||||||
|
}
|
||||||
if bi, ok := debug.ReadBuildInfo(); ok {
|
if bi, ok := debug.ReadBuildInfo(); ok {
|
||||||
for _, s := range bi.Settings {
|
for _, s := range bi.Settings {
|
||||||
if s.Key == "vcs.revision" {
|
if s.Key == "vcs.revision" {
|
||||||
@ -79,7 +92,7 @@ func main() {
|
|||||||
return fmt.Sprintf("port: %v", port)
|
return fmt.Sprintf("port: %v", port)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
log.Printf("List bot (%s) starting with datapath: %q, %s\n", commit, dataPath, listeningOn)
|
log.Printf("List bot (%s) starting with datapath: %q, %s\n", version, dataPath, listeningOn)
|
||||||
|
|
||||||
var chats sync.Map
|
var chats sync.Map
|
||||||
if err := loadData(dataPath, &chats); err != nil {
|
if err := loadData(dataPath, &chats); err != nil {
|
||||||
|
Reference in New Issue
Block a user