Skip to content

Commit

Permalink
Merge pull request tucnak#377 from omar-polo/v2
Browse files Browse the repository at this point in the history
implements voice chat service messages
  • Loading branch information
tucnak authored and demget committed Jul 25, 2021
1 parent 1b57dbc commit 8261689
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 46 deletions.
87 changes: 45 additions & 42 deletions admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ import (

// Rights is a list of privileges available to chat members.
type Rights struct {
CanBeEdited bool `json:"can_be_edited"`
CanChangeInfo bool `json:"can_change_info"`
CanPostMessages bool `json:"can_post_messages"`
CanEditMessages bool `json:"can_edit_messages"`
CanDeleteMessages bool `json:"can_delete_messages"`
CanInviteUsers bool `json:"can_invite_users"`
CanRestrictMembers bool `json:"can_restrict_members"`
CanPinMessages bool `json:"can_pin_messages"`
CanPromoteMembers bool `json:"can_promote_members"`
CanSendMessages bool `json:"can_send_messages"`
CanSendMedia bool `json:"can_send_media_messages"`
CanSendPolls bool `json:"can_send_polls"`
CanSendOther bool `json:"can_send_other_messages"`
CanAddPreviews bool `json:"can_add_web_page_previews"`
CanBeEdited bool `json:"can_be_edited"`
CanChangeInfo bool `json:"can_change_info"`
CanPostMessages bool `json:"can_post_messages"`
CanEditMessages bool `json:"can_edit_messages"`
CanDeleteMessages bool `json:"can_delete_messages"`
CanInviteUsers bool `json:"can_invite_users"`
CanRestrictMembers bool `json:"can_restrict_members"`
CanPinMessages bool `json:"can_pin_messages"`
CanPromoteMembers bool `json:"can_promote_members"`
CanSendMessages bool `json:"can_send_messages"`
CanSendMedia bool `json:"can_send_media_messages"`
CanSendPolls bool `json:"can_send_polls"`
CanSendOther bool `json:"can_send_other_messages"`
CanAddPreviews bool `json:"can_add_web_page_previews"`
CanManageVoiceChats bool `json:"can_manage_voice_chats"`
}

// NoRights is the default Rights{}.
Expand All @@ -35,40 +36,42 @@ func NoRights() Rights { return Rights{} }
//
func NoRestrictions() Rights {
return Rights{
CanBeEdited: true,
CanChangeInfo: false,
CanPostMessages: false,
CanEditMessages: false,
CanDeleteMessages: false,
CanInviteUsers: false,
CanRestrictMembers: false,
CanPinMessages: false,
CanPromoteMembers: false,
CanSendMessages: true,
CanSendMedia: true,
CanSendPolls: true,
CanSendOther: true,
CanAddPreviews: true,
CanBeEdited: true,
CanChangeInfo: false,
CanPostMessages: false,
CanEditMessages: false,
CanDeleteMessages: false,
CanInviteUsers: false,
CanRestrictMembers: false,
CanPinMessages: false,
CanPromoteMembers: false,
CanSendMessages: true,
CanSendMedia: true,
CanSendPolls: true,
CanSendOther: true,
CanAddPreviews: true,
CanManageVoiceChats: false,
}
}

// AdminRights could be used to promote user to admin.
func AdminRights() Rights {
return Rights{
CanBeEdited: true,
CanChangeInfo: true,
CanPostMessages: true,
CanEditMessages: true,
CanDeleteMessages: true,
CanInviteUsers: true,
CanRestrictMembers: true,
CanPinMessages: true,
CanPromoteMembers: true,
CanSendMessages: true,
CanSendMedia: true,
CanSendPolls: true,
CanSendOther: true,
CanAddPreviews: true,
CanBeEdited: true,
CanChangeInfo: true,
CanPostMessages: true,
CanEditMessages: true,
CanDeleteMessages: true,
CanInviteUsers: true,
CanRestrictMembers: true,
CanPinMessages: true,
CanPromoteMembers: true,
CanSendMessages: true,
CanSendMedia: true,
CanSendPolls: true,
CanSendOther: true,
CanAddPreviews: true,
CanManageVoiceChats: true,
}
}

Expand Down
15 changes: 15 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,21 @@ func (b *Bot) ProcessUpdate(upd Update) {
b.handle(OnMigration, c)
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 {
Expand Down
8 changes: 4 additions & 4 deletions bot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestNewBot(t *testing.T) {
_, err = NewBot(pref)
assert.Error(t, err)

b, err := NewBot(Settings{offline: true})
b, err := NewBot(Settings{Offline: true})
if err != nil {
t.Fatal(err)
}
Expand All @@ -66,7 +66,7 @@ func TestNewBot(t *testing.T) {
pref.Poller = &LongPoller{Timeout: time.Second}
pref.Updates = 50
pref.ParseMode = ModeHTML
pref.offline = true
pref.Offline = true

b, err = NewBot(pref)
require.NoError(t, err)
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestBotStart(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 {
t.Fatal(err)
}
Expand Down Expand Up @@ -340,7 +340,7 @@ func TestBotProcessUpdate(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 {
t.Fatal(err)
}
Expand Down
9 changes: 9 additions & 0 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ type Message struct {

// Inline keyboard attached to the message.
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,
Expand Down
15 changes: 15 additions & 0 deletions telebot.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ const (
//
// Handler: func(*PollAnswer)
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.
Expand Down
17 changes: 17 additions & 0 deletions voicechat.go
Original file line number Diff line number Diff line change
@@ -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"`
}

0 comments on commit 8261689

Please sign in to comment.