1
0
Fork 0
telegram/utils.go

70 lines
1.5 KiB
Go
Raw Normal View History

package telegram
import http "github.com/valyala/fasthttp"
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) *http.URI {
link := http.AcquireURI()
link.SetScheme(SchemeTelegram)
link.SetPath("user")
q := link.QueryArgs()
q.SetUint("id", userID)
link.SetQueryStringBytes(q.QueryString())
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 *http.URI) 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 {
return NewMarkdownURL(text, NewInlineMentionURL(id))
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 *http.URI) 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 {
return NewHtmlURL(text, NewInlineMentionURL(id))
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
}