diff --git a/TelegramBotBase.Extensions.Images/ImageExtensions.cs b/TelegramBotBase.Extensions.Images/ImageExtensions.cs index 7ed5dc0..e394c74 100644 --- a/TelegramBotBase.Extensions.Images/ImageExtensions.cs +++ b/TelegramBotBase.Extensions.Images/ImageExtensions.cs @@ -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); } diff --git a/TelegramBotBase.Test/Tests/DataForm.cs b/TelegramBotBase.Test/Tests/DataForm.cs index 49554d0..aa77bc1 100644 --- a/TelegramBotBase.Test/Tests/DataForm.cs +++ b/TelegramBotBase.Test/Tests/DataForm.cs @@ -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); diff --git a/TelegramBotBase.Test/Tests/Groups/LinkReplaceTest.cs b/TelegramBotBase.Test/Tests/Groups/LinkReplaceTest.cs index 69bc1ad..9d8e6c5 100644 --- a/TelegramBotBase.Test/Tests/Groups/LinkReplaceTest.cs +++ b/TelegramBotBase.Test/Tests/Groups/LinkReplaceTest.cs @@ -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"); diff --git a/TelegramBotBase/Base/DataResult.cs b/TelegramBotBase/Base/DataResult.cs index 14c7d9b..c7be873 100644 --- a/TelegramBotBase/Base/DataResult.cs +++ b/TelegramBotBase/Base/DataResult.cs @@ -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 DownloadDocument() + public async Task 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 DownloadVideo() + public async Task 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 DownloadAudio() + public async Task 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 DownloadPhoto(int index) + public async Task 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) diff --git a/TelegramBotBase/MessageLoops/FormBaseMessageLoop.cs b/TelegramBotBase/MessageLoops/FormBaseMessageLoop.cs index f1a2d39..0069c1b 100644 --- a/TelegramBotBase/MessageLoops/FormBaseMessageLoop.cs +++ b/TelegramBotBase/MessageLoops/FormBaseMessageLoop.cs @@ -44,6 +44,7 @@ public class FormBaseMessageLoop : IMessageLoopFactory } mr.Device = session; + ur.Device = session; var activeForm = session.ActiveForm; diff --git a/TelegramBotBase/MessageLoops/FullMessageLoop.cs b/TelegramBotBase/MessageLoops/FullMessageLoop.cs index b7855c6..2c4b1b9 100644 --- a/TelegramBotBase/MessageLoops/FullMessageLoop.cs +++ b/TelegramBotBase/MessageLoops/FullMessageLoop.cs @@ -37,6 +37,7 @@ public class FullMessageLoop : IMessageLoopFactory } mr.Device = session; + ur.Device = session; var activeForm = session.ActiveForm; diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index f823c59..50ad65e 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -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 /// /// /// - public async Task SendPhoto(InputOnlineFile file, string caption = null, ButtonForm buttons = null, + public async Task 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 /// /// /// - public async Task SendVideo(InputOnlineFile file, string caption = null, ButtonForm buttons = null, + public async Task 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 /// /// /// - public async Task SendDocument(InputOnlineFile document, string caption = "", + public async Task 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 { diff --git a/TelegramBotBase/TelegramBotBase.csproj b/TelegramBotBase/TelegramBotBase.csproj index 12c0a79..7efdd5c 100644 --- a/TelegramBotBase/TelegramBotBase.csproj +++ b/TelegramBotBase/TelegramBotBase.csproj @@ -57,7 +57,7 @@ - + diff --git a/TelegramBotBase/TelegramBotBase.nuspec b/TelegramBotBase/TelegramBotBase.nuspec index 7e14769..5dfff90 100644 --- a/TelegramBotBase/TelegramBotBase.nuspec +++ b/TelegramBotBase/TelegramBotBase.nuspec @@ -15,12 +15,12 @@ - + - +