1
0
telegram/utils.go

76 lines
1.5 KiB
Go
Raw Normal View History

package telegram
import (
"net/url"
"strconv"
)
2018-04-19 13:02:15 +00:00
// NewForceReply calls the response interface to the message.
func NewForceReply() *ForceReply {
return &ForceReply{ForceReply: true}
}
2018-04-19 13:02:15 +00:00
// NewInlineMentionURL creates a url.URL for the mention user without username.
func NewInlineMentionURL(userID int) *url.URL {
link := &url.URL{
Scheme: SchemeTelegram,
Path: "user",
}
q := link.Query()
q.Add("id", strconv.Itoa(userID))
link.RawQuery = q.Encode()
return link
}
2018-06-20 13:40:07 +00:00
func NewMarkdownBold(text string) string {
2018-08-21 11:05:04 +00:00
return "*" + text + "*"
2018-06-20 13:40:07 +00:00
}
func NewMarkdownItalic(text string) string {
2018-08-21 11:05:04 +00:00
return "_" + text + "_"
2018-06-20 13:40:07 +00:00
}
func NewMarkdownURL(text string, link *url.URL) string {
2018-08-21 11:05:04 +00:00
return "[" + text + "](" + link.String() + ")"
2018-06-20 13:40:07 +00:00
}
func NewMarkdownMention(text string, id int) string {
link := NewInlineMentionURL(id)
return NewMarkdownURL(text, link)
2018-06-20 13:40:07 +00:00
}
func NewMarkdownCode(text string) string {
2018-08-21 11:05:04 +00:00
return "`" + text + "`"
2018-06-20 13:40:07 +00:00
}
func NewMarkdownCodeBlock(text string) string {
2018-08-21 11:05:04 +00:00
return "```" + text + "```"
2018-06-20 13:40:07 +00:00
}
func NewHtmlBold(text string) string {
2018-08-21 11:05:04 +00:00
return "<b>" + text + "</b>"
2018-06-20 13:40:07 +00:00
}
func NewHtmlItalic(text string) string {
2018-08-21 11:05:04 +00:00
return "<i>" + text + "</i>"
2018-06-20 13:40:07 +00:00
}
func NewHtmlURL(text string, link *url.URL) string {
2018-08-21 11:05:04 +00:00
return `<a href="` + link.String() + `">` + text + `</a>`
2018-06-20 13:40:07 +00:00
}
func NewHtmlMention(text string, id int) string {
link := NewInlineMentionURL(id)
return NewHtmlURL(text, link)
2018-06-20 13:40:07 +00:00
}
func NewHtmlCode(text string) string {
2018-08-21 11:05:04 +00:00
return "<code>" + text + "</code>"
2018-06-20 13:40:07 +00:00
}
func NewHtmlCodeBlock(text string) string {
2018-08-21 11:05:04 +00:00
return "<pre>" + text + "</pre>"
2018-06-20 13:40:07 +00:00
}