35 lines
662 B
Go
35 lines
662 B
Go
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)
|
|
}
|