Breakable change! Remove of most try/catch's in DeviceSession
This commit is contained in:
parent
175927fbab
commit
7a86ecdf32
@ -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,18 +194,8 @@ 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,
|
||||||
{
|
replyMarkup: markup));
|
||||||
return await Api(a =>
|
|
||||||
a.EditMessageTextAsync(DeviceId, message.MessageId, message.Text, parseMode,
|
|
||||||
replyMarkup: markup));
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -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,21 +239,16 @@ public class DeviceSession : IDeviceSession
|
|||||||
text = text.MarkdownV2Escape();
|
text = text.MarkdownV2Escape();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var t = Api(a => a.SendTextMessageAsync(deviceId, text, null, parseMode, replyToMessageId: replyTo,
|
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var t = Api(a => a.SendTextMessageAsync(deviceId, text, null, parseMode, replyToMessageId: replyTo,
|
||||||
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
var o = GetOrigin(new StackTrace());
|
||||||
|
|
||||||
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
|
||||||
return await t;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -336,20 +293,15 @@ public class DeviceSession : IDeviceSession
|
|||||||
text = text.MarkdownV2Escape();
|
text = text.MarkdownV2Escape();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
|
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
|
var o = GetOrigin(new StackTrace());
|
||||||
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
|
||||||
return await t;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -379,20 +331,15 @@ public class DeviceSession : IDeviceSession
|
|||||||
text = text.MarkdownV2Escape();
|
text = text.MarkdownV2Escape();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
|
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var t = Api(a => a.SendTextMessageAsync(DeviceId, text, null, parseMode, replyToMessageId: replyTo,
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
|
var o = GetOrigin(new StackTrace());
|
||||||
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
|
||||||
return await t;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -414,20 +361,15 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var t = Api(a => a.SendPhotoAsync(DeviceId, file, null, caption, parseMode, replyToMessageId: replyTo,
|
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var t = Api(a => a.SendPhotoAsync(DeviceId, file, null, caption, parseMode, replyToMessageId: replyTo,
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
|
var o = GetOrigin(new StackTrace());
|
||||||
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
|
||||||
return await t;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -449,21 +391,16 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var t = Api(a => a.SendVideoAsync(DeviceId, file, caption: caption, parseMode: parseMode,
|
|
||||||
replyToMessageId: replyTo, replyMarkup: markup,
|
|
||||||
disableNotification: disableNotification));
|
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var t = Api(a => a.SendVideoAsync(DeviceId, file, caption: caption, parseMode: parseMode,
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
replyToMessageId: replyTo, replyMarkup: markup,
|
||||||
|
disableNotification: disableNotification));
|
||||||
|
|
||||||
|
var o = GetOrigin(new StackTrace());
|
||||||
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
|
||||||
return await t;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -484,21 +421,16 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var t = Api(a => a.SendVideoAsync(DeviceId, InputFile.FromUri(url), parseMode: parseMode,
|
|
||||||
replyToMessageId: replyTo, replyMarkup: markup,
|
|
||||||
disableNotification: disableNotification));
|
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var t = Api(a => a.SendVideoAsync(DeviceId, InputFile.FromUri(url), parseMode: parseMode,
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
replyToMessageId: replyTo, replyMarkup: markup,
|
||||||
|
disableNotification: disableNotification));
|
||||||
|
|
||||||
|
var o = GetOrigin(new StackTrace());
|
||||||
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
|
||||||
return await t;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -520,24 +452,19 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var ms = new MemoryStream(video);
|
|
||||||
|
|
||||||
var fts = InputFile.FromStream(ms, filename);
|
var ms = new MemoryStream(video);
|
||||||
|
|
||||||
var t = Api(a => a.SendVideoAsync(DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo,
|
var fts = InputFile.FromStream(ms, filename);
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var t = Api(a => a.SendVideoAsync(DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo,
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
|
var o = GetOrigin(new StackTrace());
|
||||||
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
|
||||||
return await t;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -560,26 +487,21 @@ public class DeviceSession : IDeviceSession
|
|||||||
|
|
||||||
InlineKeyboardMarkup markup = buttons;
|
InlineKeyboardMarkup markup = buttons;
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var fs = new FileStream(filepath, FileMode.Open);
|
|
||||||
|
|
||||||
var filename = Path.GetFileName(filepath);
|
var fs = new FileStream(filepath, FileMode.Open);
|
||||||
|
|
||||||
var fts = InputFile.FromStream(fs, filename);
|
var filename = Path.GetFileName(filepath);
|
||||||
|
|
||||||
var t = Api(a => a.SendVideoAsync(DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo,
|
var fts = InputFile.FromStream(fs, filename);
|
||||||
replyMarkup: markup, disableNotification: disableNotification));
|
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var t = Api(a => a.SendVideoAsync(DeviceId, fts, parseMode: parseMode, replyToMessageId: replyTo,
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
replyMarkup: markup, disableNotification: disableNotification));
|
||||||
|
|
||||||
|
var o = GetOrigin(new StackTrace());
|
||||||
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
|
||||||
return await t;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -650,20 +572,15 @@ public class DeviceSession : IDeviceSession
|
|||||||
markup = buttons;
|
markup = buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var t = Api(a => a.SendDocumentAsync(DeviceId, document, null, null, caption, replyMarkup: markup,
|
|
||||||
disableNotification: disableNotification, replyToMessageId: replyTo));
|
|
||||||
|
|
||||||
var o = GetOrigin(new StackTrace());
|
var t = Api(a => a.SendDocumentAsync(DeviceId, document, null, null, caption, replyMarkup: markup,
|
||||||
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
disableNotification: disableNotification, replyToMessageId: replyTo));
|
||||||
|
|
||||||
|
var o = GetOrigin(new StackTrace());
|
||||||
|
await OnMessageSent(new MessageSentEventArgs(await t, o));
|
||||||
|
|
||||||
|
return await t;
|
||||||
|
|
||||||
return await t;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -714,22 +631,16 @@ 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());
|
|
||||||
|
|
||||||
if (autoDeleteResponse && m != null)
|
var m = await Send(closedMsg, new ReplyKeyboardRemove());
|
||||||
{
|
|
||||||
await DeleteMessage(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
return m;
|
if (autoDeleteResponse && m != null)
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
{
|
||||||
|
await DeleteMessage(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return m;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user