diff --git a/.gitignore b/.gitignore index c860579..fdec95d 100644 --- a/.gitignore +++ b/.gitignore @@ -189,3 +189,4 @@ cython_debug/ # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +config.toml diff --git a/config.example.toml b/config.example.toml new file mode 100644 index 0000000..d628035 --- /dev/null +++ b/config.example.toml @@ -0,0 +1,7 @@ +[telegram] +api_key = "example" +admin_id = "000000" + +[storage] +type = "local" #local, s3 +path = "data/storage" diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..19667c1 --- /dev/null +++ b/config/config.go @@ -0,0 +1,29 @@ +package config + +import ( + toml "github.com/BurntSushi/toml" +) + +type TelegramConfig struct { + APIKey string `toml:"api_key"` + AdminID string `toml:"admin_id"` +} + +type StorageConfig struct { + Type string `toml:"type"` + Path string `toml:"path"` +} + +type Config struct { + Telegram TelegramConfig + Storage StorageConfig +} + +func LoadConfig(path string) (*Config, error) { + var cfg Config + _, err := toml.DecodeFile(path, &cfg) + if err != nil { + return nil, err + } + return &cfg, nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c12349b --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module git.iamglitch.cc/glitch/bookmate + +go 1.24.4 + +require github.com/BurntSushi/toml v1.5.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..ff7fd09 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg= +github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= diff --git a/internal/bot/handler.go b/internal/bot/handler.go new file mode 100644 index 0000000..022a07d --- /dev/null +++ b/internal/bot/handler.go @@ -0,0 +1,44 @@ +package bot + +import ( + "context" + + "git.iamglitch.cc/glitch/bookmate/internal/service" + tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" +) + +type Handler struct { + bot *tgbotapi.BotAPI + service *service.Service +} + +func newHandler(bot *tgbotapi.BotAPI, svc *service.Service) *Handler { + return &Handler{ + bot: bot, + service: svc, + } +} + +func (h *Handler) HandleUpdate(ctx context.Context, update tgbotapi.Update) { + if update.Message != nil { + h.handleMessage(ctx, update.Message) + } + + if update.CallbackQuery != nil { + h.handleCallback(ctx, update.CallbackQuery) + } +} + +func (h *Handler) handleMessage(ctx context.Context, msg *tgbotapi.Message) { + if msg.IsCommand() { + h.handleCommand(ctx, msg) + } +} + +func (h *Handler) handleCommand(ctx context.Context, msg *tgbotapi.Message) { + panic("unimplemented") +} + +func (h *Handler) handleCallback(ctx context.Context, cb *tgbotapi.CallbackQuery) { + panic("unimplemented") +} diff --git a/internal/bot/router.go b/internal/bot/router.go new file mode 100644 index 0000000..e69de29 diff --git a/internal/service/service.go b/internal/service/service.go new file mode 100644 index 0000000..593b530 --- /dev/null +++ b/internal/service/service.go @@ -0,0 +1,4 @@ +package service + +type Service struct { +}