-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoginTest.cs
81 lines (67 loc) · 2.48 KB
/
LoginTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using Microsoft.EntityFrameworkCore;
using MTProto.Client;
using MTProto.Client.Events;
using MTProto.Utils.Md;
namespace MTProto.Tests.Auth
{
public class LoginTest
{
[Fact]
public async void Test1()
{
//TODO: load these variables from env or from config file.
var client = new MTProtoClient(
botToken: "",
apiId: "",
apiHash: ""
);
Assert.NotNull(await client.Start());
var md = MdContainer.GetNormal(client, "hello ! ,,").Bold("\nHow are you doing??");
await client.SendMessage("Falling_inside_the_black", md);
client.EventNewMessage += NewMessageHandler;
client.EventNewChannelMessage += NewChannelMessageHandler;
Thread.Sleep(1000000);
client.Close();
}
[Fact]
public async void TestGetAllPeerInfos()
{
//TODO: load these variables from env or from config file.
var client = new MTProtoClient(
botToken: "",
apiId: "",
apiHash: ""
);
Assert.NotNull(await client.Start());
var infos = client.MTProtoDatabase.PeerInfos.FromSql($"SELECT * FROM PeerInfos")
.ToList();
Assert.NotNull(infos);
infos = client.MTProtoDatabase.PeerInfos.FromSql(
$"SELECT * FROM PeerInfos WHERE PeerId = 1341091260"
).ToList();
Assert.NotNull(infos);
Console.WriteLine(infos);
}
private static async Task NewMessageHandler(MTProtoClientBase c, TL.UpdateNewMessage update)
{
if (update.message is TL.Message msg)
{
if (update.message.From?.ID == c.CachedMe?.ID)
return;
await c.SendMessage(update.message.Peer, MdContainer.GetNormal(c, "got your message!"), msg.ID);
Console.WriteLine(msg.message);
}
}
private static async Task NewChannelMessageHandler(MTProtoClientBase c, TL.UpdateNewChannelMessage update)
{
if (update.message is TL.Message msg)
{
if (update.message.From?.ID == c.CachedMe?.ID)
return;
await c.SendMessage(update.message.Peer, MdContainer.GetNormal(c, "got your message!"), msg.ID);
Console.WriteLine(msg.message);
}
}
}
}