Fixing class renaming of TelegramBot framework 18 to 19

This commit is contained in:
FlorianDahn 2023-09-09 18:49:52 +02:00
parent 375362ac46
commit 0700e1e1ba
9 changed files with 44 additions and 38 deletions

View File

@ -3,7 +3,6 @@ using System.Drawing.Imaging;
using System.IO;
using System.Threading.Tasks;
using Telegram.Bot.Types;
using Telegram.Bot.Types.InputFiles;
using TelegramBotBase.Form;
using TelegramBotBase.Sessions;
@ -34,7 +33,7 @@ namespace TelegramBotBase.Extensions.Images
{
using (var fileStream = ToStream(image, ImageFormat.Png))
{
var fts = new InputOnlineFile(fileStream, name);
var fts = InputFile.FromStream(fileStream, name);
return await session.SendPhoto(fts, caption, buttons, replyTo, disableNotification);
}
@ -55,7 +54,7 @@ namespace TelegramBotBase.Extensions.Images
{
using (var fileStream = ToStream(image, ImageFormat.Png))
{
var fts = new InputOnlineFile(fileStream, name);
var fts = InputFile.FromStream(fileStream, name);
return await session.SendPhoto(fts, caption, buttons, replyTo, disableNotification);
}

View File

@ -1,8 +1,8 @@
using System.Linq;
using System.Threading.Tasks;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.InputFiles;
using Telegram.Bot.Types.ReplyMarkups;
using TelegramBotBase.Base;
using TelegramBotBase.Form;
@ -14,7 +14,7 @@ public class DataForm : AutoCleanForm
public override async Task SentData(DataResult data)
{
var tmp = "";
InputOnlineFile file;
InputFile file;
switch (data.Type)
{
@ -31,7 +31,7 @@ public class DataForm : AutoCleanForm
case MessageType.Document:
file = new InputOnlineFile(data.Document.FileId);
file = InputFile.FromString(data.Document.FileId);
await Device.SendDocument(file, "Your uploaded document");
@ -40,7 +40,7 @@ public class DataForm : AutoCleanForm
case MessageType.Video:
file = new InputOnlineFile(data.Document.FileId);
file = InputFile.FromString(data.Document.FileId);
await Device.SendDocument(file, "Your uploaded video");
@ -48,7 +48,7 @@ public class DataForm : AutoCleanForm
case MessageType.Audio:
file = new InputOnlineFile(data.Document.FileId);
file = InputFile.FromString(data.Document.FileId);
await Device.SendDocument(file, "Your uploaded audio");
@ -65,7 +65,7 @@ public class DataForm : AutoCleanForm
case MessageType.Photo:
var photo = new InputOnlineFile(data.Photos.Last().FileId);
var photo = InputFile.FromString(data.Photos.Last().FileId);
await Device.Send("Your image: ", replyTo: data.MessageId);
await Client.TelegramClient.SendPhotoAsync(Device.DeviceId, photo);

View File

@ -102,7 +102,13 @@ public class LinkReplaceTest : GroupForm
CanChangeInfo = false,
CanInviteUsers = false,
CanPinMessages = false,
CanSendMediaMessages = false,
CanManageTopics = false,
CanSendAudios = false,
CanSendVideos = false,
CanSendDocuments = false,
CanSendPhotos = false,
CanSendVideoNotes = false,
CanSendVoiceNotes = false,
CanSendMessages = false,
CanSendOtherMessages = false,
CanSendPolls = false
@ -128,7 +134,7 @@ public class LinkReplaceTest : GroupForm
}
else
{
await e.Device.RestrictUser(from, cp, DateTime.UtcNow.AddSeconds(30));
await e.Device.RestrictUser(from, cp, null, DateTime.UtcNow.AddSeconds(30));
await e.Device.Send(e.Message.From.FirstName + " " + e.Message.From.LastName +
" has been blocked for 30 seconds");

View File

@ -5,7 +5,6 @@ using System.Threading.Tasks;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.InputFiles;
namespace TelegramBotBase.Base;
@ -17,6 +16,7 @@ public class DataResult : ResultBase
public DataResult(UpdateResult update)
{
UpdateData = update;
Device = update.Device;
}
//public Telegram.Bot.Args.MessageEventArgs RawMessageData { get; set; }
@ -51,14 +51,14 @@ public class DataResult : ResultBase
Photos.FirstOrDefault()?.FileId;
public async Task<InputOnlineFile> DownloadDocument()
public async Task<InputFileStream> DownloadDocument()
{
var encryptedContent = new MemoryStream();
encryptedContent.SetLength(Document.FileSize.Value);
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Document.FileId,
encryptedContent);
return new InputOnlineFile(encryptedContent, Document.FileName);
return new InputFileStream(encryptedContent, Document.FileName);
}
@ -112,13 +112,13 @@ public class DataResult : ResultBase
return sr.ReadToEnd();
}
public async Task<InputOnlineFile> DownloadVideo()
public async Task<InputFileStream> DownloadVideo()
{
var encryptedContent = new MemoryStream();
encryptedContent.SetLength(Video.FileSize.Value);
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Video.FileId, encryptedContent);
return new InputOnlineFile(encryptedContent, "");
return new InputFileStream(encryptedContent, "");
}
public async Task DownloadVideo(string path)
@ -130,13 +130,13 @@ public class DataResult : ResultBase
fs.Dispose();
}
public async Task<InputOnlineFile> DownloadAudio()
public async Task<InputFileStream> DownloadAudio()
{
var encryptedContent = new MemoryStream();
encryptedContent.SetLength(Audio.FileSize.Value);
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(Audio.FileId, encryptedContent);
return new InputOnlineFile(encryptedContent, "");
return new InputFileStream(encryptedContent, "");
}
public async Task DownloadAudio(string path)
@ -148,14 +148,14 @@ public class DataResult : ResultBase
fs.Dispose();
}
public async Task<InputOnlineFile> DownloadPhoto(int index)
public async Task<InputFileStream> DownloadPhoto(int index)
{
var photo = Photos[index];
var encryptedContent = new MemoryStream();
encryptedContent.SetLength(photo.FileSize.Value);
var file = await Device.Client.TelegramClient.GetInfoAndDownloadFileAsync(photo.FileId, encryptedContent);
return new InputOnlineFile(encryptedContent, "");
return new InputFileStream(encryptedContent, "");
}
public async Task DownloadPhoto(int index, string path)

View File

@ -44,6 +44,7 @@ public class FormBaseMessageLoop : IMessageLoopFactory
}
mr.Device = session;
ur.Device = session;
var activeForm = session.ActiveForm;

View File

@ -37,6 +37,7 @@ public class FullMessageLoop : IMessageLoopFactory
}
mr.Device = session;
ur.Device = session;
var activeForm = session.ActiveForm;

View File

@ -9,7 +9,6 @@ using Telegram.Bot;
using Telegram.Bot.Exceptions;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.InputFiles;
using Telegram.Bot.Types.ReplyMarkups;
using TelegramBotBase.Args;
using TelegramBotBase.Base;
@ -280,7 +279,7 @@ public class DeviceSession : IDeviceSession
try
{
var t = Api(a => a.SendTextMessageAsync(deviceId, text, parseMode, replyToMessageId: replyTo,
var t = Api(a => a.SendTextMessageAsync(deviceId, text, null, parseMode, replyToMessageId: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
var o = GetOrigin(new StackTrace());
@ -339,7 +338,7 @@ public class DeviceSession : IDeviceSession
try
{
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, parseMode, replyToMessageId: replyTo,
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
var o = GetOrigin(new StackTrace());
@ -382,7 +381,7 @@ public class DeviceSession : IDeviceSession
try
{
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, parseMode, replyToMessageId: replyTo,
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
var o = GetOrigin(new StackTrace());
@ -404,7 +403,7 @@ public class DeviceSession : IDeviceSession
/// <param name="replyTo"></param>
/// <param name="disableNotification"></param>
/// <returns></returns>
public async Task<Message> SendPhoto(InputOnlineFile file, string caption = null, ButtonForm buttons = null,
public async Task<Message> SendPhoto(InputFile file, string caption = null, ButtonForm buttons = null,
int replyTo = 0, bool disableNotification = false,
ParseMode parseMode = ParseMode.Markdown)
{
@ -417,7 +416,7 @@ public class DeviceSession : IDeviceSession
try
{
var t = Api(a => a.SendPhotoAsync(DeviceId, file, caption, parseMode, replyToMessageId: replyTo,
var t = Api(a => a.SendPhotoAsync(DeviceId, file, null, caption, parseMode, replyToMessageId: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
var o = GetOrigin(new StackTrace());
@ -439,7 +438,7 @@ public class DeviceSession : IDeviceSession
/// <param name="replyTo"></param>
/// <param name="disableNotification"></param>
/// <returns></returns>
public async Task<Message> SendVideo(InputOnlineFile file, string caption = null, ButtonForm buttons = null,
public async Task<Message> SendVideo(InputFile file, string caption = null, ButtonForm buttons = null,
int replyTo = 0, bool disableNotification = false,
ParseMode parseMode = ParseMode.Markdown)
{
@ -487,7 +486,7 @@ public class DeviceSession : IDeviceSession
try
{
var t = Api(a => a.SendVideoAsync(DeviceId, new InputOnlineFile(url), parseMode: parseMode,
var t = Api(a => a.SendVideoAsync(DeviceId, InputFile.FromUri(url), parseMode: parseMode,
replyToMessageId: replyTo, replyMarkup: markup,
disableNotification: disableNotification));
@ -525,7 +524,7 @@ public class DeviceSession : IDeviceSession
{
var ms = new MemoryStream(video);
var fts = new InputOnlineFile(ms, filename);
var fts = InputFile.FromStream(ms, filename);
var t = Api(a => a.SendVideoAsync(DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
@ -567,7 +566,7 @@ public class DeviceSession : IDeviceSession
var filename = Path.GetFileName(filepath);
var fts = new InputOnlineFile(fs, filename);
var fts = InputFile.FromStream(fs, filename);
var t = Api(a => a.SendVideoAsync(DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
@ -599,7 +598,7 @@ public class DeviceSession : IDeviceSession
{
var ms = new MemoryStream(document);
var fts = new InputOnlineFile(ms, filename);
var fts = InputFile.FromStream(ms, filename);
return await SendDocument(fts, caption, buttons, replyTo, disableNotification);
}
@ -641,7 +640,7 @@ public class DeviceSession : IDeviceSession
/// <param name="replyTo"></param>
/// <param name="disableNotification"></param>
/// <returns></returns>
public async Task<Message> SendDocument(InputOnlineFile document, string caption = "",
public async Task<Message> SendDocument(InputFile document, string caption = "",
ButtonForm buttons = null, int replyTo = 0,
bool disableNotification = false)
{
@ -653,7 +652,7 @@ public class DeviceSession : IDeviceSession
try
{
var t = Api(a => a.SendDocumentAsync(DeviceId, document, caption, replyMarkup: markup,
var t = Api(a => a.SendDocumentAsync(DeviceId, document, null, null, caption, replyMarkup: markup,
disableNotification: disableNotification, replyToMessageId: replyTo));
var o = GetOrigin(new StackTrace());
@ -866,11 +865,11 @@ public class DeviceSession : IDeviceSession
#region "Users"
public virtual async Task RestrictUser(long userId, ChatPermissions permissions, DateTime until = default)
public virtual async Task RestrictUser(long userId, ChatPermissions permissions, bool? useIndependentGroupPermission = null, DateTime until = default)
{
try
{
await Api(a => a.RestrictChatMemberAsync(DeviceId, userId, permissions, until));
await Api(a => a.RestrictChatMemberAsync(DeviceId, userId, permissions, useIndependentGroupPermission, until));
}
catch
{

View File

@ -57,7 +57,7 @@
<ItemGroup>
<PackageReference Include="Telegram.Bot" Version="18.0.0" />
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
<PackageReference Include="Telegram.Bot.Extensions.Polling" Version="1.0.2" />
</ItemGroup>

View File

@ -15,12 +15,12 @@
<group targetFramework=".NETFramework4.6.1">
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
<dependency id="System.Drawing.Common" version="4.6.0" exclude="Build,Analyzers" />
<dependency id="Telegram.Bot" version="15.0.0" exclude="Build,Analyzers" />
<dependency id="Telegram.Bot" version="19.0.0" exclude="Build,Analyzers" />
</group>
<group targetFramework=".NETStandard2.0">
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
<dependency id="System.Drawing.Common" version="4.6.0" exclude="Build,Analyzers" />
<dependency id="Telegram.Bot" version="15.0.0" exclude="Build,Analyzers" />
<dependency id="Telegram.Bot" version="19.0.0" exclude="Build,Analyzers" />
</group>
</dependencies>
</metadata>