Breakable change! Remove of most try/catch's in DeviceSession

This commit is contained in:
Florian Zevedei 2024-05-25 17:24:24 +02:00
parent 175927fbab
commit 7a86ecdf32

View File

@ -131,13 +131,9 @@ public class DeviceSession : IDeviceSession
public async Task ConfirmAction(string callbackQueryId, string message = "", bool showAlert = false,
string urlToOpen = null)
{
try
{
await Client.TelegramClient.AnswerCallbackQueryAsync(callbackQueryId, message, showAlert, urlToOpen);
}
catch
{
}
}
/// <summary>
@ -157,17 +153,8 @@ public class DeviceSession : IDeviceSession
throw new MessageTooLongException(text.Length);
}
try
{
return await Api(a =>
a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
}
catch
{
}
return null;
return await Api(a => a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
}
/// <summary>
@ -185,17 +172,9 @@ public class DeviceSession : IDeviceSession
throw new MessageTooLongException(text.Length);
}
try
{
return await Api(a =>
a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
}
catch
{
}
return await Api(a => a.EditMessageTextAsync(DeviceId, messageId, text, parseMode, replyMarkup: markup));
return null;
}
/// <summary>
@ -215,19 +194,9 @@ public class DeviceSession : IDeviceSession
throw new MessageTooLongException(message.Text.Length);
}
try
{
return await Api(a =>
a.EditMessageTextAsync(DeviceId, message.MessageId, message.Text, parseMode,
return await Api(a => a.EditMessageTextAsync(DeviceId, message.MessageId, message.Text, parseMode,
replyMarkup: markup));
}
catch
{
}
return null;
}
/// <summary>
/// Edits the reply keyboard markup (buttons)
@ -237,15 +206,8 @@ public class DeviceSession : IDeviceSession
/// <returns></returns>
public async Task<Message> EditReplyMarkup(int messageId, ButtonForm bf)
{
try
{
return await Api(a => a.EditMessageReplyMarkupAsync(DeviceId, messageId, bf));
}
catch
{
}
return null;
return await Api(a => a.EditMessageReplyMarkupAsync(DeviceId, messageId, bf));
}
/// <summary>
@ -277,8 +239,7 @@ public class DeviceSession : IDeviceSession
text = text.MarkdownV2Escape();
}
try
{
var t = Api(a => a.SendTextMessageAsync(deviceId, text, null, parseMode, replyToMessageId: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
@ -287,11 +248,7 @@ public class DeviceSession : IDeviceSession
await OnMessageSent(new MessageSentEventArgs(await t, o));
return await t;
}
catch
{
return null;
}
}
/// <summary>
@ -336,8 +293,7 @@ public class DeviceSession : IDeviceSession
text = text.MarkdownV2Escape();
}
try
{
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
@ -345,11 +301,7 @@ public class DeviceSession : IDeviceSession
await OnMessageSent(new MessageSentEventArgs(await t, o));
return await t;
}
catch
{
return null;
}
}
/// <summary>
@ -379,8 +331,7 @@ public class DeviceSession : IDeviceSession
text = text.MarkdownV2Escape();
}
try
{
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
@ -388,11 +339,7 @@ public class DeviceSession : IDeviceSession
await OnMessageSent(new MessageSentEventArgs(await t, o));
return await t;
}
catch
{
return null;
}
}
/// <summary>
@ -414,8 +361,7 @@ public class DeviceSession : IDeviceSession
InlineKeyboardMarkup markup = buttons;
try
{
var t = Api(a => a.SendPhotoAsync(DeviceId, file, null, caption, parseMode, replyToMessageId: replyTo,
replyMarkup: markup, disableNotification: disableNotification));
@ -423,11 +369,7 @@ public class DeviceSession : IDeviceSession
await OnMessageSent(new MessageSentEventArgs(await t, o));
return await t;
}
catch
{
return null;
}
}
/// <summary>
@ -449,8 +391,7 @@ public class DeviceSession : IDeviceSession
InlineKeyboardMarkup markup = buttons;
try
{
var t = Api(a => a.SendVideoAsync(DeviceId, file, caption: caption, parseMode: parseMode,
replyToMessageId: replyTo, replyMarkup: markup,
disableNotification: disableNotification));
@ -459,11 +400,7 @@ public class DeviceSession : IDeviceSession
await OnMessageSent(new MessageSentEventArgs(await t, o));
return await t;
}
catch
{
return null;
}
}
/// <summary>
@ -484,8 +421,7 @@ public class DeviceSession : IDeviceSession
InlineKeyboardMarkup markup = buttons;
try
{
var t = Api(a => a.SendVideoAsync(DeviceId, InputFile.FromUri(url), parseMode: parseMode,
replyToMessageId: replyTo, replyMarkup: markup,
disableNotification: disableNotification));
@ -494,11 +430,7 @@ public class DeviceSession : IDeviceSession
await OnMessageSent(new MessageSentEventArgs(await t, o));
return await t;
}
catch
{
return null;
}
}
/// <summary>
@ -520,8 +452,7 @@ public class DeviceSession : IDeviceSession
InlineKeyboardMarkup markup = buttons;
try
{
var ms = new MemoryStream(video);
var fts = InputFile.FromStream(ms, filename);
@ -533,11 +464,7 @@ public class DeviceSession : IDeviceSession
await OnMessageSent(new MessageSentEventArgs(await t, o));
return await t;
}
catch
{
return null;
}
}
/// <summary>
@ -560,8 +487,7 @@ public class DeviceSession : IDeviceSession
InlineKeyboardMarkup markup = buttons;
try
{
var fs = new FileStream(filepath, FileMode.Open);
var filename = Path.GetFileName(filepath);
@ -575,11 +501,7 @@ public class DeviceSession : IDeviceSession
await OnMessageSent(new MessageSentEventArgs(await t, o));
return await t;
}
catch
{
return null;
}
}
/// <summary>
@ -650,8 +572,7 @@ public class DeviceSession : IDeviceSession
markup = buttons;
}
try
{
var t = Api(a => a.SendDocumentAsync(DeviceId, document, null, null, caption, replyMarkup: markup,
disableNotification: disableNotification, replyToMessageId: replyTo));
@ -659,11 +580,7 @@ public class DeviceSession : IDeviceSession
await OnMessageSent(new MessageSentEventArgs(await t, o));
return await t;
}
catch
{
return null;
}
}
/// <summary>
@ -714,8 +631,7 @@ public class DeviceSession : IDeviceSession
public async Task<Message> HideReplyKeyboard(string closedMsg = "Closed", bool autoDeleteResponse = true)
{
try
{
var m = await Send(closedMsg, new ReplyKeyboardRemove());
if (autoDeleteResponse && m != null)
@ -724,12 +640,7 @@ public class DeviceSession : IDeviceSession
}
return m;
}
catch
{
}
return null;
}
/// <summary>
@ -759,13 +670,9 @@ public class DeviceSession : IDeviceSession
public virtual async Task ChangeChatPermissions(ChatPermissions permissions)
{
try
{
await Api(a => a.SetChatPermissionsAsync(DeviceId, permissions));
}
catch
{
}
}
private Type GetOrigin(StackTrace stackTrace)
@ -878,49 +785,31 @@ public class DeviceSession : IDeviceSession
public virtual async Task<ChatMember> GetChatUser(long userId)
{
try
{
return await Api(a => a.GetChatMemberAsync(DeviceId, userId));
}
catch
{
}
return null;
return await Api(a => a.GetChatMemberAsync(DeviceId, userId));
}
[Obsolete("User BanUser instead.")]
public virtual async Task KickUser(long userId, DateTime until = default)
{
try
{
await Api(a => a.BanChatMemberAsync(DeviceId, userId, until));
}
catch
{
}
}
public virtual async Task BanUser(long userId, DateTime until = default)
{
try
{
await Api(a => a.BanChatMemberAsync(DeviceId, userId, until));
}
catch
{
}
}
public virtual async Task UnbanUser(long userId)
{
try
{
await Api(a => a.UnbanChatMemberAsync(DeviceId, userId));
}
catch
{
}
}
#endregion