add ping
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Владимир Фёдоров 2023-09-14 02:20:02 +07:00
parent 16eb438ad1
commit a91af5b68a
2 changed files with 38 additions and 2 deletions

View File

@ -4,13 +4,13 @@ import (
"context"
"os"
"github.com/joho/godotenv"
"git.3crabs.ru/VLADIMIR/butler/internal/modules/messenger/telegram"
"git.3crabs.ru/VLADIMIR/butler/internal/modules/storage/postgres"
"git.3crabs.ru/VLADIMIR/butler/internal/services/bot"
"git.3crabs.ru/VLADIMIR/butler/internal/services/bot/bot_all"
"git.3crabs.ru/VLADIMIR/butler/internal/services/bot/bot_ping"
"git.3crabs.ru/VLADIMIR/butler/internal/services/listener"
"github.com/joho/godotenv"
)
func main() {
@ -35,6 +35,7 @@ func main() {
messengerTelegram,
[]bot.IBot{
bot_all.NewBotAll(messengerTelegram, storage),
bot_ping.NewBotPing(messengerTelegram),
},
)
ctx := context.Background()

View File

@ -0,0 +1,35 @@
package bot_ping
import (
"context"
"strings"
"git.3crabs.ru/VLADIMIR/butler/internal/modules/messenger"
"git.3crabs.ru/VLADIMIR/butler/internal/services/bot"
)
type botPing struct {
messenger messenger.IMessenger
}
func NewBotPing(
messenger messenger.IMessenger,
) bot.IBot {
return &botPing{
messenger: messenger,
}
}
func (bot *botPing) Process(ctx context.Context, msg *messenger.Message) error {
if !strings.Contains(msg.Text, "/ping") {
return nil
}
bot.messenger.SendMessage(
ctx,
&messenger.Message{
ChatID: msg.ChatID,
Text: "pong",
},
)
return nil
}