♻️ Added new stuff, maked small fixes
This commit is contained in:
parent
f4551f07e3
commit
90a7dec4be
16
constants.go
16
constants.go
|
@ -35,10 +35,12 @@ const (
|
|||
)
|
||||
|
||||
const (
|
||||
MethodAddStickerToSet = "addStickerToSet"
|
||||
MethodAnswerCallbackQuery = "answerCallbackQuery"
|
||||
MethodAnswerInlineQuery = "answerInlineQuery"
|
||||
MethodAnswerPreCheckoutQuery = "answerPreCheckoutQuery"
|
||||
MethodAnswerShippingQuery = "answerShippingQuery"
|
||||
MethodCreateNewStickerSet = "createNewStickerSet"
|
||||
MethodDeleteChatPhoto = "deleteChatPhoto"
|
||||
MethodDeleteChatStickerSet = "deleteChatStickerSet"
|
||||
MethodDeleteMessage = "deleteMessage"
|
||||
|
@ -64,6 +66,9 @@ const (
|
|||
MethodKickChatMember = "kickChatMember"
|
||||
MethodLeaveChat = "leaveChat"
|
||||
MethodPinChatMessage = "pinChatMessage"
|
||||
MethodPromoteChatMember = "promoteChatMember"
|
||||
MethodRestrictChatMember = "restrictChatMember"
|
||||
MethodSendAudio = "sendAudio"
|
||||
MethodSendChatAction = "sendChatAction"
|
||||
MethodSendContact = "sendContact"
|
||||
MethodSendDocument = "sendDocument"
|
||||
|
@ -73,7 +78,11 @@ const (
|
|||
MethodSendMediaGroup = "sendMediaGroup"
|
||||
MethodSendMessage = "sendMessage"
|
||||
MethodSendPhoto = "sendPhoto"
|
||||
MethodSendSticker = "sendSticker"
|
||||
MethodSendVenue = "sendVenue"
|
||||
MethodSendVideo = "sendVideo"
|
||||
MethodSendVideoNote = "sendVideoNote"
|
||||
MethodSendVoice = "sendVoice"
|
||||
MethodSetChatDescription = "setChatDescription"
|
||||
MethodSetChatPhoto = "setChatPhoto"
|
||||
MethodSetChatStickerSet = "setChatStickerSet"
|
||||
|
@ -81,8 +90,10 @@ const (
|
|||
MethodSetGameScore = "setGameScore"
|
||||
MethodSetStickerPositionInSet = "setStickerPositionInSet"
|
||||
MethodSetWebhook = "setWebhook"
|
||||
MethodStopMessageLiveLocation = "stopMessageLiveLocation"
|
||||
MethodUnbanChatMember = "unbanChatMember"
|
||||
MethodUnpinChatMessage = "unpinChatMessage"
|
||||
MethodUploadStickerFile = "uploadStickerFile"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -97,7 +108,10 @@ const (
|
|||
MimeZIP = "application/zip"
|
||||
)
|
||||
|
||||
const PrefixAttach = "attach://"
|
||||
const (
|
||||
SchemeAttach = "attach"
|
||||
SchemeTelegram = "tg"
|
||||
)
|
||||
|
||||
const (
|
||||
StatusAdministrator = "administrator"
|
||||
|
|
|
@ -72,7 +72,8 @@ func (bot *Bot) SetWebhook(params *SetWebhookParameters) (bool, error) {
|
|||
if params.Certificate != nil {
|
||||
resp, err = bot.Upload(MethodSetWebhook, "certificate", "cert.pem", params.Certificate, args)
|
||||
} else {
|
||||
dst, err := json.Marshal(params)
|
||||
var dst []byte
|
||||
dst, err = json.Marshal(params)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
13
utils.go
13
utils.go
|
@ -5,21 +5,18 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
func NewForceReply(selective bool) *ForceReply {
|
||||
return &ForceReply{
|
||||
ForceReply: true,
|
||||
Selective: selective,
|
||||
}
|
||||
func NewForceReply() *ForceReply {
|
||||
return &ForceReply{ForceReply: true}
|
||||
}
|
||||
|
||||
func NewInlineMentionURL(id int) *url.URL {
|
||||
func NewInlineMentionURL(userID int) *url.URL {
|
||||
link := &url.URL{
|
||||
Scheme: "tg",
|
||||
Scheme: SchemeTelegram,
|
||||
Path: "user",
|
||||
}
|
||||
|
||||
q := link.Query()
|
||||
q.Add("id", strconv.Itoa(id))
|
||||
q.Add("id", strconv.Itoa(userID))
|
||||
link.RawQuery = q.Encode()
|
||||
|
||||
return link
|
||||
|
|
|
@ -28,7 +28,7 @@ func (bot *Bot) IsMessageFromMe(msg *Message) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
return msg.From.ID == bot.User.ID
|
||||
return msg.From.ID == bot.ID
|
||||
}
|
||||
|
||||
func (bot *Bot) IsForwardFromMe(msg *Message) bool {
|
||||
|
@ -44,7 +44,7 @@ func (bot *Bot) IsForwardFromMe(msg *Message) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
return msg.ForwardFrom.ID == bot.User.ID
|
||||
return msg.ForwardFrom.ID == bot.ID
|
||||
}
|
||||
|
||||
func (bot *Bot) IsReplyToMe(msg *Message) bool {
|
||||
|
@ -99,7 +99,7 @@ func (bot *Bot) IsMessageMentionsMe(msg *Message) bool {
|
|||
|
||||
for _, entity := range entities {
|
||||
if entity.IsMention() {
|
||||
if bot.User.ID == entity.User.ID {
|
||||
if bot.ID == entity.User.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package telegram
|
||||
|
||||
import "fmt"
|
||||
|
||||
func (chat *Chat) IsPrivate() bool {
|
||||
if chat == nil {
|
||||
return false
|
||||
|
@ -39,3 +41,40 @@ func (chat *Chat) HasPinnedMessage() bool {
|
|||
|
||||
return chat.PinnedMessage != nil
|
||||
}
|
||||
|
||||
func (chat *Chat) HasStickerSet() bool {
|
||||
if chat == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return chat.StickerSetName != ""
|
||||
}
|
||||
|
||||
func (chat *Chat) StickerSet(bot *Bot) *StickerSet {
|
||||
if !chat.HasStickerSet() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if bot == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
set, err := bot.GetStickerSet(chat.StickerSetName)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return set
|
||||
}
|
||||
|
||||
func (chat *Chat) FullName() string {
|
||||
if chat == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
if chat.LastName != "" {
|
||||
return fmt.Sprintln(chat.FirstName, chat.LastName)
|
||||
}
|
||||
|
||||
return chat.FirstName
|
||||
}
|
||||
|
|
|
@ -10,28 +10,24 @@ func (entity *MessageEntity) ParseURL(messageText string) *url.URL {
|
|||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
link := new(url.URL)
|
||||
switch {
|
||||
case entity.IsTextLink():
|
||||
link, err = url.Parse(entity.URL)
|
||||
case entity.IsURL():
|
||||
if messageText == "" {
|
||||
return nil
|
||||
}
|
||||
if !entity.IsURL() {
|
||||
return nil
|
||||
}
|
||||
|
||||
rawMessageText := []rune(messageText)
|
||||
if len(rawMessageText) < (entity.Offset + entity.Length) {
|
||||
return nil
|
||||
}
|
||||
if messageText == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
from := entity.Offset
|
||||
to := from + entity.Length
|
||||
rawURL := string([]rune(messageText)[from:to])
|
||||
link, err = url.Parse(rawURL)
|
||||
if err == nil && link.Scheme == "" {
|
||||
link, err = url.Parse(fmt.Sprint("http://", link))
|
||||
}
|
||||
from := entity.Offset
|
||||
to := from + entity.Length
|
||||
text := []rune(messageText)
|
||||
if len(text) < to {
|
||||
return nil
|
||||
}
|
||||
|
||||
link, err := url.Parse(string(text[from:to]))
|
||||
if err == nil && link.Scheme == "" {
|
||||
link, err = url.Parse(fmt.Sprint("http://", link))
|
||||
}
|
||||
if err != nil {
|
||||
return nil
|
||||
|
@ -127,3 +123,16 @@ func (entity *MessageEntity) IsURL() bool {
|
|||
|
||||
return entity.Type == EntityURL
|
||||
}
|
||||
|
||||
func (entity *MessageEntity) TextLink() *url.URL {
|
||||
if entity == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
link, err := url.Parse(entity.URL)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return link
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ func (msg *Message) IsCommand(command string) bool {
|
|||
}
|
||||
|
||||
entity := msg.Entities[0]
|
||||
|
||||
isBotCommand := entity.IsBotCommand() && entity.Offset == 0
|
||||
if command != "" {
|
||||
return isBotCommand && strings.EqualFold(msg.Command(), command)
|
||||
|
@ -107,6 +106,10 @@ func (msg *Message) EditTime() time.Time {
|
|||
}
|
||||
|
||||
func (msg *Message) HasBeenEdited() bool {
|
||||
if msg == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return msg.EditDate > 0
|
||||
}
|
||||
|
||||
|
@ -141,6 +144,7 @@ func (msg *Message) IsSticker() bool {
|
|||
func (msg *Message) IsVideo() bool {
|
||||
return !msg.IsText() && msg.Video != nil
|
||||
}
|
||||
|
||||
func (msg *Message) IsVoice() bool {
|
||||
return !msg.IsText() && msg.Voice != nil
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ func (user *User) FullName() string {
|
|||
}
|
||||
|
||||
if user.LastName != "" {
|
||||
return fmt.Sprint(user.FirstName, " ", user.LastName)
|
||||
return fmt.Sprintln(user.FirstName, user.LastName)
|
||||
}
|
||||
|
||||
return user.FirstName
|
||||
|
|
Loading…
Reference in New Issue