Files
muninn-aio/handlers.go

46 lines
1.6 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"context"
"fmt"
"net/url"
"code.gurenya.net/carlsmei/muninn-aio/services"
"github.com/go-telegram/bot"
"github.com/go-telegram/bot/models"
)
func generateLinkHandler(ctx context.Context, b *bot.Bot, update *models.Update) {
user, err := services.GetOrCreateUser(ctx, update.Message.From.ID)
if err != nil {
panic(err)
}
link, err := services.CreateLink(ctx, user, update.Message.Text, "")
if err != nil {
panic(err)
}
url, err := url.Parse("http://localhost:3000")
url.Path = link.Key
if err != nil {
panic(err)
}
b.SendMessage(ctx, &bot.SendMessageParams{
ChatID: update.Message.Chat.ID,
Text: fmt.Sprintf("Ваша короткая ссылка готова - %s", url.String()),
ParseMode: models.ParseModeHTML,
})
}
func startHandler(ctx context.Context, b *bot.Bot, update *models.Update) {
b.SendMessage(ctx, &bot.SendMessageParams{
ChatID: update.Message.Chat.ID,
Text: fmt.Sprintf("Привет! Я Muninn, бот для укорачивания ссылок.\n\nВ данный момент у меня нет особых возможностей, но в скором времени что-нибудь да появится.\n\nЭто быстренький прототип написанный за ночь, в оригинальной версии сервис делится на части и состоит из разных приложений взаимодействующих между собой :/\n\nVersion: %s\nRepository: https://code.gurenya.net/carlsmei/muninn-aio", Version),
})
}