[UPD] now it works with tdlib-ruby 2.2 (tdlib 1.6)
[UPD] now /s (edit) replaces your whole message (/s new message)
[!] removed /history command (as it does not work)
[!] some groupchat stuff still untested, use at your own risk
* tdlib-ruby == 2.0 with pre-compiled _libtdjson.so_
* tdlib-ruby == 2.2 with pre-compiled _libtdjson.so_ (1.6)
There is pre-compiled _libtdjson.so_ for Debian Stretch x64 in repository.
For any other distro you need to manually compile [**tdlib**](https://github.com/tdlib/td) and place _libtdjson.so_ to relative **lib/** directory (or **LD_LIBRARY_PATH**).
prefix<<DateTime.strptime((update.message.date+Time.now.getlocal(@session[:timezone]).utc_offset).to_s,'%s').strftime("%d %b %Y %H:%M:%S")ifshow_date# show date if its
prefix<<(update.message.is_outgoing?'➡ ':'⬅ ')+update.message.id.to_s# message direction
prefix<<"%s"%self.format_contact(update.message.sender_user_id)ifupdate.message.chat_id<0andupdate.message.sender_user_id# show sender in group chats
prefix<<"fwd: %s"%self.format_contact(update.message.forward_info.sender_user_id)ifupdate.message.forward_info.instance_of?TD::Types::MessageForwardInfo::MessageForwardedFromUser# fwd from user
prefix<<"fwd: %s%s"%[self.format_contact(update.message.forward_info.chat_id),(update.message.forward_info.author_signature!='')?" (%s)"%update.message.forward_info.author_signature:'']ifupdate.message.forward_info.instance_of?TD::Types::MessageForwardInfo::MessageForwardedPost# fwd from chat
prefix<<"reply: %s"%self.format_message(update.message.chat_id,update.message.reply_to_message_id,true)ifupdate.message.reply_to_message_id.to_i!=0# reply to
document=TD::Types::InputMessageContent::Document.new(document:file,caption:text)iffile# we can try to send a document
message_id?@telegram.edit_message_text(chat_id,message_id,message):@telegram.send_message(chat_id,document||message,reply_to_message_id:reply||0).rescue{|why|@xmpp.send_message(@jid,chat_id,"Message not sent: %s"%why)}
defprocess_outgoing_message(id,text)
returnifself.process_command(id,text.split.first,text.split[1..-1])ornotself.online?# try to execute commands
chat,user=self.get_contact(chat_id)unlesschat_id==0# get chat information
ifchat_id==0then# transport commands
defprocess_command(id,cmd,args)
chat,user=self.get_contact(id)unlessid==0# get chat information
ifid==0then# transport commands
casecmd
when'/login'then@telegram.set_authentication_phone_number(args[0]).then{|_|@session[:login]=args[0]}unless@session[:login]# sign in
when'/logout'then@telegram.log_out().then{|_|@cache[:chats].each_keydo|chat|@xmpp.send_presence(@jid,chat,:unsubscribed);@session[:login]=nilend}# sign out
@ -281,29 +277,28 @@ class TelegramClient
returntrue# stop executing
else# chat commands
casecmd
when'/d'then@telegram.delete_messages(chat.id,@telegram.search_chat_messages(chat.id,0,args[0]||1,sender_user_id:@me.id,filter:TD::Types::SearchMessagesFilter::Empty.new).value.messages.map(&:id),true)# delete last message(s)
when'/s'then@telegram.search_chat_messages(chat.id,0,1,sender_user_id:@me.id,filter:TD::Types::SearchMessagesFilter::Empty.new).value.messages.eachdo|msg|self.process_outgoing_message(chat.id,msg.content.text.text.to_s.gsub(Regexp.new(args[0]),args[1..-1].join(' ')),msg.id)end# edit last message
when'/supergroup'then@telegram.create_new_supergroup_chat(args[0],args[1..-1].join(' '),is_channel:false)# create new supergroup
when'/channel'then@telegram.create_new_supergroup_chat(args[0],args[1..-1].join(' '),is_channel:true)# create new channel
when'/secret'then@telegram.create_new_secret_chat(chat.id)ifuser# create secret chat with current user
when'/group'then@telegram.create_new_basic_group_chat(chat.id,args[0])ifchat.id>0# create group chat with current user
when'/block'then@telegram.block_user(chat.id)ifchat.id>0# blacklists current user
when'/unblock'then@telegram.unblock_user(chat.id)ifchat.id>0# unblacklists current user
when'/invite'then@telegram.add_chat_member(chat.id,(args[0].to_i==0?@telegram.search_public_chat(args[0]).value.id:args[0].to_i))ifchat.id<0# invite @username to current groupchat
when'/kick'then@telegram.set_chat_member_status(chat.id,(args[0].to_i==0?@telegram.search_public_chat(args[0]).value.id:args[0].to_i))ifchat.id<0# kick @username from current group chat
when'/ban'then@telegram.set_chat_member_status(chat.id,(args[0].to_i==0?@telegram.search_public_chat(args[0]).value.id:args[0].to_i),TD::Types::ChatMemberStatus::Banned(banned_until_date:(args[1].to_i>0?Time.now.getutc.to_i+(args[1].to_i*3600):0)))ifchat.id<0# ban @username from current chat [for N hours]
when'/leave'then@telegram.leave_chat(chat.id).then{@xmpp.send_presence(@jid,chat_id,:unsubscribed)}ifchat.type.instance_of?TD::Types::ChatType::Supergrouporchat.type.instance_of?TD::Types::ChatType::BasicGroup# leave current chat
when'/close'then@telegram.close_secret_chat(chat.type.secret_chat_id).then{@xmpp.send_presence(@jid,chat_id,:unsubscribed)}ifchat.type.instance_of?TD::Types::ChatType::Secret# close secret chat
when'/delete'then@telegram.delete_chat_history(chat.id,true).then{@xmpp.send_presence(@jid,chat_id,:unsubscribed)}# delete current chat
when'/search'then@telegram.search_chat_messages(chat.id,0,args[1]||10,query:args[0]||nil,filter:TD::Types::SearchMessagesFilter::Empty.new).value.messages.reverse.eachdo|msg|@xmpp.send_message(@jid,chat_id,self.format_message(nil,nil,nil,msg))end# search messages within current chat
when'/history'then@telegram.get_chat_history(chat.id,0,0,args[0]||10).value.messages.reverse.eachdo|msg|@xmpp.send_message(@jid,chat_id,self.format_message(nil,nil,msg))end# get latest entries from history
when'/members'then@telegram.search_chat_members(chat.id,9999,query:args[0],filter:TD::Types::ChatMembersFilter::Members.new).then{|members|@xmpp.send_message(@jid,chat_id,(members.members.mapdo|user|"%s | role: %s"%[self.fmt_chat(user.user_id),user.status.class]end).join("\n"))}# members list (for admins)
when'/supergroup'then@telegram.create_new_supergroup_chat(args[0],false,args[1..-1].join(' '),nil)# create new supergroup
when'/channel'then@telegram.create_new_supergroup_chat(args[0],true,args[1..-1].join(' '),nil)# create new channel
when'/secret'then@telegram.create_new_secret_chat(chat.id,false)# create secret chat with current user
when'/group'then@telegram.create_new_basic_group_chat(chat.id,args[0])# create group chat with current user
when'/block'then@telegram.block_user(chat.id)# blacklists current user
when'/unblock'then@telegram.unblock_user(chat.id)# unblacklists current user
when'/invite'then@telegram.add_chat_member(chat.id,self.get_contact(args[0]).first.id,100)# invite @username to current groupchat
when'/kick'then@telegram.set_chat_member_status(chat.id,self.get_contact(args[0]).first.id,self.format_restrict())# kick @username from current group chat
when'/ban'then@telegram.set_chat_member_status(chat.id,self.get_contact(args[0]).first.id,self.format_restrict(true,args[1]))# ban @username from current chat [for N hours]
when'/leave'then@telegram.leave_chat(chat.id).then{@xmpp.send_presence(@jid,id,:unsubscribed)}# leave current chat
when'/close'then@telegram.close_secret_chat(chat.type.secret_id).then{@xmpp.send_presence(@jid,id,:unsubscribed)}# close secret chat
when'/delete'then@telegram.delete_chat_history(chat.id,true,true).then{@xmpp.send_presence(@jid,id,:unsubscribed)}# delete current chat
when'/members'then@telegram.search_chat_members(chat.id,args[0],9999,TD::Types::ChatMembersFilter::Members.new).then{|m|@xmpp.send_message(@jid,chat.id,(m.members.mapdo|u|"%s | role: %s"%[self.format_contact(u.user_id),u.status.class]end).join("\n"))}# chat members