This commit is contained in:
xeon 2026-08-21 23:53:17 +03:00
commit 973c19f148
7 changed files with 95 additions and 0 deletions

35
internal/bot/bot.go Normal file
View file

@ -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)
}

View file

@ -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!",
})
}

20
internal/config/config.go Normal file
View file

@ -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
}