add ping
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
16eb438ad1
commit
a91af5b68a
|
@ -4,13 +4,13 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
|
||||||
|
|
||||||
"git.3crabs.ru/VLADIMIR/butler/internal/modules/messenger/telegram"
|
"git.3crabs.ru/VLADIMIR/butler/internal/modules/messenger/telegram"
|
||||||
"git.3crabs.ru/VLADIMIR/butler/internal/modules/storage/postgres"
|
"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"
|
||||||
"git.3crabs.ru/VLADIMIR/butler/internal/services/bot/bot_all"
|
"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"
|
"git.3crabs.ru/VLADIMIR/butler/internal/services/listener"
|
||||||
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -35,6 +35,7 @@ func main() {
|
||||||
messengerTelegram,
|
messengerTelegram,
|
||||||
[]bot.IBot{
|
[]bot.IBot{
|
||||||
bot_all.NewBotAll(messengerTelegram, storage),
|
bot_all.NewBotAll(messengerTelegram, storage),
|
||||||
|
bot_ping.NewBotPing(messengerTelegram),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue