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