Skip to content

Commit

Permalink
bot api 6.4, and 6.5 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Watson committed Mar 23, 2023
1 parent db5277d commit caa4a93
Show file tree
Hide file tree
Showing 23 changed files with 311 additions and 53 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

I will do my best to keep this updated with changes as they happen.

## 0.28.0

**This release contains major breaking changes. If you currently rely on Tourmaline as a framework you may not want to update.**

- Added full support for Bot API versions 6.4, 6.5, and 6.6
- **(breaking change)** Removed all annotation based handlers.
- **(breaking change)** Removed the `Handlers` namespace. All handlers now fall directly under `Tourmaline`.
- **(breaking change)** Stripped Tourmaline of all _magic_. Models no longer have a `client` instance passed to them, instead we will now rely on the `Tourmaline::Context` which is passed to all handler callbacks.

Examples have been updated.

## 0.27.0
- Added full support for Bot API 6.3
- **(breaking change)** All `is_` prefixed properties in models have been replaced with `?` getters. For instance, `is_anonymous` is now `anonymous?`.
Expand Down
97 changes: 87 additions & 10 deletions src/tourmaline/client.cr
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,8 @@ module Tourmaline
def edit_forum_topic(
chat,
message_thread_id,
name,
icon_custom_emoji_id
name = nil,
icon_custom_emoji_id = nil,
)
request(Bool, "editForumTopic", {
chat_id: extract_id(chat),
Expand Down Expand Up @@ -674,6 +674,68 @@ module Tourmaline
})
end

# Use this method to edit the name of the 'General' topic in a forum supergroup chat. The
# bot must be an administrator in the chat for this to work and must have
# can_manage_topics administrator rights.
# Returns True on success.
def edit_general_forum_topic(
chat,
name
)
request(Bool, "editGeneralForumTopic", {
chat_id: extract_id(chat),
name: name,
})
end

# Use this method to close an open 'General' topic in a forum supergroup chat. The bot must
# be an administrator in the chat for this to work and must have the
# can_manage_topics administrator rights.
# Returns True on success.
def close_general_forum_topic(
chat
)
request(Bool, "closeGeneralForumTopic", {
chat_id: extract_id(chat),
})
end

# Use this method to reopen a closed 'General' topic in a forum supergroup chat. The bot must be an
# administrator in the chat for this to work and must have the can_manage_topics
# administrator rights. The topic will be automatically unhidden if it was hidden.
# Returns True on success.
def reopen_general_forum_topic(
chat
)
request(Bool, "reopenGeneralForumTopic", {
chat_id: extract_id(chat),
})
end

# Use this method to hide the 'General' topic in a forum supergroup chat. The bot must be
# an administrator in the chat for this to work and must have the can_manage_topics
# administrator rights. The topic will be automatically closed if it was open.
# Returns True on success.
def hide_general_forum_topic(
chat
)
request(Bool, "hideGeneralForumTopic", {
chat_id: extract_id(chat),
})
end

# Use this method to unhide the 'General' topic in a forum supergroup chat. The bot must be an
# administrator in the chat for this to work and must have the can_manage_topics
# administrator rights.
# Returns True on success.
def unhide_general_forum_topic(
chat
)
request(Bool, "unhideGeneralForumTopic", {
chat_id: extract_id(chat),
})
end

# Use this method to get basic info about a file and prepare it for downloading.
# For the moment, bots can download files of up to **20MB** in size. On success,
# a `TFile` object is returned. The file can then be downloaded via the
Expand Down Expand Up @@ -802,16 +864,18 @@ module Tourmaline
chat,
user,
permissions,
use_independent_chat_permissions = false,
until_date = nil
)
until_date = until_date.to_unix unless (until_date.is_a?(Int) || until_date.nil?)
permissions = permissions.is_a?(NamedTuple) ? ChatPermissions.new(**permissions) : permissions

request(Bool, "restrictChatMember", {
chat_id: extract_id(chat),
user_id: extract_id(user_id),
until_date: until_date,
permissions: permissions.to_json,
chat_id: extract_id(chat),
user_id: extract_id(user_id),
until_date: until_date,
permissions: permissions.to_json,
use_independent_chat_permissions: use_independent_chat_permissions,
})
end

Expand Down Expand Up @@ -1015,10 +1079,15 @@ module Tourmaline
# an administrator in the group or a supergroup for this to work and must have
# the can_restrict_members admin rights.
# Returns True on success.
def set_chat_permissions(chat, permissions)
def set_chat_permissions(
chat,
permissions,
use_independent_chat_permissions = false
)
request(Bool, "setChatPermissions", {
chat_id: extract_id(chat),
permissions: permissions.to_json,
chat_id: extract_id(chat),
permissions: permissions.to_json,
use_independent_chat_permissions: use_independent_chat_permissions,
})
end

Expand Down Expand Up @@ -1139,6 +1208,7 @@ module Tourmaline
thumbnail = nil,
caption = nil,
caption_entities = [] of MessageEntity,
has_spoiler = false,
parse_mode : ParseMode = default_parse_mode,
disable_notification = false,
protect_content = false,
Expand All @@ -1156,6 +1226,7 @@ module Tourmaline
thumbnail: thumbnail,
caption: caption,
caption_entities: caption_entities,
has_spoiler: has_spoiler,
parse_mode: parse_mode,
disable_notification: disable_notification,
protect_content: protect_content,
Expand All @@ -1179,11 +1250,13 @@ module Tourmaline
# noticeable amount of time to arrive.
def send_chat_action(
chat,
action : ChatAction
action : ChatAction,
message_thread = nil
)
request(Bool, "sendChatAction", {
chat_id: extract_id(chat),
action: action.to_s,
message_thread_id: extract_id(message_thread),
})
end

Expand Down Expand Up @@ -1381,6 +1454,7 @@ module Tourmaline
caption = nil,
parse_mode : ParseMode = default_parse_mode,
caption_entities = [] of MessageEntity,
has_spoiler = false,
disable_notification = false,
protect_content = false,
reply_to_message = nil,
Expand All @@ -1396,6 +1470,7 @@ module Tourmaline
caption: caption,
parse_mode: parse_mode,
caption_entities: caption_entities,
has_spoiler: has_spoiler,
disable_notification: disable_notification,
protect_content: protect_content,
reply_to_message_id: extract_id(reply_to_message),
Expand Down Expand Up @@ -1501,6 +1576,7 @@ module Tourmaline
height = nil,
caption = nil,
caption_entities = [] of MessageEntity,
has_spoiler = false,
parse_mode : ParseMode = default_parse_mode,
disable_notification = false,
protect_content = false,
Expand All @@ -1519,6 +1595,7 @@ module Tourmaline
height: height,
caption: caption,
caption_entities: caption_entities,
has_spoiler: has_spoiler,
parse_mode: parse_mode,
disable_notification: disable_notification,
protect_content: protect_content,
Expand Down
12 changes: 8 additions & 4 deletions src/tourmaline/models/chat.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ module Tourmaline

getter emoji_status_custom_emoji_id : String?

getter has_private_forwards : Bool?
getter? has_private_forwards : Bool?

getter has_restricted_voice_and_video_messages : Bool?
getter? has_restricted_voice_and_video_messages : Bool?

getter join_to_send_messages : Bool?

Expand All @@ -46,11 +46,15 @@ module Tourmaline

getter message_auto_delete_time : Int32?

getter has_protected_content : Bool?
getter? has_aggressive_anti_spam_enabled : Bool?

getter? has_hidden_members : Bool?

getter? has_protected_content : Bool?

getter sticker_set_name : String?

getter can_set_sticker_set : Bool?
getter? can_set_sticker_set : Bool?

getter linked_chat_id : Int64?

Expand Down
2 changes: 2 additions & 0 deletions src/tourmaline/models/chat_join_request.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module Tourmaline

getter from : User

getter user_chat_id : Int64

getter date : Int64

getter bio : String?
Expand Down
12 changes: 11 additions & 1 deletion src/tourmaline/models/chat_member_restricted.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ module Tourmaline

getter? can_send_messages : Bool

getter? can_send_media_messages : Bool
getter? can_send_audios : Bool

getter? can_send_documents : Bool

getter? can_send_photos : Bool

getter? can_send_videos : Bool

getter? can_send_video_notes : Bool

getter? can_send_voice_notes : Bool

getter? can_send_polls : Bool

Expand Down
19 changes: 17 additions & 2 deletions src/tourmaline/models/chat_permissions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@ module Tourmaline

property can_send_messages : Bool

property can_send_media_messages : Bool
property can_send_audios : Bool

property can_send_documents : Bool

property can_send_photos : Bool

property can_send_videos : Bool

property can_send_video_notes : Bool

property can_send_voice_notes : Bool

property can_send_polls : Bool

Expand All @@ -22,7 +32,12 @@ module Tourmaline

def initialize(
@can_send_messages = true,
@can_send_media_messages = true,
@can_send_audios = true,
@can_send_documents = true,
@can_send_photos = true,
@can_send_videos = true,
@can_send_video_notes = true,
@can_send_voice_notes = true,
@can_send_polls = true,
@can_send_other_messages = true,
@can_add_web_page_previews = true,
Expand Down
9 changes: 9 additions & 0 deletions src/tourmaline/models/chat_shared.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Tourmaline
class ChatShared
include JSON::Serializable

getter request_id : Int32

getter chat_id : Int64
end
end
9 changes: 9 additions & 0 deletions src/tourmaline/models/forum_topic_edited.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Tourmaline
class ForumTopicEdited
include JSON::Serializable

getter name : String?

getter icon_custom_emoji_id : String?
end
end
5 changes: 5 additions & 0 deletions src/tourmaline/models/general_forum_topic_hidden.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Tourmaline
class GeneralForumTopicHidden
include JSON::Serializable
end
end
5 changes: 5 additions & 0 deletions src/tourmaline/models/general_forum_topic_unhidden.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Tourmaline
class GeneralForumTopicUnhidden
include JSON::Serializable
end
end
12 changes: 11 additions & 1 deletion src/tourmaline/models/inline/inline_keyboard_button.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ module Tourmaline

property pay : Bool?

def initialize(@text : String, @url : String? = nil, @login_url : LoginURL? = nil, @callback_data : String? = nil, @web_app = nil, @switch_inline_query : String? = nil, @switch_inline_query_current_chat : String? = nil, @callback_game : CallbackGame? = nil, @pay : Bool? = nil)
def initialize(
@text : String,
@url : String? = nil,
@login_url : LoginURL? = nil,
@callback_data : String? = nil,
@web_app = nil,
@switch_inline_query : String? = nil,
@switch_inline_query_current_chat : String? = nil,
@callback_game : CallbackGame? = nil,
@pay : Bool? = nil
)
end
end
end
4 changes: 3 additions & 1 deletion src/tourmaline/models/input_media_animation.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ module Tourmaline

property caption_entities : Array(MessageEntity) = [] of MessageEntity

property? has_spoiler : Bool

property width : Int32?

property height : Int32?

property duration : Int32?

def initialize(@media, @thumb = nil, @caption = nil, @parse_mode = nil, @caption_entities = [] of MessageEntity,
@width = nil, @height = nil, duration = nil)
@has_spoiler = false, @width = nil, @height = nil, @duration = nil)
end
end
end
4 changes: 3 additions & 1 deletion src/tourmaline/models/input_media_photo.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ module Tourmaline

property caption_entities : Array(MessageEntity) = [] of MessageEntity

def initialize(@media, @caption = nil, @parse_mode = nil, @caption_entities = [] of MessageEntity)
property? has_spoiler : Bool?

def initialize(@media, @caption = nil, @parse_mode = nil, @caption_entities = [] of MessageEntity, @has_spoiler = false)
end
end
end
6 changes: 4 additions & 2 deletions src/tourmaline/models/input_media_video.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ module Tourmaline

property duration : Int32?

property supports_streaming : Bool?
property? supports_streaming : Bool?

property? has_spoiler : Bool?

def initialize(@media, @thumb = nil, @caption = nil, @parse_mode = nil, @caption_entities = [] of MessageEntity,
@width = nil, @height = nil, duration = nil, @supports_streaming = nil)
@width = nil, @height = nil, duration = nil, @supports_streaming = nil, @has_spoiler = false)
end
end
end
Loading

0 comments on commit caa4a93

Please sign in to comment.