2017-11-23 08:59:25 +00:00
|
|
|
package telegram
|
|
|
|
|
2018-01-29 09:06:40 +00:00
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2018-04-19 13:02:15 +00:00
|
|
|
// NewForceReply calls the response interface to the message.
|
2018-04-12 12:56:53 +00:00
|
|
|
func NewForceReply() *ForceReply {
|
|
|
|
return &ForceReply{ForceReply: true}
|
2017-11-23 08:59:25 +00:00
|
|
|
}
|
2018-01-29 09:06:40 +00:00
|
|
|
|
2018-04-19 13:02:15 +00:00
|
|
|
// NewInlineMentionURL creates a url.URL for the mention user without username.
|
2018-04-12 12:56:53 +00:00
|
|
|
func NewInlineMentionURL(userID int) *url.URL {
|
2018-01-29 09:06:40 +00:00
|
|
|
link := &url.URL{
|
2018-04-12 12:56:53 +00:00
|
|
|
Scheme: SchemeTelegram,
|
2018-01-29 09:06:40 +00:00
|
|
|
Path: "user",
|
|
|
|
}
|
|
|
|
|
|
|
|
q := link.Query()
|
2018-04-12 12:56:53 +00:00
|
|
|
q.Add("id", strconv.Itoa(userID))
|
2018-01-29 09:06:40 +00:00
|
|
|
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 {
|
2018-06-20 13:48:48 +00:00
|
|
|
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 {
|
2018-06-20 13:48:48 +00:00
|
|
|
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
|
|
|
}
|