This commit is contained in:
Ilya P 2016-10-11 16:28:57 +03:00
parent a14dfdc1fe
commit 2ffa954246
9 changed files with 225 additions and 37 deletions

View file

@ -13,6 +13,8 @@ using TeleSharp.TL;
using MD5 = System.Security.Cryptography.MD5;
using TeleSharp.TL.Help;
using TeleSharp.TL.Auth;
using TeleSharp.TL.Contacts;
using TeleSharp.TL.Messages;
namespace TLSharp.Core
{
@ -153,9 +155,57 @@ namespace TLSharp.Core
{
await _sender.Send(methodtoExceute);
await _sender.Receive(methodtoExceute);
return (T)Convert.ChangeType(typeof(TLMethod).GetProperty("Response").GetValue(methodtoExceute),typeof(T));
var result = methodtoExceute.GetType().GetProperty("Response").GetValue(methodtoExceute);
return (T)result;
}
private void OnUserAuthenticated(TLUser TLUser)
public async Task<TLContacts> GetContacts()
{
if (!IsUserAuthorized())
throw new InvalidOperationException("Authorize user first!");
var req = new TLRequestGetContacts() {hash = ""};
return await SendRequest<TLContacts>(req);
}
public async Task<TLAbsUpdates> SendMessage(TLAbsInputPeer peer, string message)
{
if (!IsUserAuthorized())
throw new InvalidOperationException("Authorize user first!");
long uniqueId = Convert.ToInt64((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalMilliseconds);
return await SendRequest<TLAbsUpdates>(
new TLRequestSendMessage()
{
peer = peer,
message = message,
random_id = uniqueId
});
}
public async Task<Boolean> SendTyping(TLAbsInputPeer peer)
{
var req = new TLRequestSetTyping()
{
action = new TLSendMessageTypingAction(),
peer = peer
};
return await SendRequest<Boolean>(req);
}
public async Task<TLDialogs> GetUserDialogs()
{
var peer = new TLInputPeerSelf();
return await SendRequest<TLDialogs>(
new TLRequestGetDialogs() { offset_date = 0, offset_peer = peer, limit = 100 });
}
private void OnUserAuthenticated(TLUser TLUser)
{
_session.TLUser = TLUser;
_session.SessionExpires = int.MaxValue;

View file

@ -7,7 +7,7 @@ using System.Threading.Tasks;
using TeleSharp.TL;
namespace TeleSharp.TL.Auth
{
[TLObject(-2035355412)]
[TLObject(-2035355412)]
public class TLRequestSendCode : TLMethod
{
public override int Constructor
@ -18,55 +18,55 @@ namespace TeleSharp.TL.Auth
}
}
public int flags { get; set; }
public bool allow_flashcall { get; set; }
public string phone_number { get; set; }
public bool? current_number { get; set; }
public int api_id { get; set; }
public string api_hash { get; set; }
public Auth.TLSentCode Response { get; set; }
public int flags {get;set;}
public bool allow_flashcall {get;set;}
public string phone_number {get;set;}
public bool? current_number {get;set;}
public int api_id {get;set;}
public string api_hash {get;set;}
public Auth.TLSentCode Response{ get; set;}
public void ComputeFlags()
{
flags = 0;
flags = allow_flashcall ? (flags | 1) : (flags & ~1);
flags = current_number != null ? (flags | 1) : (flags & ~1);
public void ComputeFlags()
{
flags = 0;
flags = allow_flashcall ? (flags | 1) : (flags & ~1);
flags = current_number != null ? (flags | 1) : (flags & ~1);
}
}
public override void DeserializeBody(BinaryReader br)
{
flags = br.ReadInt32();
allow_flashcall = (flags & 1) != 0;
phone_number = StringUtil.Deserialize(br);
if ((flags & 1) != 0)
current_number = BoolUtil.Deserialize(br);
else
current_number = null;
allow_flashcall = (flags & 1) != 0;
phone_number = StringUtil.Deserialize(br);
if ((flags & 1) != 0)
current_number = BoolUtil.Deserialize(br);
else
current_number = null;
api_id = br.ReadInt32();
api_hash = StringUtil.Deserialize(br);
api_id = br.ReadInt32();
api_hash = StringUtil.Deserialize(br);
}
public override void SerializeBody(BinaryWriter bw)
{
bw.Write(Constructor);
bw.Write(Constructor);
ComputeFlags();
bw.Write(flags);
bw.Write(flags);
StringUtil.Serialize(phone_number, bw);
if ((flags & 1) != 0)
BoolUtil.Serialize(current_number.Value, bw);
bw.Write(api_id);
StringUtil.Serialize(api_hash, bw);
StringUtil.Serialize(phone_number,bw);
if ((flags & 1) != 0)
BoolUtil.Serialize(current_number.Value,bw);
bw.Write(api_id);
StringUtil.Serialize(api_hash,bw);
}
public override void deserializeResponse(BinaryReader br)
{
Response = (Auth.TLSentCode)ObjectUtils.DeserializeObject(br);
public override void deserializeResponse(BinaryReader br)
{
Response = (Auth.TLSentCode)ObjectUtils.DeserializeObject(br);
}
}
}
}

View file

@ -30,7 +30,7 @@ namespace TeleSharp.TL.Contacts
public override void DeserializeBody(BinaryReader br)
{
contacts = (TLVector<TLInputPhoneContact>)ObjectUtils.DeserializeVector<TLInputPhoneContact>(br);
contacts = ObjectUtils.DeserializeVector<TLInputPhoneContact>(br);
replace = BoolUtil.Deserialize(br);
}

View file

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TeleSharp.TL;
namespace TeleSharp.TL
{
public abstract class TLAbsBool : TLObject
{
}
}

View file

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TeleSharp.TL;
namespace TeleSharp.TL
{
[TLObject(-1132882121)]
public class TLBoolFalse : TLAbsBool
{
public override int Constructor
{
get
{
return -1132882121;
}
}
public void ComputeFlags()
{
}
public override void DeserializeBody(BinaryReader br)
{
}
public override void SerializeBody(BinaryWriter bw)
{
bw.Write(Constructor);
}
}
}

View file

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TeleSharp.TL;
namespace TeleSharp.TL
{
[TLObject(-1720552011)]
public class TLBoolTrue : TLAbsBool
{
public override int Constructor
{
get
{
return -1720552011;
}
}
public void ComputeFlags()
{
}
public override void DeserializeBody(BinaryReader br)
{
}
public override void SerializeBody(BinaryWriter bw)
{
bw.Write(Constructor);
}
}
}

39
TeleSharp.TL/TL/TLTrue.cs Normal file
View file

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TeleSharp.TL;
namespace TeleSharp.TL
{
[TLObject(1072550713)]
public class TLTrue : TLObject
{
public override int Constructor
{
get
{
return 1072550713;
}
}
public void ComputeFlags()
{
}
public override void DeserializeBody(BinaryReader br)
{
}
public override void SerializeBody(BinaryWriter bw)
{
bw.Write(Constructor);
}
}
}

View file

@ -53,7 +53,11 @@ namespace TeleSharp.TL
public override void SerializeBody(BinaryWriter bw)
{
throw new NotImplementedException();
bw.Write(Constructor);
foreach (var item in lists.Cast<TLObject>())
{
item.SerializeBody(bw);
}
}
}
}

View file

@ -301,6 +301,7 @@
<Compile Include="TL\Storage\TLFilePng.cs" />
<Compile Include="TL\Storage\TLFileUnknown.cs" />
<Compile Include="TL\Storage\TLFileWebp.cs" />
<Compile Include="TL\TLAbsBool.cs" />
<Compile Include="TL\TLAbsBotInlineMessage.cs" />
<Compile Include="TL\TLAbsBotInlineResult.cs" />
<Compile Include="TL\TLAbsChannelMessagesFilter.cs" />
@ -370,6 +371,8 @@
<Compile Include="TL\TLAbsWebPage.cs" />
<Compile Include="TL\TLAccountDaysTTL.cs" />
<Compile Include="TL\TLAuthorization.cs" />
<Compile Include="TL\TLBoolFalse.cs" />
<Compile Include="TL\TLBoolTrue.cs" />
<Compile Include="TL\TLBotCommand.cs" />
<Compile Include="TL\TLBotInfo.cs" />
<Compile Include="TL\TLBotInlineMediaResult.cs" />
@ -639,6 +642,7 @@
<Compile Include="TL\TLTopPeerCategoryCorrespondents.cs" />
<Compile Include="TL\TLTopPeerCategoryGroups.cs" />
<Compile Include="TL\TLTopPeerCategoryPeers.cs" />
<Compile Include="TL\TLTrue.cs" />
<Compile Include="TL\TLUpdateBotCallbackQuery.cs" />
<Compile Include="TL\TLUpdateBotInlineQuery.cs" />
<Compile Include="TL\TLUpdateBotInlineSend.cs" />