Merge pull request #377 from omar-polo/v2

implements voice chat service messages
pull/425/head
Ian P Badtrousers 3 years ago committed by Demian
parent 1b57dbc404
commit 8261689cda

@ -8,20 +8,21 @@ import (
// Rights is a list of privileges available to chat members. // Rights is a list of privileges available to chat members.
type Rights struct { type Rights struct {
CanBeEdited bool `json:"can_be_edited"` CanBeEdited bool `json:"can_be_edited"`
CanChangeInfo bool `json:"can_change_info"` CanChangeInfo bool `json:"can_change_info"`
CanPostMessages bool `json:"can_post_messages"` CanPostMessages bool `json:"can_post_messages"`
CanEditMessages bool `json:"can_edit_messages"` CanEditMessages bool `json:"can_edit_messages"`
CanDeleteMessages bool `json:"can_delete_messages"` CanDeleteMessages bool `json:"can_delete_messages"`
CanInviteUsers bool `json:"can_invite_users"` CanInviteUsers bool `json:"can_invite_users"`
CanRestrictMembers bool `json:"can_restrict_members"` CanRestrictMembers bool `json:"can_restrict_members"`
CanPinMessages bool `json:"can_pin_messages"` CanPinMessages bool `json:"can_pin_messages"`
CanPromoteMembers bool `json:"can_promote_members"` CanPromoteMembers bool `json:"can_promote_members"`
CanSendMessages bool `json:"can_send_messages"` CanSendMessages bool `json:"can_send_messages"`
CanSendMedia bool `json:"can_send_media_messages"` CanSendMedia bool `json:"can_send_media_messages"`
CanSendPolls bool `json:"can_send_polls"` CanSendPolls bool `json:"can_send_polls"`
CanSendOther bool `json:"can_send_other_messages"` CanSendOther bool `json:"can_send_other_messages"`
CanAddPreviews bool `json:"can_add_web_page_previews"` CanAddPreviews bool `json:"can_add_web_page_previews"`
CanManageVoiceChats bool `json:"can_manage_voice_chats"`
} }
// NoRights is the default Rights{}. // NoRights is the default Rights{}.
@ -35,40 +36,42 @@ func NoRights() Rights { return Rights{} }
// //
func NoRestrictions() Rights { func NoRestrictions() Rights {
return Rights{ return Rights{
CanBeEdited: true, CanBeEdited: true,
CanChangeInfo: false, CanChangeInfo: false,
CanPostMessages: false, CanPostMessages: false,
CanEditMessages: false, CanEditMessages: false,
CanDeleteMessages: false, CanDeleteMessages: false,
CanInviteUsers: false, CanInviteUsers: false,
CanRestrictMembers: false, CanRestrictMembers: false,
CanPinMessages: false, CanPinMessages: false,
CanPromoteMembers: false, CanPromoteMembers: false,
CanSendMessages: true, CanSendMessages: true,
CanSendMedia: true, CanSendMedia: true,
CanSendPolls: true, CanSendPolls: true,
CanSendOther: true, CanSendOther: true,
CanAddPreviews: true, CanAddPreviews: true,
CanManageVoiceChats: false,
} }
} }
// AdminRights could be used to promote user to admin. // AdminRights could be used to promote user to admin.
func AdminRights() Rights { func AdminRights() Rights {
return Rights{ return Rights{
CanBeEdited: true, CanBeEdited: true,
CanChangeInfo: true, CanChangeInfo: true,
CanPostMessages: true, CanPostMessages: true,
CanEditMessages: true, CanEditMessages: true,
CanDeleteMessages: true, CanDeleteMessages: true,
CanInviteUsers: true, CanInviteUsers: true,
CanRestrictMembers: true, CanRestrictMembers: true,
CanPinMessages: true, CanPinMessages: true,
CanPromoteMembers: true, CanPromoteMembers: true,
CanSendMessages: true, CanSendMessages: true,
CanSendMedia: true, CanSendMedia: true,
CanSendPolls: true, CanSendPolls: true,
CanSendOther: true, CanSendOther: true,
CanAddPreviews: true, CanAddPreviews: true,
CanManageVoiceChats: true,
} }
} }

@ -349,6 +349,21 @@ func (b *Bot) ProcessUpdate(upd Update) {
b.handle(OnMigration, c) b.handle(OnMigration, c)
return return
} }
if m.VoiceChatStarted != nil {
b.handle(OnVoiceChatStarted, c)
return
}
if m.VoiceChatEnded != nil {
b.handle(OnVoiceChatEnded, c)
return
}
if m.VoiceChatParticipants != nil {
b.handle(OnVoiceChatParticipants, c)
return
}
} }
if upd.EditedMessage != nil { if upd.EditedMessage != nil {

@ -49,7 +49,7 @@ func TestNewBot(t *testing.T) {
_, err = NewBot(pref) _, err = NewBot(pref)
assert.Error(t, err) assert.Error(t, err)
b, err := NewBot(Settings{offline: true}) b, err := NewBot(Settings{Offline: true})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -66,7 +66,7 @@ func TestNewBot(t *testing.T) {
pref.Poller = &LongPoller{Timeout: time.Second} pref.Poller = &LongPoller{Timeout: time.Second}
pref.Updates = 50 pref.Updates = 50
pref.ParseMode = ModeHTML pref.ParseMode = ModeHTML
pref.offline = true pref.Offline = true
b, err = NewBot(pref) b, err = NewBot(pref)
require.NoError(t, err) require.NoError(t, err)
@ -147,7 +147,7 @@ func TestBotStart(t *testing.T) {
} }
func TestBotProcessUpdate(t *testing.T) { func TestBotProcessUpdate(t *testing.T) {
b, err := NewBot(Settings{Synchronous: true, offline: true}) b, err := NewBot(Settings{Synchronous: true, Offline: true})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -340,7 +340,7 @@ func TestBotProcessUpdate(t *testing.T) {
} }
func TestBotOnError(t *testing.T) { func TestBotOnError(t *testing.T) {
b, err := NewBot(Settings{Synchronous: true, offline: true}) b, err := NewBot(Settings{Synchronous: true, Offline: true})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

@ -217,6 +217,15 @@ type Message struct {
// Inline keyboard attached to the message. // Inline keyboard attached to the message.
ReplyMarkup InlineKeyboardMarkup `json:"reply_markup"` ReplyMarkup InlineKeyboardMarkup `json:"reply_markup"`
// For a service message, a voice chat started in the chat.
VoiceChatStarted *VoiceChatStarted `json:"voice_chat_started,omitempty"`
// For a service message, a voice chat ended in the chat.
VoiceChatEnded *VoiceChatEnded `json:"voice_chat_ended,omitempty"`
// For a service message, some users were invited in the voice chat.
VoiceChatParticipants *VoiceChatParticipants `json:"voice_chat_participants_invited,omitempty"`
} }
// MessageEntity object represents "special" parts of text messages, // MessageEntity object represents "special" parts of text messages,

@ -121,6 +121,21 @@ const (
// //
// Handler: func(*PollAnswer) // Handler: func(*PollAnswer)
OnPollAnswer = "\apoll_answer" OnPollAnswer = "\apoll_answer"
// Will fire on VoiceChatStarted
//
// Handler: func(*Message)
OnVoiceChatStarted = "\avoice_chat_started"
// Will fire on VoiceChatEnded
//
// Handler: func(*Message)
OnVoiceChatEnded = "\avoice_chat_ended"
// Will fire on VoiceChatParticipants
//
// Handler: func(*Message)
OnVoiceChatParticipants = "\avoice_chat_participants_invited"
) )
// ChatAction is a client-side status indicating bot activity. // ChatAction is a client-side status indicating bot activity.

@ -0,0 +1,17 @@
package telebot
// VoiceChatStarted represents a service message about a voice chat
// started in the chat.
type VoiceChatStarted struct{}
// VoiceChatEnded represents a service message about a voice chat
// ended in the chat.
type VoiceChatEnded struct {
Duration int `json:"duration"`
}
// VoiceChatParticipants represents a service message about new
// members invited to a voice chat
type VoiceChatParticipants struct {
Users []User `json:"users"`
}
Loading…
Cancel
Save