init
This commit is contained in:
commit
973c19f148
7 changed files with 95 additions and 0 deletions
35
internal/bot/bot.go
Normal file
35
internal/bot/bot.go
Normal 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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue