Filters, ChainRun, UserMention
This commit is contained in:
51
update.go
51
update.go
@ -73,6 +73,18 @@ func (u *Update) MessageID() int {
|
||||
log.Fatalf("[%s] Can't get ChatID of update %v+", u.UpdateID, u.U)
|
||||
return 0
|
||||
}
|
||||
func (u *Update) ThreadID() int64 {
|
||||
if !u.Chat().IsForum {
|
||||
return 0
|
||||
}
|
||||
if u.IsMessage() {
|
||||
return int64(u.Message.ThreadID)
|
||||
}
|
||||
if u.IsCallback() {
|
||||
return int64(u.CallbackQuery.Message.ThreadID)
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (u *Update) AnswerText(text string, options *echotron.MessageOptions) (echotron.APIResponseMessage, error) {
|
||||
return u.Bot.SendMessage(text, u.ChatID(), options)
|
||||
@ -83,12 +95,15 @@ func (u *Update) EditText(text string, options *echotron.MessageTextOptions) (ec
|
||||
}
|
||||
|
||||
func (u *Update) AnswerPlain(text string) (echotron.APIResponseMessage, error) {
|
||||
return u.Bot.SendMessage(text, u.ChatID(), &emptyOpts)
|
||||
return u.Bot.SendMessage(text, u.ChatID(), &echotron.MessageOptions{
|
||||
MessageThreadID: u.ThreadID(),
|
||||
})
|
||||
}
|
||||
|
||||
func (u *Update) AnswerMarkdown(text string) (echotron.APIResponseMessage, error) {
|
||||
return u.Bot.SendMessage(text, u.ChatID(), &echotron.MessageOptions{
|
||||
ParseMode: echotron.MarkdownV2,
|
||||
ParseMode: echotron.MarkdownV2,
|
||||
MessageThreadID: u.ThreadID(),
|
||||
})
|
||||
}
|
||||
|
||||
@ -116,6 +131,9 @@ func (u *Update) IsMessage() bool {
|
||||
func (u *Update) IsCallback() bool {
|
||||
return u.CallbackQuery != nil
|
||||
}
|
||||
func (u *Update) IsReply() bool {
|
||||
return u.IsMessage() && u.Message.ReplyToMessage != nil
|
||||
}
|
||||
func (u *Update) IsButton(b *Button) bool {
|
||||
if u.IsText() && u.Text() == b.text {
|
||||
return true
|
||||
@ -192,6 +210,16 @@ func (u *Update) From() *echotron.User {
|
||||
return u.CallbackQuery.From
|
||||
}
|
||||
|
||||
func GetText(u *echotron.Message) string {
|
||||
if u.Text != "" {
|
||||
return u.Text
|
||||
}
|
||||
if u.Caption != "" {
|
||||
return u.Caption
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (u *Update) Text() string {
|
||||
if u.IsText() {
|
||||
return u.Message.Text
|
||||
@ -209,25 +237,6 @@ func (u *Update) Entities() []*echotron.MessageEntity {
|
||||
return u.Message.CaptionEntities
|
||||
}
|
||||
|
||||
func IsUserAdmin(u *Update) bool {
|
||||
if IsPrivate(u) {
|
||||
return true
|
||||
}
|
||||
member, err := u.Bot.GetChatMember(u.ChatID(), u.From().ID)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return member.Result.Status == "administrator" || member.Result.Status == "creator"
|
||||
}
|
||||
|
||||
func IsPrivate(u *Update) bool {
|
||||
return u.ChatID() > 0
|
||||
}
|
||||
|
||||
func IsForum(u *Update) bool {
|
||||
return u.Chat().IsForum
|
||||
}
|
||||
|
||||
func (u *Update) LogError(text string, e error, send bool) {
|
||||
if text != "" {
|
||||
text = "Ошибка: " + text
|
||||
|
Reference in New Issue
Block a user