go-dette/main.go

51 lines
1.4 KiB
Go
Raw Permalink Normal View History

2023-01-19 23:12:55 +03:00
package main
import (
2023-01-24 23:17:30 +03:00
"context"
2023-01-19 23:12:55 +03:00
"log"
"os"
2023-01-20 00:30:21 +03:00
"git.nefrace.ru/nefrace/nechotron"
"git.nefrace.ru/nefrace/tongo"
2023-01-24 03:11:15 +03:00
"github.com/NicoNex/echotron/v3"
"github.com/joho/godotenv"
"go.mongodb.org/mongo-driver/mongo"
2023-01-24 23:17:30 +03:00
"go.mongodb.org/mongo-driver/mongo/options"
2023-01-19 23:12:55 +03:00
)
2023-01-24 00:37:27 +03:00
var BuildTime string
2023-01-24 23:17:30 +03:00
var db *tongo.Database
2023-01-24 00:37:27 +03:00
2023-01-19 23:12:55 +03:00
func main() {
2023-06-08 01:44:38 +03:00
log.Println("Starting Go-Dette")
godotenv.Load()
2023-01-24 23:17:30 +03:00
var err error
db, err = tongo.NewConnection(os.Getenv("MONGO_URI"), "godette")
if err != nil {
log.Fatalf("Can't connect to database: %v", err)
}
2023-01-24 23:17:30 +03:00
createIndexes(db)
2023-01-24 03:11:15 +03:00
token := os.Getenv("TELEGRAM_TOKEN")
neco := nechotron.NewTron(token, &MainState)
neco.
Use(UserDBUpdater(db)).
2023-06-18 23:39:55 +03:00
Use(ChatUpdate(db)).
2023-01-24 23:17:30 +03:00
Use(ErrorLogger).
Use(ExecTimeLogger)
2023-01-24 03:11:15 +03:00
api := echotron.NewAPI(token)
nechotron.SetMyCommands(api, "", echotron.BotCommandScope{Type: echotron.Any}, defaultCommands...)
nechotron.SetMyCommands(api, "", echotron.BotCommandScope{Type: echotron.BCSTAllChatAdministrators}, allCommands...)
2023-06-15 17:03:57 +03:00
go RSSTask(&api)
2023-07-27 21:48:26 +03:00
for {
log.Println(neco.DispatchPoll())
}
2023-01-19 23:12:55 +03:00
}
2023-01-24 23:17:30 +03:00
func createIndexes(db *tongo.Database) error {
userStore := tongo.NewStore[User](db)
_, err := userStore.Coll.Indexes().CreateOne(context.Background(), userIndex, options.CreateIndexes())
karmaShotStore := tongo.NewStore[KarmaShot](db)
_, err = karmaShotStore.Coll.Indexes().CreateMany(context.Background(), []mongo.IndexModel{karmaFromIndex, karmaToIndex}, options.CreateIndexes())
2023-01-24 23:17:30 +03:00
return err
}