Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public BotInlineHandlerWithDependency(ServiceScoped serviceScoped, ServiceTransi

public async Task<UpdateResult> Handle(PRBotBase bot, Update update, CallbackQuery updateType)
{
await PRTelegramBot.Helpers.Message.Send(bot.botClient, update, $"{nameof(Handle)} {_logger != null}");
await PRTelegramBot.Helpers.Message.Send(bot.BotClient, update, $"{nameof(Handle)} {_logger != null}");
return UpdateResult.Handled;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<IActionResult> Post([FromBody] Update update)
var secretToken = bot.Options.WebHookOptions.SecretToken;
if (string.Equals(secretTokenHeader, secretToken, StringComparison.Ordinal))
{
await bot.Handler.HandleUpdateAsync(bot.botClient, update, bot.Options.CancellationToken.Token);
await bot.Handler.HandleUpdateAsync(bot.BotClient, update, bot.Options.CancellationTokenSource.Token);
return Ok();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ private async Task StartBots()

if (bot.DataRetrieval == DataRetrievalMethod.WebHook)
{
var webHookResult = await((PRBotWebHook)bot).GetWebHookInfo();
var webHookResult = await((PRBotWebHook)bot)
.GetWebHookInfo(bot.Options.CancellationTokenSource.Token);
if (!string.IsNullOrEmpty(webHookResult.LastErrorMessage))
bot.Events.OnErrorLogInvoke(new Exception(webHookResult.LastErrorMessage));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace ConsoleExample.Checkers
{
internal class AdminExampleChecher : IInternalCheck
internal class AdminExampleChecker : IInternalCheck
{
public async Task<InternalCheckResult> Check(PRBotBase bot, Update update, CommandHandler handler)
{
Expand All @@ -19,7 +19,7 @@ public async Task<InternalCheckResult> Check(PRBotBase bot, Update update, Comma
{
var userIsAdmin = await bot.IsAdmin(update.GetChatId());
if(!userIsAdmin)
await PRTelegramBot.Helpers.Message.Send(bot.botClient, update.GetChatId(), "Вы не админ!");
await PRTelegramBot.Helpers.Message.Send(bot.BotClient, update.GetChatId(), "Вы не админ!");

return userIsAdmin ? InternalCheckResult.Passed : InternalCheckResult.Custom;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task<UpdateResult> Handle(PRBotBase bot, Update update, CallbackQue
var command = InlineCallback<StringTCommand>.GetCommandByCallbackOrNull(updateType.Data);
if (command != null)
{
await PRTelegramBot.Helpers.Message.Send(bot.botClient, update.GetChatId(), $"{TEST_ADD_MESSAGE} {command.Data.StrData}");
await PRTelegramBot.Helpers.Message.Send(bot.BotClient, update.GetChatId(), $"{TEST_ADD_MESSAGE} {command.Data.StrData}");
return UpdateResult.Handled;
}

Expand Down
2 changes: 1 addition & 1 deletion Examples/ConsoleExample/Services/Initializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static Dictionary<string, string> GetDynamicCommands()
public static List<InternalChecker> GetCommandChekers()
{
var checkerReplyCommand = new InternalChecker(CommandType.Reply, new ReplyExampleChecker());
var adminChecker = new InternalChecker(new List<CommandType>() { CommandType.Reply, CommandType.NextStep, CommandType.Inline, CommandType.ReplyDynamic, CommandType.Slash }, new AdminExampleChecher());
var adminChecker = new InternalChecker(new List<CommandType>() { CommandType.Reply, CommandType.NextStep, CommandType.Inline, CommandType.ReplyDynamic, CommandType.Slash }, new AdminExampleChecker());
return new List<InternalChecker>() { checkerReplyCommand, adminChecker };
}

Expand Down
12 changes: 6 additions & 6 deletions PRTelegramBot.Tests/EventsTests/EventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Task EventHandler(StartEventArgs e)
}

bot.Events.OnUserStartWithArgs += EventHandler;
await bot.Handler.HandleUpdateAsync(bot.botClient, update, new CancellationToken());
await bot.Handler.HandleUpdateAsync(bot.BotClient, update, new CancellationToken());
Assert.IsTrue(eventCalled, $"The {nameof(bot.Events.OnUserStartWithArgs)} event was not called.");
bot.Events.OnUserStartWithArgs -= EventHandler;
}
Expand All @@ -59,7 +59,7 @@ Task EventHandler(BotEventArgs e)
}

bot.Events.OnMissingCommand += EventHandler;
await bot.Handler.HandleUpdateAsync(bot.botClient, update, new CancellationToken());
await bot.Handler.HandleUpdateAsync(bot.BotClient, update, new CancellationToken());
Assert.IsTrue(eventCalled, $"The {nameof(bot.Events.OnMissingCommand)} event was not called.");
bot.Events.OnMissingCommand -= EventHandler;
}
Expand All @@ -77,7 +77,7 @@ Task EventHandler(PrivilegeEventArgs e)
}

bot.Events.OnCheckPrivilege += EventHandler;
await bot.Handler.HandleUpdateAsync(bot.botClient, update, new CancellationToken());
await bot.Handler.HandleUpdateAsync(bot.BotClient, update, new CancellationToken());
Assert.IsTrue(eventCalled, $"The {nameof(bot.Events.OnCheckPrivilege)} event was not called.");
bot.Events.OnCheckPrivilege -= EventHandler;
}
Expand All @@ -93,7 +93,7 @@ Task EventHandler(BotEventArgs e)
return Task.CompletedTask;
}
bot.Events.OnWrongTypeMessage += EventHandler;
await bot.Handler.HandleUpdateAsync(bot.botClient, update, new CancellationToken());
await bot.Handler.HandleUpdateAsync(bot.BotClient, update, new CancellationToken());
Assert.IsTrue(eventCalled, $"The {nameof(bot.Events.OnWrongTypeMessage)} event was not called.");
bot.Events.OnWrongTypeMessage -= EventHandler;
}
Expand All @@ -111,7 +111,7 @@ Task EventHandler(BotEventArgs e)
return Task.CompletedTask;
}
bot.Events.OnAccessDenied += EventHandler;
await bot.Handler.HandleUpdateAsync(bot.botClient, update, new CancellationToken());
await bot.Handler.HandleUpdateAsync(bot.BotClient, update, new CancellationToken());
Assert.IsTrue(eventCalled, $"The {nameof(bot.Events.OnAccessDenied)} event was not called.");
bot.Events.OnAccessDenied -= EventHandler;
await bot.Options.WhiteListManager.RemoveUser(testUserId);
Expand All @@ -130,7 +130,7 @@ Task EventHandler(BotEventArgs e)
return Task.CompletedTask;
}
bot.Events.OnAccessDenied += EventHandler;
await bot.Handler.HandleUpdateAsync(bot.botClient, update, new CancellationToken());
await bot.Handler.HandleUpdateAsync(bot.BotClient, update, new CancellationToken());
Assert.IsFalse(eventCalled, $"The {nameof(bot.Events.OnAccessDenied)} event was not called.");
bot.Events.OnAccessDenied -= EventHandler;
await bot.Options.WhiteListManager.RemoveUser(userId);
Expand Down
Loading
Loading