Replacing Client in ResultBase and subclasses
- replace Client with Device to allow more access - making Client in DeviceSession public to allow access from outside
This commit is contained in:
parent
d08cbe8b0e
commit
72a1fa3c99
@ -109,7 +109,7 @@ namespace TelegramBotBase.Base
|
||||
public async Task<InputOnlineFile> DownloadDocument()
|
||||
{
|
||||
var encryptedContent = new System.IO.MemoryStream(this.Document.FileSize.Value);
|
||||
var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, encryptedContent);
|
||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, encryptedContent);
|
||||
|
||||
return new InputOnlineFile(encryptedContent, this.Document.FileName);
|
||||
}
|
||||
@ -122,9 +122,9 @@ namespace TelegramBotBase.Base
|
||||
/// <returns></returns>
|
||||
public async Task DownloadDocument(String path)
|
||||
{
|
||||
var file = await this.Client.TelegramClient.GetFileAsync(this.Document.FileId);
|
||||
var file = await Device.Client.TelegramClient.GetFileAsync(this.Document.FileId);
|
||||
FileStream fs = new FileStream(path, FileMode.Create);
|
||||
await this.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
fs.Close();
|
||||
fs.Dispose();
|
||||
}
|
||||
@ -136,7 +136,7 @@ namespace TelegramBotBase.Base
|
||||
public async Task<byte[]> DownloadRawDocument()
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, ms);
|
||||
await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, ms);
|
||||
return ms.ToArray();
|
||||
}
|
||||
|
||||
@ -156,7 +156,7 @@ namespace TelegramBotBase.Base
|
||||
public async Task<String> DownloadRawTextDocument(Encoding encoding)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, ms);
|
||||
await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Document.FileId, ms);
|
||||
|
||||
ms.Position = 0;
|
||||
|
||||
@ -168,16 +168,16 @@ namespace TelegramBotBase.Base
|
||||
public async Task<InputOnlineFile> DownloadVideo()
|
||||
{
|
||||
var encryptedContent = new System.IO.MemoryStream(this.Video.FileSize.Value);
|
||||
var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Video.FileId, encryptedContent);
|
||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Video.FileId, encryptedContent);
|
||||
|
||||
return new InputOnlineFile(encryptedContent, "");
|
||||
}
|
||||
|
||||
public async Task DownloadVideo(String path)
|
||||
{
|
||||
var file = await this.Client.TelegramClient.GetFileAsync(this.Video.FileId);
|
||||
var file = await Device.Client.TelegramClient.GetFileAsync(this.Video.FileId);
|
||||
FileStream fs = new FileStream(path, FileMode.Create);
|
||||
await this.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
fs.Close();
|
||||
fs.Dispose();
|
||||
}
|
||||
@ -185,16 +185,16 @@ namespace TelegramBotBase.Base
|
||||
public async Task<InputOnlineFile> DownloadAudio()
|
||||
{
|
||||
var encryptedContent = new System.IO.MemoryStream(this.Audio.FileSize.Value);
|
||||
var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Audio.FileId, encryptedContent);
|
||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(this.Audio.FileId, encryptedContent);
|
||||
|
||||
return new InputOnlineFile(encryptedContent, "");
|
||||
}
|
||||
|
||||
public async Task DownloadAudio(String path)
|
||||
{
|
||||
var file = await this.Client.TelegramClient.GetFileAsync(this.Audio.FileId);
|
||||
var file = await Device.Client.TelegramClient.GetFileAsync(this.Audio.FileId);
|
||||
FileStream fs = new FileStream(path, FileMode.Create);
|
||||
await this.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
fs.Close();
|
||||
fs.Dispose();
|
||||
}
|
||||
@ -203,7 +203,7 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
var photo = this.Photos[index];
|
||||
var encryptedContent = new System.IO.MemoryStream(photo.FileSize.Value);
|
||||
var file = await this.Client.TelegramClient.GetInfoAndDownloadFileAsync(photo.FileId, encryptedContent);
|
||||
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(photo.FileId, encryptedContent);
|
||||
|
||||
return new InputOnlineFile(encryptedContent, "");
|
||||
}
|
||||
@ -211,9 +211,9 @@ namespace TelegramBotBase.Base
|
||||
public async Task DownloadPhoto(int index, String path)
|
||||
{
|
||||
var photo = this.Photos[index];
|
||||
var file = await this.Client.TelegramClient.GetFileAsync(photo.FileId);
|
||||
var file = await Device.Client.TelegramClient.GetFileAsync(photo.FileId);
|
||||
FileStream fs = new FileStream(path, FileMode.Create);
|
||||
await this.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
await Device.Client.TelegramClient.DownloadFileAsync(file.FilePath, fs);
|
||||
fs.Close();
|
||||
fs.Dispose();
|
||||
}
|
||||
|
||||
@ -10,15 +10,6 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
public class ResultBase : EventArgs
|
||||
{
|
||||
public MessageClient Client
|
||||
{
|
||||
get
|
||||
{
|
||||
return Device.ActiveForm.Client;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public DeviceSession Device
|
||||
{
|
||||
get;
|
||||
@ -56,7 +47,7 @@ namespace TelegramBotBase.Base
|
||||
{
|
||||
try
|
||||
{
|
||||
await this.Client.TelegramClient.DeleteMessageAsync(this.DeviceId, (messageId == -1 ? this.MessageId : messageId));
|
||||
await Device.Client.TelegramClient.DeleteMessageAsync(this.DeviceId, (messageId == -1 ? this.MessageId : messageId));
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@ -84,7 +84,7 @@ namespace TelegramBotBase.Sessions
|
||||
/// </summary>
|
||||
public Message LastMessage { get; set; }
|
||||
|
||||
private MessageClient Client
|
||||
public MessageClient Client
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user