chore: update comments

This commit is contained in:
Steven
2024-05-14 22:48:38 +08:00
parent 7ad0b19dce
commit 04a8062c47
2 changed files with 11 additions and 5 deletions

View File

@@ -1,11 +1,16 @@
package main package main
import "github.com/usememos/memogram" import (
"context"
"github.com/usememos/memogram"
)
func main() { func main() {
ctx := context.Background()
service, err := memogram.NewService() service, err := memogram.NewService()
if err != nil { if err != nil {
panic(err) panic(err)
} }
service.Start() service.Start(ctx)
} }

View File

@@ -19,6 +19,7 @@ import (
// userAccessTokenCache is a cache for user access token. // userAccessTokenCache is a cache for user access token.
// Key is the user id from telegram. // Key is the user id from telegram.
// Value is the access token from memos. // Value is the access token from memos.
// TODO: save it to a persistent storage.
var userAccessTokenCache sync.Map // map[int64]string var userAccessTokenCache sync.Map // map[int64]string
type Service struct { type Service struct {
@@ -45,7 +46,7 @@ func NewService() (*Service, error) {
}, nil }, nil
} }
func (s *Service) Start() { func (s *Service) Start(ctx context.Context) {
config, err := getConfigFromEnv() config, err := getConfigFromEnv()
if err != nil { if err != nil {
slog.Error("failed to get config from env", slog.Any("err", err)) slog.Error("failed to get config from env", slog.Any("err", err))
@@ -63,8 +64,7 @@ func (s *Service) Start() {
} }
slog.Info("memogram started") slog.Info("memogram started")
b.Start(ctx)
b.Start(context.Background())
} }
func (s *Service) handler(ctx context.Context, b *bot.Bot, m *models.Update) { func (s *Service) handler(ctx context.Context, b *bot.Bot, m *models.Update) {
@@ -83,6 +83,7 @@ func (s *Service) handler(ctx context.Context, b *bot.Bot, m *models.Update) {
} }
message := m.Message message := m.Message
// TODO: handle message.Entities to get markdown text.
text := message.Text text := message.Text
if text == "" { if text == "" {
b.SendMessage(ctx, &bot.SendMessageParams{ b.SendMessage(ctx, &bot.SendMessageParams{