Skip to content
This repository has been archived by the owner on Nov 16, 2024. It is now read-only.

Commit

Permalink
Updated to version 5.5 of the Bot API
Browse files Browse the repository at this point in the history
  • Loading branch information
watzon committed Dec 8, 2021
1 parent 1c71d79 commit 6b58498
Show file tree
Hide file tree
Showing 6 changed files with 396 additions and 346 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1 +1 @@
crystal 1.0.0
crystal 1.2.2
579 changes: 248 additions & 331 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: tourmaline
version: 0.23.0
version: 0.24.0

authors:
- Chris Watson <chris@watzon.tech>
Expand Down
147 changes: 135 additions & 12 deletions src/tourmaline/client/core_methods.cr
Original file line number Diff line number Diff line change
Expand Up @@ -505,18 +505,6 @@ module Tourmaline
})
end

# Use this method to generate a new invite link for a chat; any previously
# generated link is revoked. The bot must be an administrator in the chat
# for this to work and must have the appropriate admin rights.
# Returns the new invite link as `String` on success.
def export_chat_invite_link(chat)
chat_id = chat.is_a?(Int::Primitive | String) ? chat : chat.id

request(String, "exportChatInviteLink", {
chat_id: chat_id,
})
end

# Use this method to set a new profile photo for the chat. Photos can't be changed
# for private chats. The bot must be an administrator in the chat for this to
# work and must have the appropriate admin rights.
Expand Down Expand Up @@ -561,6 +549,141 @@ module Tourmaline
})
end

# Use this method to ban a channel chat in a supergroup or a channel. The owner
# of the chat will not be able to send messages and join live streams on
# behalf of the chat, unless it is unbanned first. The bot must be an
# administrator in the supergroup or channel for this to work and
# must have the appropriate administrator rights.
# Returns True on success.
def ban_chat_sender_chat(chat, sender_chat)
chat_id = chat.is_a?(Int::Primitive | String) ? chat : chat.id
sender_chat_id = sender_chat.is_a?(Int::Primitive) ? chat : chat.id

request(Bool, "banChatSenderChat", {
chat_id: chat_id,
sender_chat_id: sender_chat_id
})
end

# Use this method to unban a previously banned channel chat in a supergroup or channel.
# The bot must be an administrator for this to work and must have the
# appropriate administrator rights.
# Returns True on success.
def unban_chat_sender_chat(chat, sender_chat)
chat_id = chat.is_a?(Int::Primitive | String) ? chat : chat.id
sender_chat_id = sender_chat.is_a?(Int::Primitive) ? chat : chat.id

request(Bool, "unbanChatSenderChat", {
chat_id: chat_id,
sender_chat_id: sender_chat_id
})
end

# Use this method to generate a new invite link for a chat; any previously
# generated link is revoked. The bot must be an administrator in the chat
# for this to work and must have the appropriate admin rights.
# Returns the new invite link as `String` on success.
def export_chat_invite_link(chat)
chat_id = chat.is_a?(Int::Primitive | String) ? chat : chat.id

request(String, "exportChatInviteLink", {
chat_id: chat_id,
})
end

# Use this method to create an additional invite link for a chat. The bot must be an
# administrator in the chat for this to work and must have the appropriate
# administrator rights. The link can be revoked using the method
# revokeChatInviteLink.
# Returns the new invite link as ChatInviteLink object.
def create_chat_invite_link(
chat,
name = nil,
expire_date = nil,
member_limit = nil,
creates_join_request = false,
)
chat_id = chat.is_a?(Int::Primitive | String) ? chat : chat.id
expire_date = expire_date.to_unix unless (expire_date.is_a?(Int) || expire_date.nil?)

request(ChatInviteLink, "createChatInviteLink", {
chat_id: chat_id,
name: name,
expire_date: expire_date,
member_limit: member_limit,
creates_join_request: creates_join_request,
})
end

# Use this method to edit a non-primary invite link created by the bot. The
# bot must be an administrator in the chat for this to work and must
# have the appropriate administrator rights.
# Returns the edited invite link as a ChatInviteLink object.
def edit_chat_invite_link(
chat,
invite_link,
name = nil,
expire_date = nil,
member_limit = nil,
creates_join_request = false,
)
chat_id = chat.is_a?(Int::Primitive | String) ? chat : chat.id
invite_link = invite_link.is_a?(String) ? invite_link : invite_link.invite_link
expire_date = expire_date.to_unix unless (expire_date.is_a?(Int) || expire_date.nil?)

request(ChatInviteLink, "editChatInviteLink", {
chat_id: chat_id,
invite_link: invite_link,
name: name,
expire_date: expire_date,
member_limit: member_limit,
creates_join_request: creates_join_request,
})
end

# Use this method to revoke an invite link created by the bot. If the primary link
# is revoked, a new link is automatically generated. The bot must be an
# administrator in the chat for this to work and must have the
# appropriate administrator rights.
# Returns the revoked invite link as ChatInviteLink object.
def revoke_chat_invite_link(chat, invite_link)
chat_id = chat.is_a?(Int::Primitive | String) ? chat : chat.id
invite_link = invite_link.is_a?(String) ? invite_link : invite_link.invite_link

request(ChatInviteLink, "revokeChatInviteLink", {
chat_id: chat_id,
invite_link: invite_link,
})
end

# Use this method to approve a chat join request. The bot must be an administrator
# in the chat for this to work and must have the can_invite_users
# administrator right.
# Returns True on success.
def approve_chat_join_request(chat, user)
chat_id = chat.is_a?(Int::Primitive | String) ? chat : chat.id
user_id = user.is_a?(Int) ? user : user.id

request(Bool, "approveChatJoinRequest", {
chat_id: chat_id,
user_id: user_id,
})
end

# Use this method to decline a chat join request. The bot must be an administrator
# in the chat for this to work and must have the can_invite_users
# administrator right.
# Returns True on success.
def decline_chat_join_request(chat, user)
chat_id = chat.is_a?(Int::Primitive | String) ? chat : chat.id
user_id = user.is_a?(Int) ? user : user.id

request(Bool, "declineChatJoinRequest", {
chat_id: chat_id,
user_id: user_id,
})
end

# Use this method to set default chat permissions for all members. The bot must be
# an administrator in the group or a supergroup for this to work and must have
# the can_restrict_members admin rights.
Expand Down
8 changes: 7 additions & 1 deletion src/tourmaline/models/chat.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Tourmaline
# # This object represents a Telegram user or bot.
# This object represents a Telegram user or bot.
class Chat
include JSON::Serializable
include Tourmaline::Model
Expand All @@ -20,6 +20,8 @@ module Tourmaline

getter bio : String?

getter has_private_forwards : Bool?

getter description : String?

getter invite_link : String?
Expand All @@ -30,6 +32,10 @@ module Tourmaline

getter slow_mode_delay : Int32?

getter message_auto_delete_time : Int32?

getter has_protected_content : Bool?

getter sticker_set_name : String?

getter can_set_sticker_set : Bool?
Expand Down
4 changes: 4 additions & 0 deletions src/tourmaline/models/message.cr
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module Tourmaline
@[JSON::Field(converter: Time::EpochConverter)]
getter forward_date : Time?

getter is_automatic_forward : Bool?

@[JSON::Field(converter: Time::EpochConverter)]
getter edit_date : Time?

Expand All @@ -42,6 +44,8 @@ module Tourmaline
@[JSON::Field(converter: Time::EpochConverter)]
getter edit_date : Time?

getter has_protected_content : Bool?

getter media_group_id : String?

getter author_signature : String?
Expand Down

0 comments on commit 6b58498

Please sign in to comment.