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