2017-11-23 08:59:25 +00:00
|
|
|
package telegram
|
|
|
|
|
2018-01-29 09:06:40 +00:00
|
|
|
import (
|
2018-06-20 13:40:07 +00:00
|
|
|
"fmt"
|
2018-01-29 09:06:40 +00:00
|
|
|
"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 {
|
|
|
|
return fmt.Sprint("*", text, "*")
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMarkdownItalic(text string) string {
|
|
|
|
return fmt.Sprint("_", text, "_")
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMarkdownURL(text string, link *url.URL) string {
|
|
|
|
return fmt.Sprint("[", text, "](", link.String(), ")")
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return fmt.Sprint("`", text, "`")
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewMarkdownCodeBlock(text string) string {
|
|
|
|
return fmt.Sprint("```", text, "```")
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHtmlBold(text string) string {
|
|
|
|
return fmt.Sprint("<b>", text, "</b>")
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHtmlItalic(text string) string {
|
|
|
|
return fmt.Sprint("<i>", text, "</i>")
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHtmlURL(text string, link *url.URL) string {
|
|
|
|
return fmt.Sprint(`<a href="`, link.String(), `">`, text, `</a>`)
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
return fmt.Sprint("<code>", text, "</code>")
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewHtmlCodeBlock(text string) string {
|
|
|
|
return fmt.Sprint("<pre>", text, "</pre>")
|
|
|
|
}
|