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 MD5 = System.Security.Cryptography.MD5;
using TeleSharp.TL.Help; using TeleSharp.TL.Help;
using TeleSharp.TL.Auth; using TeleSharp.TL.Auth;
using TeleSharp.TL.Contacts;
using TeleSharp.TL.Messages;
namespace TLSharp.Core namespace TLSharp.Core
{ {
@ -153,8 +155,56 @@ namespace TLSharp.Core
{ {
await _sender.Send(methodtoExceute); await _sender.Send(methodtoExceute);
await _sender.Receive(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;
} }
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) private void OnUserAuthenticated(TLUser TLUser)
{ {
_session.TLUser = TLUser; _session.TLUser = TLUser;

View file

@ -30,7 +30,7 @@ namespace TeleSharp.TL.Contacts
public override void DeserializeBody(BinaryReader br) public override void DeserializeBody(BinaryReader br)
{ {
contacts = (TLVector<TLInputPhoneContact>)ObjectUtils.DeserializeVector<TLInputPhoneContact>(br); contacts = ObjectUtils.DeserializeVector<TLInputPhoneContact>(br);
replace = BoolUtil.Deserialize(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) 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\TLFilePng.cs" />
<Compile Include="TL\Storage\TLFileUnknown.cs" /> <Compile Include="TL\Storage\TLFileUnknown.cs" />
<Compile Include="TL\Storage\TLFileWebp.cs" /> <Compile Include="TL\Storage\TLFileWebp.cs" />
<Compile Include="TL\TLAbsBool.cs" />
<Compile Include="TL\TLAbsBotInlineMessage.cs" /> <Compile Include="TL\TLAbsBotInlineMessage.cs" />
<Compile Include="TL\TLAbsBotInlineResult.cs" /> <Compile Include="TL\TLAbsBotInlineResult.cs" />
<Compile Include="TL\TLAbsChannelMessagesFilter.cs" /> <Compile Include="TL\TLAbsChannelMessagesFilter.cs" />
@ -370,6 +371,8 @@
<Compile Include="TL\TLAbsWebPage.cs" /> <Compile Include="TL\TLAbsWebPage.cs" />
<Compile Include="TL\TLAccountDaysTTL.cs" /> <Compile Include="TL\TLAccountDaysTTL.cs" />
<Compile Include="TL\TLAuthorization.cs" /> <Compile Include="TL\TLAuthorization.cs" />
<Compile Include="TL\TLBoolFalse.cs" />
<Compile Include="TL\TLBoolTrue.cs" />
<Compile Include="TL\TLBotCommand.cs" /> <Compile Include="TL\TLBotCommand.cs" />
<Compile Include="TL\TLBotInfo.cs" /> <Compile Include="TL\TLBotInfo.cs" />
<Compile Include="TL\TLBotInlineMediaResult.cs" /> <Compile Include="TL\TLBotInlineMediaResult.cs" />
@ -639,6 +642,7 @@
<Compile Include="TL\TLTopPeerCategoryCorrespondents.cs" /> <Compile Include="TL\TLTopPeerCategoryCorrespondents.cs" />
<Compile Include="TL\TLTopPeerCategoryGroups.cs" /> <Compile Include="TL\TLTopPeerCategoryGroups.cs" />
<Compile Include="TL\TLTopPeerCategoryPeers.cs" /> <Compile Include="TL\TLTopPeerCategoryPeers.cs" />
<Compile Include="TL\TLTrue.cs" />
<Compile Include="TL\TLUpdateBotCallbackQuery.cs" /> <Compile Include="TL\TLUpdateBotCallbackQuery.cs" />
<Compile Include="TL\TLUpdateBotInlineQuery.cs" /> <Compile Include="TL\TLUpdateBotInlineQuery.cs" />
<Compile Include="TL\TLUpdateBotInlineSend.cs" /> <Compile Include="TL\TLUpdateBotInlineSend.cs" />