commit 973c19f148cd0ebbab4963e8d5adb63bba5d320c Author: xeon Date: Fri Aug 21 23:53:17 2026 +0300 init diff --git a/.env b/.env new file mode 100644 index 0000000..66dde18 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +BOT_TOKEN=8978257540:AAEzAXLT1ylVlC-y0AtoM_FXtTMntbpYg60 \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..397794a --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module spambot + +go 1.26.5 + +require ( + github.com/go-telegram/bot v1.23.0 // indirect + github.com/joho/godotenv v1.5.1 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..348354b --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/go-telegram/bot v1.23.0 h1:CKKQq115G/GUGBG8uuWl5uXbiBHyVjZBp/qqOLWZjJk= +github.com/go-telegram/bot v1.23.0/go.mod h1:i2TRs7fXWIeaceF3z7KzsMt/he0TwkVC680mvdTFYeM= +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= diff --git a/internal/bot/bot.go b/internal/bot/bot.go new file mode 100644 index 0000000..7392b56 --- /dev/null +++ b/internal/bot/bot.go @@ -0,0 +1,35 @@ +package bot + +import ( + "context" + "log" + "spambot/internal/commands" + "spambot/internal/config" + + "github.com/go-telegram/bot" +) + +type TelegramBot struct { + config *config.Config + bot *bot.Bot + ctx context.Context +} + +func NewTelegramBot(config *config.Config) *TelegramBot { + b, err := bot.New(config.Token) + + b.RegisterHandler(bot.HandlerTypeMessageText, "/start", bot.MatchTypeExact, commands.StartCommand) + + if err != nil { + log.Fatalf("Failed to create bot: %v", err) + } + return &TelegramBot{ + config: config, + bot: b, + ctx: context.Background(), + } +} + +func (b *TelegramBot) Start() { + b.bot.Start(b.ctx) +} diff --git a/internal/commands/start.go b/internal/commands/start.go new file mode 100644 index 0000000..592d486 --- /dev/null +++ b/internal/commands/start.go @@ -0,0 +1,15 @@ +package commands + +import ( + "context" + + "github.com/go-telegram/bot" + "github.com/go-telegram/bot/models" +) + +func StartCommand(ctx context.Context, b *bot.Bot, update *models.Update) { + b.SendMessage(ctx, &bot.SendMessageParams{ + ChatID: update.Message.Chat.ID, + Text: "Hello, world!", + }) +} diff --git a/internal/config/config.go b/internal/config/config.go new file mode 100644 index 0000000..9b4b967 --- /dev/null +++ b/internal/config/config.go @@ -0,0 +1,20 @@ +package config + +import ( + "os" + + "github.com/joho/godotenv" +) + +type Config struct { + Token string +} + +func NewConfig() *Config { + config := &Config{} + _ = godotenv.Load() + + config.Token = os.Getenv("BOT_TOKEN") + + return config +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..862f7cb --- /dev/null +++ b/main.go @@ -0,0 +1,12 @@ +package main + +import ( + "spambot/internal/bot" + "spambot/internal/config" +) + +func main() { + config := config.NewConfig() + bot := bot.NewTelegramBot(config) + bot.Start() +}