Compare commits
No commits in common. "bfda135c193a0c78c91ca24bbd91261fda6428be" and "81eee54695ddf3e08d66bb5379b0fade7b8c981d" have entirely different histories.
bfda135c19
...
81eee54695
@ -18,8 +18,6 @@ module Telepathy
|
||||
@last_update_id = nil
|
||||
@command_hooks = {} of String => Update, Array(String) -> Void
|
||||
@message_hooks = [] of Update -> Void
|
||||
@poll_start_hooks = [] of -> Void
|
||||
@poll_end_hooks = [] of -> Void
|
||||
@poll_channel = Channel(Int64?|Control).new
|
||||
@update_channel = Channel(Array(Update)|Control).new
|
||||
@poll_running = false
|
||||
@ -60,42 +58,6 @@ module Telepathy
|
||||
body: message_data.to_json)
|
||||
end
|
||||
|
||||
def send_photo(chat_id : String | Int64, photo : String | File, caption : String? = nil,
|
||||
disable_notification : Bool = false,
|
||||
reply_to_message_id : Int64? = nil)
|
||||
IO.pipe do |reader, writer|
|
||||
channel = Channel(String).new(1)
|
||||
spawn do
|
||||
HTTP::FormData.build(writer) do |formdata|
|
||||
channel.send(formdata.content_type)
|
||||
case chat_id
|
||||
when String
|
||||
formdata.field("chat_id", chat_id.as(String))
|
||||
when Int64
|
||||
formdata.field("chat_id", chat_id.as(Int64).to_s)
|
||||
end
|
||||
formdata.field("disable_notification", disable_notification.to_s)
|
||||
caption.try { |caption| formdata.field("caption", caption) }
|
||||
reply_to_message_id.try { |id| formdata.field("reply_to_message_id", id) }
|
||||
case photo
|
||||
when String
|
||||
formdata.field("photo", photo.as(String))
|
||||
when File
|
||||
photo_file = photo.as(File)
|
||||
formdata.file("photo", photo_file,
|
||||
HTTP::FormData::FileMetadata.new(filename: File.basename(photo_file.path)))
|
||||
end
|
||||
end
|
||||
|
||||
writer.close
|
||||
end
|
||||
|
||||
response = HTTP::Client.get(@request_base + "/sendPhoto",
|
||||
headers: HTTP::Headers{"User-agent" => "Telepathy", "Content-type" => channel.receive },
|
||||
body: reader)
|
||||
end
|
||||
end
|
||||
|
||||
def command(command_name, &block: Update, Array(String) -> Void)
|
||||
@command_hooks[command_name] = block
|
||||
end
|
||||
@ -104,14 +66,6 @@ module Telepathy
|
||||
@message_hooks.push(block)
|
||||
end
|
||||
|
||||
def poll_start(&block: -> Void)
|
||||
@poll_start_hooks.push(block);
|
||||
end
|
||||
|
||||
def poll_end(&block: -> Void)
|
||||
@poll_end_hooks.push(block);
|
||||
end
|
||||
|
||||
private def process_updates(updates)
|
||||
updates.each do |update|
|
||||
if message = update.message
|
||||
@ -140,6 +94,7 @@ module Telepathy
|
||||
@last_update_id = action.nil? ? @last_update_id : action + 1
|
||||
@update_channel.send get_updates 10
|
||||
when Control
|
||||
@update_channel.send action
|
||||
break
|
||||
end
|
||||
end
|
||||
@ -152,7 +107,6 @@ module Telepathy
|
||||
process_updates(item)
|
||||
@poll_channel.send item.last?.try &.update_id
|
||||
when Control
|
||||
@poll_channel.send item
|
||||
break
|
||||
end
|
||||
end
|
||||
@ -164,7 +118,6 @@ module Telepathy
|
||||
@poll_running = true
|
||||
spawn_workers
|
||||
@poll_channel.send nil
|
||||
@poll_start_hooks.each &.call
|
||||
end
|
||||
end
|
||||
|
||||
@ -172,7 +125,6 @@ module Telepathy
|
||||
if @poll_running
|
||||
@poll_running = false
|
||||
@poll_channel.send Control::Done
|
||||
@poll_end_hooks.each &.call
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user