Skip to content

Commit

Permalink
API 6.7
Browse files Browse the repository at this point in the history
  • Loading branch information
reloadlife committed Jun 7, 2023
1 parent a89444b commit 7b3b210
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 91 deletions.
52 changes: 35 additions & 17 deletions admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,24 @@ type Rights struct {
// Anonymous is true, if the user's presence in the chat is hidden.
Anonymous bool `json:"is_anonymous"`

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"`
CanPinMessages bool `json:"can_pin_messages"`
CanInviteUsers bool `json:"can_invite_users"`
CanRestrictMembers bool `json:"can_restrict_members"`
CanPromoteMembers bool `json:"can_promote_members"`
CanSendMessages bool `json:"can_send_messages"`
CanSendMedia bool `json:"can_send_media_messages"`
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"`
CanPinMessages bool `json:"can_pin_messages"`
CanInviteUsers bool `json:"can_invite_users"`
CanRestrictMembers bool `json:"can_restrict_members"`
CanPromoteMembers bool `json:"can_promote_members"`
CanSendMessages bool `json:"can_send_messages"`

CanSendAudios bool `json:"can_send_audios"`
CanSendDocuments bool `json:"can_send_documents"`
CanSendPhotos bool `json:"can_send_photos"`
CanSendVideos bool `json:"can_send_videos"`
CanSendVideoNotes bool `json:"can_send_video_notes"`
CanSendVoiceNotes bool `json:"can_send_voice_notes"`

CanSendPolls bool `json:"can_send_polls"`
CanSendOther bool `json:"can_send_other_messages"`
CanAddPreviews bool `json:"can_add_web_page_previews"`
Expand Down Expand Up @@ -50,7 +57,12 @@ func NoRestrictions() Rights {
CanPinMessages: false,
CanPromoteMembers: false,
CanSendMessages: true,
CanSendMedia: true,
CanSendAudios: true,
CanSendDocuments: true,
CanSendPhotos: true,
CanSendVideos: true,
CanSendVideoNotes: true,
CanSendVoiceNotes: true,
CanSendPolls: true,
CanSendOther: true,
CanAddPreviews: true,
Expand All @@ -72,7 +84,12 @@ func AdminRights() Rights {
CanPinMessages: true,
CanPromoteMembers: true,
CanSendMessages: true,
CanSendMedia: true,
CanSendAudios: true,
CanSendDocuments: true,
CanSendPhotos: true,
CanSendVideos: true,
CanSendVideoNotes: true,
CanSendVoiceNotes: true,
CanSendPolls: true,
CanSendOther: true,
CanAddPreviews: true,
Expand Down Expand Up @@ -124,13 +141,14 @@ func (b *Bot) Unban(chat *Chat, user *User, forBanned ...bool) error {
// - can send media
// - can send other
// - can add web page previews
func (b *Bot) Restrict(chat *Chat, member *ChatMember) error {
func (b *Bot) Restrict(chat *Chat, member *ChatMember, useIndependentChatPermissions bool) error {
prv, until := member.Rights, member.RestrictedUntil

params := map[string]interface{}{
"chat_id": chat.Recipient(),
"user_id": member.User.Recipient(),
"until_date": strconv.FormatInt(until, 10),
"chat_id": chat.Recipient(),
"user_id": member.User.Recipient(),
"until_date": strconv.FormatInt(until, 10),
"use_independent_chat_permissions": useIndependentChatPermissions,
}
embedRights(params, prv)

Expand Down
1 change: 0 additions & 1 deletion admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func TestEmbedRights(t *testing.T) {
"user_id": "2",
"can_be_edited": true,
"can_send_messages": true,
"can_send_media_messages": true,
"can_send_polls": true,
"can_send_other_messages": true,
"can_add_web_page_previews": true,
Expand Down
2 changes: 1 addition & 1 deletion bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func (b *Bot) EditMedia(msg Editable, media Inputtable, opts ...interface{}) (*M
files = make(map[string]File)

thumb *Photo
thumbName = "thumb"
thumbName = "thumbnail"
)

switch {
Expand Down
91 changes: 91 additions & 0 deletions bot_data.go
Original file line number Diff line number Diff line change
@@ -1 +1,92 @@
package telebot

import "encoding/json"

func (b *Bot) SetMyDescription(description, languageCode string) error {
_, err := b.Raw("setMyCommands", map[string]interface{}{
"description": description,
"language_code": languageCode,
})
return err
}

type BotDescription struct {
Description string `json:"description"`
}

func (b *Bot) GetMyDescription(languageCode string) (*BotDescription, error) {
params := map[string]string{
"language_code": languageCode,
}

data, err := b.Raw("getMyCommands", params)
if err != nil {
return nil, err
}

var resp struct {
Result BotDescription
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return &resp.Result, nil
}

func (b *Bot) SetMyShortDescription(shortDescription, languageCode string) error {
_, err := b.Raw("setMyShortDescription", map[string]interface{}{
"short_description": shortDescription,
"language_code": languageCode,
})
return err
}

type BotShortDescription struct {
ShortDescription string `json:"short_description"`
}

func (b *Bot) GetMyShortDescription(languageCode string) (*BotShortDescription, error) {
data, err := b.Raw("getMyCommands", map[string]string{
"language_code": languageCode,
})
if err != nil {
return nil, err
}

var resp struct {
Result BotShortDescription
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return &resp.Result, nil
}

func (b *Bot) SetMyName(name, languageCode string) error {
_, err := b.Raw("setMyName", map[string]interface{}{
"name": name,
"language_code": languageCode,
})
return err
}

type BotName struct {
Name string `json:"name"`
}

func (b *Bot) GetMyName(languageCode string) (*BotName, error) {
data, err := b.Raw("getMyCommands", map[string]string{
"language_code": languageCode,
})
if err != nil {
return nil, err
}

var resp struct {
Result BotName
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return &resp.Result, nil
}
5 changes: 5 additions & 0 deletions chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ type ChatMemberUpdate struct {
// (Optional) InviteLink which was used by the user to
// join the chat; for joining by invite link events only.
InviteLink *ChatInviteLink `json:"invite_link"`

ViaChatFolderInviteLink bool `json:"via_chat_folder_invite_link,omitempty"`
}

// Time returns the moment of the change in local time.
Expand Down Expand Up @@ -199,6 +201,9 @@ type ChatJoinRequest struct {
// InviteLink is the chat invite link that was used by
//the user to send the join request, optional.
InviteLink *ChatInviteLink `json:"invite_link"`

// Identifier of a private chat with the user who sent the join request.
UserChatID int64 `json:"user_chat_id"`
}

// ChatInviteLink object represents an invite for a chat.
Expand Down
15 changes: 7 additions & 8 deletions inline.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,7 @@ type QueryResponse struct {
// pagination. Offset length can’t exceed 64 bytes.
NextOffset string `json:"next_offset"`

// (Optional) If passed, clients will display a button with specified
// text that switches the user to a private chat with the bot and sends
// the bot a start message with the parameter switch_pm_parameter.
SwitchPMText string `json:"switch_pm_text,omitempty"`

// (Optional) Parameter for the start message sent to the bot when user
// presses the switch button.
SwitchPMParameter string `json:"switch_pm_parameter,omitempty"`
Button *InlineQueryResultsButton `json:"button,omitempty"`
}

// InlineResult represents a result of an inline query that was chosen
Expand Down Expand Up @@ -137,3 +130,9 @@ func inferIQR(result Result) error {

return nil
}

type InlineQueryResultsButton struct {
Text string `json:"text"`
WebApp *WebApp `json:"web_app,omitempty"`
StartParameter string `json:"start_parameter,omitempty"`
}
38 changes: 19 additions & 19 deletions inline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ type ArticleResult struct {
Description string `json:"description,omitempty"`

// Optional. URL of the thumbnail for the result.
ThumbURL string `json:"thumb_url,omitempty"`
ThumbURL string `json:"thumbnail_url,omitempty"`

// Optional. Width of the thumbnail for the result.
ThumbWidth int `json:"thumb_width,omitempty"`
ThumbWidth int `json:"thumbnail_width,omitempty"`

// Optional. Height of the thumbnail for the result.
ThumbHeight int `json:"thumb_height,omitempty"`
ThumbHeight int `json:"thumbnail_height,omitempty"`
}

// AudioResult represents a link to an mp3 audio file.
Expand Down Expand Up @@ -130,13 +130,13 @@ type ContactResult struct {
LastName string `json:"last_name,omitempty"`

// Optional. URL of the thumbnail for the result.
ThumbURL string `json:"thumb_url,omitempty"`
ThumbURL string `json:"thumbnail_url,omitempty"`

// Optional. Width of the thumbnail for the result.
ThumbWidth int `json:"thumb_width,omitempty"`
ThumbWidth int `json:"thumbnail_width,omitempty"`

// Optional. Height of the thumbnail for the result.
ThumbHeight int `json:"thumb_height,omitempty"`
ThumbHeight int `json:"thumbnail_height,omitempty"`
}

// DocumentResult represents a link to a file.
Expand All @@ -160,13 +160,13 @@ type DocumentResult struct {
Description string `json:"description,omitempty"`

// Optional. URL of the thumbnail (jpeg only) for the file.
ThumbURL string `json:"thumb_url,omitempty"`
ThumbURL string `json:"thumbnail_url,omitempty"`

// Optional. Width of the thumbnail for the result.
ThumbWidth int `json:"thumb_width,omitempty"`
ThumbWidth int `json:"thumbnail_width,omitempty"`

// Optional. Height of the thumbnail for the result.
ThumbHeight int `json:"thumb_height,omitempty"`
ThumbHeight int `json:"thumbnail_height,omitempty"`

// If Cache != "", it'll be used instead
Cache string `json:"document_file_id,omitempty"`
Expand All @@ -189,11 +189,11 @@ type GifResult struct {
Duration int `json:"gif_duration,omitempty"`

// URL of the static thumbnail for the result (jpeg or gif).
ThumbURL string `json:"thumb_url"`
ThumbURL string `json:"thumbnail_url"`

// Optional. MIME type of the thumbnail, must be one of
// “image/jpeg”, “image/gif”, or “video/mp4”.
ThumbMIME string `json:"thumb_mime_type,omitempty"`
ThumbMIME string `json:"thumbnail_mime_type,omitempty"`

// Optional. Title for the result.
Title string `json:"title,omitempty"`
Expand All @@ -215,7 +215,7 @@ type LocationResult struct {
Title string `json:"title"`

// Optional. Url of the thumbnail for the result.
ThumbURL string `json:"thumb_url,omitempty"`
ThumbURL string `json:"thumbnail_url,omitempty"`
}

// Mpeg4GifResult represents a link to a video animation
Expand All @@ -236,11 +236,11 @@ type Mpeg4GifResult struct {
Duration int `json:"mpeg4_duration,omitempty"`

// URL of the static thumbnail (jpeg or gif) for the result.
ThumbURL string `json:"thumb_url,omitempty"`
ThumbURL string `json:"thumbnail_url,omitempty"`

// Optional. MIME type of the thumbnail, must be one of
// “image/jpeg”, “image/gif”, or “video/mp4”.
ThumbMIME string `json:"thumb_mime_type,omitempty"`
ThumbMIME string `json:"thumbnail_mime_type,omitempty"`

// Optional. Title for the result.
Title string `json:"title,omitempty"`
Expand Down Expand Up @@ -276,7 +276,7 @@ type PhotoResult struct {
Caption string `json:"caption,omitempty"`

// URL of the thumbnail for the photo.
ThumbURL string `json:"thumb_url"`
ThumbURL string `json:"thumbnail_url"`

// If Cache != "", it'll be used instead
Cache string `json:"photo_file_id,omitempty"`
Expand All @@ -298,13 +298,13 @@ type VenueResult struct {
FoursquareID string `json:"foursquare_id,omitempty"`

// Optional. URL of the thumbnail for the result.
ThumbURL string `json:"thumb_url,omitempty"`
ThumbURL string `json:"thumbnail_url,omitempty"`

// Optional. Width of the thumbnail for the result.
ThumbWidth int `json:"thumb_width,omitempty"`
ThumbWidth int `json:"thumbnail_width,omitempty"`

// Optional. Height of the thumbnail for the result.
ThumbHeight int `json:"thumb_height,omitempty"`
ThumbHeight int `json:"thumbnail_height,omitempty"`
}

// VideoResult represents a link to a page containing an embedded
Expand All @@ -319,7 +319,7 @@ type VideoResult struct {
MIME string `json:"mime_type"`

// URL of the thumbnail (jpeg only) for the video.
ThumbURL string `json:"thumb_url"`
ThumbURL string `json:"thumbnail_url"`

// Title for the result.
Title string `json:"title"`
Expand Down
Loading

0 comments on commit 7b3b210

Please sign in to comment.