diff --git a/docker-compose.yml.example b/docker-compose.yml.example index 977c2a9..63467f5 100644 --- a/docker-compose.yml.example +++ b/docker-compose.yml.example @@ -39,7 +39,8 @@ services: tg_bot: build: - context: telegram_bot + context: . + dockerfile: tg_bot/Dockerfile depends_on: - backend environment: @@ -50,7 +51,8 @@ services: tg_parser: build: - context: tg_parser + context: . + dockerfile: tg_parser/Dockerfile depends_on: - postgres environment: diff --git a/pkg/go.mod b/pkg/go.mod new file mode 100644 index 0000000..8ffc90d --- /dev/null +++ b/pkg/go.mod @@ -0,0 +1,9 @@ +module github.com/TelegramExchange/pkg + +go 1.24.4 + +require ( + github.com/gotd/td v0.136.0 + github.com/jackc/pgx/v5 v5.7.6 + github.com/rs/zerolog v1.34.0 +) diff --git a/pkg/go.sum b/pkg/go.sum new file mode 100644 index 0000000..39ea11a --- /dev/null +++ b/pkg/go.sum @@ -0,0 +1,13 @@ +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gotd/td v0.136.0/go.mod h1:mStcqs/9FXhNhWnPTguptSwqkQbRIwXLw3SCSpzPJxM= +github.com/jackc/pgx/v5 v5.7.6/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0= +github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/tg_parser/pkg/logger/logger.go b/pkg/logger/logger.go similarity index 100% rename from tg_parser/pkg/logger/logger.go rename to pkg/logger/logger.go diff --git a/tg_parser/pkg/postgres/postgres.go b/pkg/postgres/postgres.go similarity index 100% rename from tg_parser/pkg/postgres/postgres.go rename to pkg/postgres/postgres.go diff --git a/tg_parser/pkg/telegram/telegram.go b/pkg/telegram/telegram.go similarity index 100% rename from tg_parser/pkg/telegram/telegram.go rename to pkg/telegram/telegram.go diff --git a/tg_parser/pkg/transaction/transaction.go b/pkg/transaction/transaction.go similarity index 96% rename from tg_parser/pkg/transaction/transaction.go rename to pkg/transaction/transaction.go index 50b2a4a..29e4d19 100644 --- a/tg_parser/pkg/transaction/transaction.go +++ b/pkg/transaction/transaction.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - "github.com/TelegramExchange/tgex-parser/pkg/postgres" + "github.com/TelegramExchange/pkg/postgres" "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgconn" "github.com/jackc/pgx/v5/pgxpool" diff --git a/tg_parser/pkg/transaction/wrap.go b/pkg/transaction/wrap.go similarity index 100% rename from tg_parser/pkg/transaction/wrap.go rename to pkg/transaction/wrap.go diff --git a/telegram_bot/handlers/global_callbacks.go b/telegram_bot/handlers/global_callbacks.go deleted file mode 100644 index 54d19a5..0000000 --- a/telegram_bot/handlers/global_callbacks.go +++ /dev/null @@ -1,42 +0,0 @@ -package handlers - -import ( - "strings" - - "example.com/m/bot" - "example.com/m/screens" -) - -// HandleGlobalCallback обрабатывает глобальные callbacks из уведомлений -// Возвращает новый State если callback был обработан, иначе nil -func HandleGlobalCallback(callbackData string) bot.State { - // pending_channel:{channel_id} - выбор workspace для нового канала - if strings.HasPrefix(callbackData, "pending_channel:") { - parts := strings.Split(callbackData, ":") - if len(parts) == 2 { - channelID := parts[1] - return &screens.SelectWorkspace{ - ChannelID: channelID, - BackState: &screens.MainMenu{}, - } - } - } - - // workspace_invite_accept:{invite_id} - принятие приглашения в workspace - if strings.HasPrefix(callbackData, "workspace_invite_accept:") { - parts := strings.Split(callbackData, ":") - if len(parts) == 2 { - inviteID := parts[1] - return &screens.AcceptWorkspaceInvite{ - InviteID: inviteID, - } - } - } - - // Здесь можно добавлять другие глобальные callback паттерны - // Например: - // if strings.HasPrefix(callbackData, "notification:") { ... } - // if strings.HasPrefix(callbackData, "alert:") { ... } - - return nil -} diff --git a/telegram_bot/pkg/logger/logger.go b/telegram_bot/pkg/logger/logger.go deleted file mode 100644 index 32057b2..0000000 --- a/telegram_bot/pkg/logger/logger.go +++ /dev/null @@ -1,38 +0,0 @@ -package logger - -import ( - "os" - "time" - - "github.com/rs/zerolog" - "github.com/rs/zerolog/log" -) - -type Config struct { - AppName string `envconfig:"APP_NAME" required:"true"` - AppVersion string `envconfig:"APP_VERSION" required:"true"` - Level string `default:"error" envconfig:"LOGGER_LEVEL"` - PrettyConsole bool `default:"false" envconfig:"LOGGER_PRETTY_CONSOLE"` -} - -func Init(c Config) { - zerolog.TimeFieldFormat = time.RFC3339 - zerolog.SetGlobalLevel(zerolog.InfoLevel) - - level, err := zerolog.ParseLevel(c.Level) - if err != nil { - zerolog.SetGlobalLevel(level) - } - - log.Logger = log.With(). - // Caller(). - // Str("app_name", c.AppName). - // Str("app_version", c.AppVersion). - Logger() - - if c.PrettyConsole { - log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr, TimeFormat: "15:04:05"}) - } - - log.Info().Msg("Logger initialized") -} diff --git a/telegram_bot/Dockerfile b/tg_bot/Dockerfile similarity index 63% rename from telegram_bot/Dockerfile rename to tg_bot/Dockerfile index 59624d8..307a1a1 100644 --- a/telegram_bot/Dockerfile +++ b/tg_bot/Dockerfile @@ -1,17 +1,18 @@ FROM golang:1.25-alpine AS build -WORKDIR /app +WORKDIR /app/tg_bot # Modules layer -COPY go.mod go.sum ./ +COPY tg_bot/go.mod tg_bot/go.sum ./ +COPY pkg /app/pkg RUN go mod download # Build layer -COPY . . +COPY tg_bot /app/tg_bot RUN CGO_ENABLED=0 GOOS=linux go build -o /tg_bot . FROM alpine:latest AS run COPY --from=build /tg_bot /tg_bot -CMD ["/tg_bot"] \ No newline at end of file +CMD ["/tg_bot"] diff --git a/telegram_bot/adapter/backend/backend_client.go b/tg_bot/backend/backend_client.go similarity index 100% rename from telegram_bot/adapter/backend/backend_client.go rename to tg_bot/backend/backend_client.go diff --git a/telegram_bot/bot/bot.go b/tg_bot/bot/bot.go similarity index 99% rename from telegram_bot/bot/bot.go rename to tg_bot/bot/bot.go index 505a058..8788038 100644 --- a/telegram_bot/bot/bot.go +++ b/tg_bot/bot/bot.go @@ -7,8 +7,8 @@ import ( "strings" "sync" - "example.com/m/adapter/backend" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/backend" "github.com/rs/zerolog/log" ) diff --git a/telegram_bot/bot/state.go b/tg_bot/bot/state.go similarity index 100% rename from telegram_bot/bot/state.go rename to tg_bot/bot/state.go diff --git a/telegram_bot/go.mod b/tg_bot/go.mod similarity index 57% rename from telegram_bot/go.mod rename to tg_bot/go.mod index 1d68548..87dbccc 100644 --- a/telegram_bot/go.mod +++ b/tg_bot/go.mod @@ -1,8 +1,11 @@ -module example.com/m +module github.com/TelegramExchange/tgex-backend/tg_bot go 1.24.4 -require github.com/rs/zerolog v1.34.0 +require ( + github.com/rs/zerolog v1.34.0 + github.com/TelegramExchange/pkg v0.0.0 +) require ( github.com/NicoNex/echotron/v3 v3.43.0 // indirect @@ -11,3 +14,5 @@ require ( golang.org/x/sys v0.39.0 // indirect golang.org/x/time v0.5.0 // indirect ) + +replace github.com/TelegramExchange/pkg => ../pkg diff --git a/telegram_bot/go.sum b/tg_bot/go.sum similarity index 100% rename from telegram_bot/go.sum rename to tg_bot/go.sum diff --git a/telegram_bot/main.go b/tg_bot/main.go similarity index 66% rename from telegram_bot/main.go rename to tg_bot/main.go index f8ea4de..e13e46f 100644 --- a/telegram_bot/main.go +++ b/tg_bot/main.go @@ -2,21 +2,19 @@ package main import ( "os" + "strings" "time" - "example.com/m/adapter/backend" - "example.com/m/bot" - "example.com/m/handlers" - "example.com/m/pkg/logger" - "example.com/m/screens" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/pkg/logger" + "github.com/TelegramExchange/tgex-backend/tg_bot/backend" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" + "github.com/TelegramExchange/tgex-backend/tg_bot/screens" "github.com/rs/zerolog/log" ) func main() { logger.Init(logger.Config{ - AppName: "tgex-bot", - AppVersion: "v0.0.1", PrettyConsole: true, }) @@ -39,8 +37,22 @@ func main() { panic("Unknown command: " + command) } + var handleGlobalCallback = func(callbackData string) bot.State { + id, ok := strings.CutPrefix(callbackData, "pending_channel:") + if ok { + return &screens.SelectWorkspace{ChannelID: id, BackState: &screens.MainMenu{}} + } + + id, ok = strings.CutPrefix(callbackData, "workspace_invite_accept:") + if ok { + return &screens.AcceptWorkspaceInvite{InviteID: id} + } + + return nil + } + newBot := func(chatID int64) echotron.Bot { - return bot.NewBot(chatID, botToken, commandRouter, backendClient, handlers.HandleGlobalCallback) + return bot.NewBot(chatID, botToken, commandRouter, backendClient, handleGlobalCallback) } dsp := echotron.NewDispatcher(botToken, newBot) @@ -68,10 +80,10 @@ func main() { } func mustEnv(key string) string { - value := os.Getenv(key) - if value == "" { + v := os.Getenv(key) + if v == "" { log.Fatal().Str("env", key).Msg("missing required environment variable") } - return value + return v } diff --git a/telegram_bot/screens/accept_workspace_invite.go b/tg_bot/screens/accept_workspace_invite.go similarity index 96% rename from telegram_bot/screens/accept_workspace_invite.go rename to tg_bot/screens/accept_workspace_invite.go index 92fb1ef..2131fab 100644 --- a/telegram_bot/screens/accept_workspace_invite.go +++ b/tg_bot/screens/accept_workspace_invite.go @@ -3,8 +3,8 @@ package screens import ( "context" - "example.com/m/bot" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" ) type AcceptWorkspaceInvite struct { diff --git a/telegram_bot/screens/add_creative.go b/tg_bot/screens/add_creative.go similarity index 98% rename from telegram_bot/screens/add_creative.go rename to tg_bot/screens/add_creative.go index 2994372..60c4173 100644 --- a/telegram_bot/screens/add_creative.go +++ b/tg_bot/screens/add_creative.go @@ -7,10 +7,10 @@ import ( "strconv" "strings" - "example.com/m/adapter/backend" - "example.com/m/bot" - "example.com/m/ui" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/backend" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" + "github.com/TelegramExchange/tgex-backend/tg_bot/screens/ui" "github.com/rs/zerolog/log" ) diff --git a/telegram_bot/screens/add_project.go b/tg_bot/screens/add_project.go similarity index 97% rename from telegram_bot/screens/add_project.go rename to tg_bot/screens/add_project.go index bccd2ab..e454d3e 100644 --- a/telegram_bot/screens/add_project.go +++ b/tg_bot/screens/add_project.go @@ -1,8 +1,8 @@ package screens import ( - "example.com/m/bot" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" ) const addProjectInstructionText = ` diff --git a/telegram_bot/screens/add_purchase.go b/tg_bot/screens/add_purchase.go similarity index 98% rename from telegram_bot/screens/add_purchase.go rename to tg_bot/screens/add_purchase.go index 7be21c5..7283e50 100644 --- a/telegram_bot/screens/add_purchase.go +++ b/tg_bot/screens/add_purchase.go @@ -4,9 +4,9 @@ import ( "context" "fmt" - "example.com/m/bot" - "example.com/m/ui" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" + "github.com/TelegramExchange/tgex-backend/tg_bot/screens/ui" "github.com/rs/zerolog/log" ) diff --git a/telegram_bot/screens/creative_details.go b/tg_bot/screens/creative_details.go similarity index 98% rename from telegram_bot/screens/creative_details.go rename to tg_bot/screens/creative_details.go index 0d18598..b6e8373 100644 --- a/telegram_bot/screens/creative_details.go +++ b/tg_bot/screens/creative_details.go @@ -5,10 +5,10 @@ import ( "fmt" "strings" - "example.com/m/adapter/backend" - "example.com/m/bot" - "example.com/m/ui" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/backend" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" + "github.com/TelegramExchange/tgex-backend/tg_bot/screens/ui" "github.com/rs/zerolog/log" ) diff --git a/telegram_bot/screens/creative_editor.go b/tg_bot/screens/creative_editor.go similarity index 99% rename from telegram_bot/screens/creative_editor.go rename to tg_bot/screens/creative_editor.go index 7bd36f2..2c5a749 100644 --- a/telegram_bot/screens/creative_editor.go +++ b/tg_bot/screens/creative_editor.go @@ -4,9 +4,9 @@ import ( "fmt" "strings" - "example.com/m/bot" - "example.com/m/ui" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" + "github.com/TelegramExchange/tgex-backend/tg_bot/screens/ui" "github.com/rs/zerolog/log" ) diff --git a/telegram_bot/screens/creative_editor_ui.go b/tg_bot/screens/creative_editor_ui.go similarity index 98% rename from telegram_bot/screens/creative_editor_ui.go rename to tg_bot/screens/creative_editor_ui.go index de25801..1f53a13 100644 --- a/telegram_bot/screens/creative_editor_ui.go +++ b/tg_bot/screens/creative_editor_ui.go @@ -1,8 +1,8 @@ package screens import ( - "example.com/m/bot" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" ) const msgEditCreativeText = ` diff --git a/telegram_bot/screens/creatives.go b/tg_bot/screens/creatives.go similarity index 97% rename from telegram_bot/screens/creatives.go rename to tg_bot/screens/creatives.go index 2eea943..2d21816 100644 --- a/telegram_bot/screens/creatives.go +++ b/tg_bot/screens/creatives.go @@ -5,9 +5,9 @@ import ( "fmt" "strings" - "example.com/m/bot" - "example.com/m/ui" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" + "github.com/TelegramExchange/tgex-backend/tg_bot/screens/ui" "github.com/rs/zerolog/log" ) diff --git a/telegram_bot/screens/helpers.go b/tg_bot/screens/helpers.go similarity index 100% rename from telegram_bot/screens/helpers.go rename to tg_bot/screens/helpers.go diff --git a/telegram_bot/screens/login.go b/tg_bot/screens/login.go similarity index 95% rename from telegram_bot/screens/login.go rename to tg_bot/screens/login.go index a398895..94895aa 100644 --- a/telegram_bot/screens/login.go +++ b/tg_bot/screens/login.go @@ -4,8 +4,8 @@ import ( "context" "fmt" - "example.com/m/bot" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" ) type Login struct{} diff --git a/telegram_bot/screens/main_menu.go b/tg_bot/screens/main_menu.go similarity index 96% rename from telegram_bot/screens/main_menu.go rename to tg_bot/screens/main_menu.go index 499d35d..6a8f796 100644 --- a/telegram_bot/screens/main_menu.go +++ b/tg_bot/screens/main_menu.go @@ -1,8 +1,8 @@ package screens import ( - "example.com/m/bot" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" ) type MainMenu struct{} diff --git a/telegram_bot/screens/my_projects.go b/tg_bot/screens/my_projects.go similarity index 98% rename from telegram_bot/screens/my_projects.go rename to tg_bot/screens/my_projects.go index e6eee45..21668a7 100644 --- a/telegram_bot/screens/my_projects.go +++ b/tg_bot/screens/my_projects.go @@ -6,9 +6,9 @@ import ( "strings" "time" - "example.com/m/bot" - "example.com/m/ui" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" + "github.com/TelegramExchange/tgex-backend/tg_bot/screens/ui" "github.com/rs/zerolog/log" ) diff --git a/telegram_bot/screens/project_details.go b/tg_bot/screens/project_details.go similarity index 98% rename from telegram_bot/screens/project_details.go rename to tg_bot/screens/project_details.go index 23dcabb..1edf53a 100644 --- a/telegram_bot/screens/project_details.go +++ b/tg_bot/screens/project_details.go @@ -5,9 +5,9 @@ import ( "fmt" "strings" - "example.com/m/adapter/backend" - "example.com/m/bot" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/backend" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" "github.com/rs/zerolog/log" ) diff --git a/telegram_bot/screens/purchase_details.go b/tg_bot/screens/purchase_details.go similarity index 98% rename from telegram_bot/screens/purchase_details.go rename to tg_bot/screens/purchase_details.go index b009b6a..db26cbd 100644 --- a/telegram_bot/screens/purchase_details.go +++ b/tg_bot/screens/purchase_details.go @@ -5,9 +5,9 @@ import ( "fmt" "strings" - "example.com/m/adapter/backend" - "example.com/m/bot" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/backend" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" "github.com/rs/zerolog/log" ) diff --git a/telegram_bot/screens/purchase_optional_details.go b/tg_bot/screens/purchase_optional_details.go similarity index 98% rename from telegram_bot/screens/purchase_optional_details.go rename to tg_bot/screens/purchase_optional_details.go index 791570e..2ec3d72 100644 --- a/telegram_bot/screens/purchase_optional_details.go +++ b/tg_bot/screens/purchase_optional_details.go @@ -8,10 +8,10 @@ import ( "strings" "time" - "example.com/m/adapter/backend" - "example.com/m/bot" - "example.com/m/ui" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/backend" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" + ui2 "github.com/TelegramExchange/tgex-backend/tg_bot/screens/ui" "github.com/rs/zerolog/log" ) @@ -128,7 +128,7 @@ func (s *PurchaseOptionalDetails) HandleCallback(b *bot.Bot, u *echotron.Update) } case "opt_payment_date": - b.SetState(ui.NewDateTimePicker(ui.DateTimePickerConfig{ + b.SetState(ui2.NewDateTimePicker(ui2.DateTimePickerConfig{ Title: "Дата оплаты", Key: "payment_date", IncludeTime: true, @@ -381,8 +381,8 @@ func (s *PurchaseOptionalDetails) formatDateTime(value *time.Time) string { if value == nil { return "—" } - local := value.In(ui.MskLocation) - return fmt.Sprintf("%s %02d %s %s", ui.WeekdayName(local.Weekday()), local.Day(), ui.MonthShort(local.Month()), local.Format("15:04")) + local := value.In(ui2.MskLocation) + return fmt.Sprintf("%s %02d %s %s", ui2.WeekdayName(local.Weekday()), local.Day(), ui2.MonthShort(local.Month()), local.Format("15:04")) } func (s *PurchaseOptionalDetails) formatText(value string) string { @@ -685,7 +685,7 @@ func (s *PurchaseOptionalDetails) renderParamChannels(b *bot.Bot, mode bot.Rende if s.ParamPage*perPage >= total { s.ParamPage = 0 } - start, end := ui.GetPageBounds(s.ParamPage, perPage, total) + start, end := ui2.GetPageBounds(s.ParamPage, perPage, total) // Устанавливаем режим по умолчанию if s.ChannelEditMode == "" { @@ -757,8 +757,8 @@ func (s *PurchaseOptionalDetails) renderParamChannels(b *bot.Bot, mode bot.Rende } } - pages := ui.CalculatePages(total, perPage) - if navRow := ui.BuildNavigationRow(ui.PaginationConfig{ + pages := ui2.CalculatePages(total, perPage) + if navRow := ui2.BuildNavigationRow(ui2.PaginationConfig{ CurrentPage: s.ParamPage, TotalPages: pages, }); navRow != nil { @@ -877,7 +877,7 @@ func (s *PurchaseOptionalDetails) openCommonEditor(b *bot.Bot, param string) { case "placement": s.InputMode = "" s.ReturnMode = "" - b.SetState(ui.NewDateTimePicker(ui.DateTimePickerConfig{ + b.SetState(ui2.NewDateTimePicker(ui2.DateTimePickerConfig{ Title: "Дата и время размещения", Key: "placement_datetime", IncludeTime: true, @@ -909,7 +909,7 @@ func (s *PurchaseOptionalDetails) openChannelEditor(b *bot.Bot, param, username switch param { case "placement": s.InputMode = "placement_channels" - b.SetState(ui.NewDateTimePicker(ui.DateTimePickerConfig{ + b.SetState(ui2.NewDateTimePicker(ui2.DateTimePickerConfig{ Title: "Дата и время размещения", Key: "placement_datetime:" + username, IncludeTime: true, @@ -970,7 +970,7 @@ func (s *PurchaseOptionalDetails) pasteParamValue(param, username string) { s.PlacementByChannel[username] = nil return } - value := s.PlacementCopy.In(ui.MskLocation) + value := s.PlacementCopy.In(ui2.MskLocation) s.PlacementByChannel[username] = &value case "cost": if s.CostCopy == nil { diff --git a/telegram_bot/screens/purchases.go b/tg_bot/screens/purchases.go similarity index 98% rename from telegram_bot/screens/purchases.go rename to tg_bot/screens/purchases.go index d9f7bef..3a079e8 100644 --- a/telegram_bot/screens/purchases.go +++ b/tg_bot/screens/purchases.go @@ -4,8 +4,8 @@ import ( "context" "fmt" - "example.com/m/bot" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" "github.com/rs/zerolog/log" ) diff --git a/telegram_bot/screens/select_channels_for_purchase.go b/tg_bot/screens/select_channels_for_purchase.go similarity index 98% rename from telegram_bot/screens/select_channels_for_purchase.go rename to tg_bot/screens/select_channels_for_purchase.go index e1f055b..15d0f71 100644 --- a/telegram_bot/screens/select_channels_for_purchase.go +++ b/tg_bot/screens/select_channels_for_purchase.go @@ -6,10 +6,10 @@ import ( "regexp" "strings" - "example.com/m/adapter/backend" - "example.com/m/bot" - "example.com/m/ui" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/backend" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" + "github.com/TelegramExchange/tgex-backend/tg_bot/screens/ui" "github.com/rs/zerolog/log" ) diff --git a/telegram_bot/screens/select_workspace.go b/tg_bot/screens/select_workspace.go similarity index 97% rename from telegram_bot/screens/select_workspace.go rename to tg_bot/screens/select_workspace.go index 013fe30..ce36b54 100644 --- a/telegram_bot/screens/select_workspace.go +++ b/tg_bot/screens/select_workspace.go @@ -5,9 +5,9 @@ import ( "fmt" "strings" - "example.com/m/bot" - "example.com/m/ui" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" + "github.com/TelegramExchange/tgex-backend/tg_bot/screens/ui" "github.com/rs/zerolog/log" ) diff --git a/telegram_bot/ui/date_time_picker.go b/tg_bot/screens/ui/date_time_picker.go similarity index 99% rename from telegram_bot/ui/date_time_picker.go rename to tg_bot/screens/ui/date_time_picker.go index 9c4e964..1f416db 100644 --- a/telegram_bot/ui/date_time_picker.go +++ b/tg_bot/screens/ui/date_time_picker.go @@ -6,8 +6,8 @@ import ( "strings" "time" - "example.com/m/bot" "github.com/NicoNex/echotron/v3" + "github.com/TelegramExchange/tgex-backend/tg_bot/bot" ) const ( diff --git a/telegram_bot/ui/message_format.go b/tg_bot/screens/ui/message_format.go similarity index 100% rename from telegram_bot/ui/message_format.go rename to tg_bot/screens/ui/message_format.go diff --git a/telegram_bot/ui/pagination.go b/tg_bot/screens/ui/pagination.go similarity index 100% rename from telegram_bot/ui/pagination.go rename to tg_bot/screens/ui/pagination.go diff --git a/tg_parser/Dockerfile b/tg_parser/Dockerfile index 8964ce1..eec949b 100644 --- a/tg_parser/Dockerfile +++ b/tg_parser/Dockerfile @@ -1,13 +1,14 @@ FROM golang:1.25-alpine AS build -WORKDIR /app +WORKDIR /app/tg_parser # Modules layer -COPY go.mod go.sum ./ +COPY tg_parser/go.mod tg_parser/go.sum ./ +COPY pkg /app/pkg RUN go mod download # Build layer -COPY . . +COPY tg_parser /app/tg_parser RUN CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -o /parser . FROM alpine:latest AS run diff --git a/tg_parser/config/config.go b/tg_parser/config/config.go index 90bdcd8..00bd273 100644 --- a/tg_parser/config/config.go +++ b/tg_parser/config/config.go @@ -5,13 +5,13 @@ import ( "fmt" "os" - "github.com/TelegramExchange/tgex-parser/pkg/logger" - "github.com/TelegramExchange/tgex-parser/pkg/postgres" + "github.com/TelegramExchange/pkg/logger" + "github.com/TelegramExchange/pkg/postgres" + "github.com/TelegramExchange/pkg/telegram" "github.com/joho/godotenv" "github.com/kelseyhightower/envconfig" - "github.com/TelegramExchange/tgex-parser/internal/controller/worker" - "github.com/TelegramExchange/tgex-parser/pkg/telegram" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/controller/worker" ) type HTTP struct { diff --git a/tg_parser/go.mod b/tg_parser/go.mod index 784b40c..d56b364 100644 --- a/tg_parser/go.mod +++ b/tg_parser/go.mod @@ -1,4 +1,4 @@ -module github.com/TelegramExchange/tgex-parser +module github.com/TelegramExchange/tgex-backend/tg_parser go 1.25.0 @@ -8,6 +8,7 @@ require ( github.com/joho/godotenv v1.5.1 github.com/kelseyhightower/envconfig v1.4.0 github.com/rs/zerolog v1.34.0 + github.com/TelegramExchange/pkg v0.0.0 ) require ( @@ -49,3 +50,5 @@ require ( gopkg.in/yaml.v2 v2.4.0 // indirect rsc.io/qr v0.2.0 // indirect ) + +replace github.com/TelegramExchange/pkg => ../pkg diff --git a/tg_parser/internal/adapter/database/create_post.go b/tg_parser/internal/adapter/database/create_post.go index a5ac93b..0e1c1a2 100644 --- a/tg_parser/internal/adapter/database/create_post.go +++ b/tg_parser/internal/adapter/database/create_post.go @@ -6,8 +6,8 @@ import ( "github.com/jackc/pgx/v5/pgtype" - "github.com/TelegramExchange/tgex-parser/internal/domain" - "github.com/TelegramExchange/tgex-parser/pkg/transaction" + "github.com/TelegramExchange/pkg/transaction" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" ) func (d *Database) CreatePost(ctx context.Context, post domain.Post) error { diff --git a/tg_parser/internal/adapter/database/create_views_snapshot.go b/tg_parser/internal/adapter/database/create_views_snapshot.go index da7d357..ed00999 100644 --- a/tg_parser/internal/adapter/database/create_views_snapshot.go +++ b/tg_parser/internal/adapter/database/create_views_snapshot.go @@ -7,8 +7,8 @@ import ( "github.com/google/uuid" "github.com/jackc/pgx/v5/pgtype" - "github.com/TelegramExchange/tgex-parser/internal/domain" - "github.com/TelegramExchange/tgex-parser/pkg/transaction" + "github.com/TelegramExchange/pkg/transaction" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" ) func (d *Database) CreateViewsSnapshot(ctx context.Context, snapshot domain.ViewsSnapshot) error { diff --git a/tg_parser/internal/adapter/database/delete_post.go b/tg_parser/internal/adapter/database/delete_post.go index 4450e04..b5fc1dc 100644 --- a/tg_parser/internal/adapter/database/delete_post.go +++ b/tg_parser/internal/adapter/database/delete_post.go @@ -6,8 +6,8 @@ import ( "github.com/jackc/pgx/v5/pgtype" - "github.com/TelegramExchange/tgex-parser/internal/domain" - "github.com/TelegramExchange/tgex-parser/pkg/transaction" + "github.com/TelegramExchange/pkg/transaction" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" ) func (d *Database) DeletePost(ctx context.Context, p domain.Post) error { diff --git a/tg_parser/internal/adapter/database/get_channels.go b/tg_parser/internal/adapter/database/get_channels.go index 17fc0d4..c98056b 100644 --- a/tg_parser/internal/adapter/database/get_channels.go +++ b/tg_parser/internal/adapter/database/get_channels.go @@ -6,8 +6,8 @@ import ( "github.com/jackc/pgx/v5/pgtype" "github.com/rs/zerolog/log" - "github.com/TelegramExchange/tgex-parser/internal/domain" - "github.com/TelegramExchange/tgex-parser/pkg/transaction" + "github.com/TelegramExchange/pkg/transaction" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" ) func (d *Database) GetChannels(ctx context.Context) []domain.Channel { diff --git a/tg_parser/internal/adapter/database/get_channels_with_tracked_posts.go b/tg_parser/internal/adapter/database/get_channels_with_tracked_posts.go index 7162f2d..52065d1 100644 --- a/tg_parser/internal/adapter/database/get_channels_with_tracked_posts.go +++ b/tg_parser/internal/adapter/database/get_channels_with_tracked_posts.go @@ -6,8 +6,8 @@ import ( "github.com/jackc/pgx/v5/pgtype" - "github.com/TelegramExchange/tgex-parser/internal/domain" - "github.com/TelegramExchange/tgex-parser/pkg/transaction" + "github.com/TelegramExchange/pkg/transaction" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" ) func (d *Database) GetChannelsWithTrackedPosts(ctx context.Context) ([]domain.Channel, error) { diff --git a/tg_parser/internal/adapter/database/get_tracked_posts.go b/tg_parser/internal/adapter/database/get_tracked_posts.go index 4ba766e..b3b0234 100644 --- a/tg_parser/internal/adapter/database/get_tracked_posts.go +++ b/tg_parser/internal/adapter/database/get_tracked_posts.go @@ -6,8 +6,8 @@ import ( "github.com/jackc/pgx/v5/pgtype" - "github.com/TelegramExchange/tgex-parser/internal/domain" - "github.com/TelegramExchange/tgex-parser/pkg/transaction" + "github.com/TelegramExchange/pkg/transaction" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" ) func (d *Database) GetTrackedPosts(ctx context.Context, channel domain.Channel) ([]domain.Post, error) { diff --git a/tg_parser/internal/adapter/database/update_channel.go b/tg_parser/internal/adapter/database/update_channel.go index 1cdb700..286503a 100644 --- a/tg_parser/internal/adapter/database/update_channel.go +++ b/tg_parser/internal/adapter/database/update_channel.go @@ -6,8 +6,8 @@ import ( "github.com/jackc/pgx/v5/pgtype" - "github.com/TelegramExchange/tgex-parser/internal/domain" - "github.com/TelegramExchange/tgex-parser/pkg/transaction" + "github.com/TelegramExchange/pkg/transaction" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" ) func (d *Database) UpdateChannel(ctx context.Context, channel domain.Channel) error { diff --git a/tg_parser/internal/adapter/telegram/get_active_views.go b/tg_parser/internal/adapter/telegram/get_active_views.go index 278b048..80018d6 100644 --- a/tg_parser/internal/adapter/telegram/get_active_views.go +++ b/tg_parser/internal/adapter/telegram/get_active_views.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/TelegramExchange/tgex-parser/internal/domain" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" "github.com/gotd/td/tg" ) diff --git a/tg_parser/internal/adapter/telegram/get_channel_diff.go b/tg_parser/internal/adapter/telegram/get_channel_diff.go index 3161498..f5c008b 100644 --- a/tg_parser/internal/adapter/telegram/get_channel_diff.go +++ b/tg_parser/internal/adapter/telegram/get_channel_diff.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/TelegramExchange/tgex-parser/internal/domain" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" "github.com/gotd/td/tg" ) diff --git a/tg_parser/internal/adapter/telegram/history.go b/tg_parser/internal/adapter/telegram/history.go index cdfd68e..9bc2854 100644 --- a/tg_parser/internal/adapter/telegram/history.go +++ b/tg_parser/internal/adapter/telegram/history.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/TelegramExchange/tgex-parser/internal/domain" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" "github.com/gotd/td/tg" "github.com/rs/zerolog/log" ) diff --git a/tg_parser/internal/adapter/telegram/resolve.go b/tg_parser/internal/adapter/telegram/resolve.go index ae3dbee..29b0afe 100644 --- a/tg_parser/internal/adapter/telegram/resolve.go +++ b/tg_parser/internal/adapter/telegram/resolve.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/TelegramExchange/tgex-parser/internal/domain" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" "github.com/google/uuid" "github.com/gotd/td/tg" ) diff --git a/tg_parser/internal/adapter/telegram/telegram.go b/tg_parser/internal/adapter/telegram/telegram.go index 13c5540..409497f 100644 --- a/tg_parser/internal/adapter/telegram/telegram.go +++ b/tg_parser/internal/adapter/telegram/telegram.go @@ -1,7 +1,7 @@ package telegram import ( - "github.com/TelegramExchange/tgex-parser/pkg/telegram" + "github.com/TelegramExchange/pkg/telegram" "github.com/gotd/td/tg" ) diff --git a/tg_parser/internal/app/app.go b/tg_parser/internal/app/app.go index 60a1a01..9e77243 100644 --- a/tg_parser/internal/app/app.go +++ b/tg_parser/internal/app/app.go @@ -12,15 +12,15 @@ import ( "github.com/rs/zerolog/log" - "github.com/TelegramExchange/tgex-parser/config" - "github.com/TelegramExchange/tgex-parser/internal/adapter/database" - tgadapter "github.com/TelegramExchange/tgex-parser/internal/adapter/telegram" - "github.com/TelegramExchange/tgex-parser/internal/controller/httpserver" - "github.com/TelegramExchange/tgex-parser/internal/controller/worker" - "github.com/TelegramExchange/tgex-parser/internal/usecase" - "github.com/TelegramExchange/tgex-parser/pkg/postgres" - "github.com/TelegramExchange/tgex-parser/pkg/telegram" - "github.com/TelegramExchange/tgex-parser/pkg/transaction" + "github.com/TelegramExchange/pkg/postgres" + "github.com/TelegramExchange/pkg/telegram" + "github.com/TelegramExchange/pkg/transaction" + "github.com/TelegramExchange/tgex-backend/tg_parser/config" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/adapter/database" + tgadapter "github.com/TelegramExchange/tgex-backend/tg_parser/internal/adapter/telegram" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/controller/httpserver" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/controller/worker" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/usecase" ) func Run(ctx context.Context, c config.Config) error { diff --git a/tg_parser/internal/controller/httpserver/server.go b/tg_parser/internal/controller/httpserver/server.go index 62f9c0b..bbbeb11 100644 --- a/tg_parser/internal/controller/httpserver/server.go +++ b/tg_parser/internal/controller/httpserver/server.go @@ -6,7 +6,7 @@ import ( "net/http" "strings" - "github.com/TelegramExchange/tgex-parser/internal/usecase" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/usecase" "github.com/gotd/td/tgerr" "github.com/rs/zerolog/log" ) diff --git a/tg_parser/internal/controller/worker/channel_worker.go b/tg_parser/internal/controller/worker/channel_worker.go index 0103566..e7ad34e 100644 --- a/tg_parser/internal/controller/worker/channel_worker.go +++ b/tg_parser/internal/controller/worker/channel_worker.go @@ -7,7 +7,7 @@ import ( "github.com/rs/zerolog/log" - "github.com/TelegramExchange/tgex-parser/internal/usecase" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/usecase" ) type ChannelConfig struct { diff --git a/tg_parser/internal/controller/worker/views_worker.go b/tg_parser/internal/controller/worker/views_worker.go index ae76224..2ae9bce 100644 --- a/tg_parser/internal/controller/worker/views_worker.go +++ b/tg_parser/internal/controller/worker/views_worker.go @@ -6,7 +6,7 @@ import ( "github.com/rs/zerolog/log" - "github.com/TelegramExchange/tgex-parser/internal/usecase" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/usecase" ) type ViewsConfig struct { diff --git a/tg_parser/internal/usecase/fetch_channel_meta.go b/tg_parser/internal/usecase/fetch_channel_meta.go index 3dde6fd..0fbf8a3 100644 --- a/tg_parser/internal/usecase/fetch_channel_meta.go +++ b/tg_parser/internal/usecase/fetch_channel_meta.go @@ -3,7 +3,7 @@ package usecase import ( "context" - "github.com/TelegramExchange/tgex-parser/internal/domain" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" ) func (uc *UseCase) FetchChannelMeta(ctx context.Context, username string) (domain.Channel, error) { diff --git a/tg_parser/internal/usecase/fetch_channels.go b/tg_parser/internal/usecase/fetch_channels.go index 9d9c267..10fa36b 100644 --- a/tg_parser/internal/usecase/fetch_channels.go +++ b/tg_parser/internal/usecase/fetch_channels.go @@ -4,10 +4,10 @@ import ( "context" "fmt" - "github.com/TelegramExchange/tgex-parser/pkg/transaction" + "github.com/TelegramExchange/pkg/transaction" "github.com/rs/zerolog/log" - "github.com/TelegramExchange/tgex-parser/internal/domain" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" ) func (uc *UseCase) FetchChannels(ctx context.Context) error { diff --git a/tg_parser/internal/usecase/fetch_views.go b/tg_parser/internal/usecase/fetch_views.go index 3015613..3a75d9e 100644 --- a/tg_parser/internal/usecase/fetch_views.go +++ b/tg_parser/internal/usecase/fetch_views.go @@ -6,7 +6,7 @@ import ( "github.com/rs/zerolog/log" - "github.com/TelegramExchange/tgex-parser/internal/domain" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" ) func (uc *UseCase) FetchViews(ctx context.Context) error { diff --git a/tg_parser/internal/usecase/usecase.go b/tg_parser/internal/usecase/usecase.go index 2acaee1..a98b498 100644 --- a/tg_parser/internal/usecase/usecase.go +++ b/tg_parser/internal/usecase/usecase.go @@ -3,7 +3,7 @@ package usecase import ( "context" - "github.com/TelegramExchange/tgex-parser/internal/domain" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/domain" ) type Telegram interface { diff --git a/tg_parser/main.go b/tg_parser/main.go index 232b1f4..a9e2aaf 100644 --- a/tg_parser/main.go +++ b/tg_parser/main.go @@ -5,9 +5,9 @@ import ( "github.com/rs/zerolog/log" - "github.com/TelegramExchange/tgex-parser/config" - "github.com/TelegramExchange/tgex-parser/internal/app" - "github.com/TelegramExchange/tgex-parser/pkg/logger" + "github.com/TelegramExchange/pkg/logger" + "github.com/TelegramExchange/tgex-backend/tg_parser/config" + "github.com/TelegramExchange/tgex-backend/tg_parser/internal/app" ) func main() {