refactor
This commit is contained in:
@@ -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:
|
||||
|
||||
9
pkg/go.mod
Normal file
9
pkg/go.mod
Normal file
@@ -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
|
||||
)
|
||||
13
pkg/go.sum
Normal file
13
pkg/go.sum
Normal file
@@ -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=
|
||||
@@ -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"
|
||||
@@ -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
|
||||
}
|
||||
@@ -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")
|
||||
}
|
||||
@@ -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"]
|
||||
CMD ["/tg_bot"]
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
@@ -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 {
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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 = `
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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 = `
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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{}
|
||||
@@ -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{}
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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 {
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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 (
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package telegram
|
||||
|
||||
import (
|
||||
"github.com/TelegramExchange/tgex-parser/pkg/telegram"
|
||||
"github.com/TelegramExchange/pkg/telegram"
|
||||
"github.com/gotd/td/tg"
|
||||
)
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user