telethon 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +96 -0
- data/README.md +103 -8
- data/lib/telethon/cli/commands.rb +25 -20
- data/lib/telethon/client/auth.rb +22 -1
- data/lib/telethon/client/chats.rb +577 -0
- data/lib/telethon/client/dialogs.rb +211 -0
- data/lib/telethon/client/downloads.rb +659 -0
- data/lib/telethon/client/entities.rb +50 -2
- data/lib/telethon/client/files.rb +341 -192
- data/lib/telethon/client/messages.rb +264 -40
- data/lib/telethon/client/updates.rb +407 -0
- data/lib/telethon/client.rb +119 -31
- data/lib/telethon/crypto/rsa.rb +81 -5
- data/lib/telethon/custom/admin_log_event.rb +133 -0
- data/lib/telethon/custom/conversation.rb +358 -0
- data/lib/telethon/custom/dialog.rb +144 -0
- data/lib/telethon/custom/file.rb +130 -0
- data/lib/telethon/custom/forward.rb +63 -0
- data/lib/telethon/custom/getters.rb +152 -0
- data/lib/telethon/custom/participant_permissions.rb +100 -0
- data/lib/telethon/errors.rb +12 -0
- data/lib/telethon/events/album.rb +108 -0
- data/lib/telethon/events/chat_action.rb +212 -0
- data/lib/telethon/events/common.rb +173 -0
- data/lib/telethon/events/message_deleted.rb +119 -0
- data/lib/telethon/events/new_message.rb +176 -0
- data/lib/telethon/events/raw.rb +35 -0
- data/lib/telethon/events/user_update.rb +129 -0
- data/lib/telethon/extensions/html.rb +373 -0
- data/lib/telethon/extensions/markdown.rb +116 -0
- data/lib/telethon/extensions/text.rb +171 -0
- data/lib/telethon/message.rb +423 -0
- data/lib/telethon/mime.rb +1930 -0
- data/lib/telethon/mime_guess.rb +54 -0
- data/lib/telethon/network/authenticator.rb +5 -4
- data/lib/telethon/network/sender.rb +7 -0
- data/lib/telethon/private_files.rb +25 -0
- data/lib/telethon/session.rb +18 -0
- data/lib/telethon/tl/object.rb +4 -0
- data/lib/telethon/updates/message_box.rb +481 -0
- data/lib/telethon/version.rb +1 -1
- data/lib/telethon.rb +25 -0
- metadata +26 -1
|
@@ -9,7 +9,8 @@ module Telethon
|
|
|
9
9
|
case object.name
|
|
10
10
|
when "user", "userEmpty", "peerUser", "inputPeerUser" then object["user_id"] || object["id"]
|
|
11
11
|
when "chat", "chatForbidden", "chatEmpty", "peerChat", "inputPeerChat" then -(object["chat_id"] || object["id"])
|
|
12
|
-
|
|
12
|
+
# A community (layer 234) is addressed as a channel, as Telethon does.
|
|
13
|
+
when "channel", "channelForbidden", "community", "communityForbidden", "peerChannel", "inputPeerChannel"
|
|
13
14
|
-(CHANNEL_BASE + (object["channel_id"] || object["id"]))
|
|
14
15
|
else raise Error, "#{object.name} has no peer id"
|
|
15
16
|
end
|
|
@@ -41,7 +42,18 @@ module Telethon
|
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
44
|
|
|
45
|
+
# The input peer for a user, chat or channel, an input peer, a marked id (from the cache, else
|
|
46
|
+
# fetched), or a reference get_entity takes ("me", "@username").
|
|
44
47
|
def input_peer_for(entity)
|
|
48
|
+
entity = get_entity(entity) if entity.is_a?(String)
|
|
49
|
+
if entity.is_a?(Integer)
|
|
50
|
+
cached = input_peer(entity)
|
|
51
|
+
return cached if cached
|
|
52
|
+
|
|
53
|
+
entity = get_entity(entity)
|
|
54
|
+
end
|
|
55
|
+
return entity if entity.name.start_with?("inputPeer")
|
|
56
|
+
|
|
45
57
|
id = Client.peer_id(entity)
|
|
46
58
|
return TL.make("inputPeerSelf") if entity.name == "user" && entity["self"]
|
|
47
59
|
|
|
@@ -49,6 +61,34 @@ module Telethon
|
|
|
49
61
|
input_peer(id)
|
|
50
62
|
end
|
|
51
63
|
|
|
64
|
+
# Telethon's get_input_entity: the input peer for an input peer, a user, chat or channel, "me", a
|
|
65
|
+
# @username or link, or a marked id. An id the cache does not know is asked for with access hash 0,
|
|
66
|
+
# as Telethon does (a user through users.getUsers, a channel through channels.getChannels).
|
|
67
|
+
def get_input_entity(peer)
|
|
68
|
+
return peer if peer.is_a?(TL::Object) && peer.name.start_with?("inputPeer")
|
|
69
|
+
return input_peer_for(peer) if peer.is_a?(TL::Object)
|
|
70
|
+
return TL.make("inputPeerSelf") if %w[me self].include?(peer.to_s)
|
|
71
|
+
return input_peer_for(get_entity(peer)) unless peer.is_a?(Integer)
|
|
72
|
+
|
|
73
|
+
cached = input_peer(peer)
|
|
74
|
+
return cached if cached
|
|
75
|
+
|
|
76
|
+
if peer.positive?
|
|
77
|
+
users = call(TL.make("users.getUsers", "id" => [TL.make("inputUser", "user_id" => peer, "access_hash" => 0)]))
|
|
78
|
+
found = users[0]
|
|
79
|
+
return input_peer_for(found) if found && !found.is?("userEmpty")
|
|
80
|
+
elsif peer <= -CHANNEL_BASE
|
|
81
|
+
begin
|
|
82
|
+
chats = call(TL.make("channels.getChannels",
|
|
83
|
+
"id" => [TL.make("inputChannel", "channel_id" => -peer - CHANNEL_BASE, "access_hash" => 0)]))
|
|
84
|
+
return input_peer_for(chats["chats"][0])
|
|
85
|
+
rescue RPCError => e
|
|
86
|
+
raise unless e.name == "CHANNEL_INVALID"
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
raise Error, "Could not find the input entity for #{peer}"
|
|
90
|
+
end
|
|
91
|
+
|
|
52
92
|
def input_channel(peer)
|
|
53
93
|
TL.make("inputChannel", "channel_id" => peer["channel_id"], "access_hash" => peer["access_hash"])
|
|
54
94
|
end
|
|
@@ -72,7 +112,7 @@ module Telethon
|
|
|
72
112
|
return if entity["min"] && @session.entity(Client.peer_id(entity)) # a min entity's hash is not usable
|
|
73
113
|
|
|
74
114
|
case entity.name
|
|
75
|
-
when "user", "channel"
|
|
115
|
+
when "user", "channel", "community"
|
|
76
116
|
return if entity["access_hash"].nil?
|
|
77
117
|
|
|
78
118
|
@session.remember(Client.peer_id(entity), entity["access_hash"], entity["username"], Client.display_name(entity))
|
|
@@ -84,6 +124,9 @@ module Telethon
|
|
|
84
124
|
# The user, chat or channel for a CLI reference: "me", a marked id, or a @username. A numeric id
|
|
85
125
|
# the session has not seen yet loads the dialog list once, as tg.py did.
|
|
86
126
|
def get_entity(reference)
|
|
127
|
+
# As Telethon: anything but a reference becomes an input peer, and Telegram is asked for it.
|
|
128
|
+
return fetch_input(get_input_entity(reference)) if reference.is_a?(TL::Object)
|
|
129
|
+
|
|
87
130
|
ref = reference.to_s.strip
|
|
88
131
|
return get_me if %w[me self].include?(ref)
|
|
89
132
|
|
|
@@ -138,6 +181,11 @@ module Telethon
|
|
|
138
181
|
peer = input_peer(id)
|
|
139
182
|
return nil unless peer
|
|
140
183
|
|
|
184
|
+
fetch_input(peer)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
# The user, chat or channel of an input peer, from Telegram.
|
|
188
|
+
def fetch_input(peer)
|
|
141
189
|
case peer.name
|
|
142
190
|
when "inputPeerSelf" then get_me
|
|
143
191
|
when "inputPeerUser"
|