Use the new version of TelegramBotFramework

This commit is contained in:
2021-12-22 01:27:56 +04:00
parent 2c158330cc
commit 73ed1d88a9
7 changed files with 19 additions and 19 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="AleXr64.BotFramework" Version="0.0.17" /> <PackageReference Include="AleXr64.BotFramework" Version="0.3.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.2" />
+1 -1
View File
@@ -20,6 +20,6 @@ namespace Kruzya.TelegramBot.Core.Data
/// <summary> /// <summary>
/// The Telegram User identifier. /// The Telegram User identifier.
/// </summary> /// </summary>
public int UserId { get; set; } public long UserId { get; set; }
} }
} }
+4 -4
View File
@@ -51,7 +51,7 @@ namespace Kruzya.TelegramBot.Core.Extensions
#region BotUser #region BotUser
public static async Task<BotUser> FindOrCreate(this DbSet<BotUser> repository, long chatId, int userId) public static async Task<BotUser> FindOrCreate(this DbSet<BotUser> repository, long chatId, long userId)
{ {
var user = await repository.SingleOrDefaultAsync(e => e.ChatId == chatId && e.UserId == userId); var user = await repository.SingleOrDefaultAsync(e => e.ChatId == chatId && e.UserId == userId);
if (user == null) if (user == null)
@@ -76,7 +76,7 @@ namespace Kruzya.TelegramBot.Core.Extensions
public static async Task<BotUserValue> FindOption(this DbSet<BotUserValue> repository, BotUser user, public static async Task<BotUserValue> FindOption(this DbSet<BotUserValue> repository, BotUser user,
string option) => await repository.FindOption(user.ChatId, user.UserId, option); string option) => await repository.FindOption(user.ChatId, user.UserId, option);
public static async Task<BotUserValue> FindOption(this DbSet<BotUserValue> repository, long chatId, int userId, public static async Task<BotUserValue> FindOption(this DbSet<BotUserValue> repository, long chatId, long userId,
string option) => await repository.SingleOrDefaultAsync(e => string option) => await repository.SingleOrDefaultAsync(e =>
e.BotUser.ChatId == chatId && e.BotUser.UserId == userId && e.Name == option); e.BotUser.ChatId == chatId && e.BotUser.UserId == userId && e.Name == option);
@@ -91,7 +91,7 @@ namespace Kruzya.TelegramBot.Core.Extensions
string option) => await repository.FindOrCreateOption(user.ChatId, user.UserId, option); string option) => await repository.FindOrCreateOption(user.ChatId, user.UserId, option);
public static async Task<BotUserValue> FindOrCreateOption(this DbSet<BotUserValue> repository, long chatId, public static async Task<BotUserValue> FindOrCreateOption(this DbSet<BotUserValue> repository, long chatId,
int userId, string option) long userId, string option)
{ {
var opt = await repository.FindOption(chatId, userId, option); var opt = await repository.FindOption(chatId, userId, option);
if (opt == null) if (opt == null)
@@ -113,7 +113,7 @@ namespace Kruzya.TelegramBot.Core.Extensions
public static async Task SetOptionValue<T>(this DbSet<BotUserValue> repository, BotUser user, string option, public static async Task SetOptionValue<T>(this DbSet<BotUserValue> repository, BotUser user, string option,
T val) => await repository.SetOptionValue(user.ChatId, user.UserId, option, val); T val) => await repository.SetOptionValue(user.ChatId, user.UserId, option, val);
public static async Task SetOptionValue<T>(this DbSet<BotUserValue> repository, long chatId, int userId, public static async Task SetOptionValue<T>(this DbSet<BotUserValue> repository, long chatId, long userId,
string option, T val) string option, T val)
{ {
var opt = await repository.FindOrCreateOption(chatId, userId, option); var opt = await repository.FindOrCreateOption(chatId, userId, option);
+2 -2
View File
@@ -53,7 +53,7 @@ namespace Kruzya.TelegramBot.Core
await VerifyChatPair(chat.Id, user.Id); await VerifyChatPair(chat.Id, user.Id);
} }
public async Task VerifyChatPair(long chat, int user) public async Task VerifyChatPair(long chat, long user)
{ {
var hasEntry = await databaseContext.Users.AnyAsync(e => e.ChatId == chat && e.UserId == user); var hasEntry = await databaseContext.Users.AnyAsync(e => e.ChatId == chat && e.UserId == user);
if (hasEntry) if (hasEntry)
@@ -64,7 +64,7 @@ namespace Kruzya.TelegramBot.Core
await MakeChatPair(chat, user); await MakeChatPair(chat, user);
} }
public async Task MakeChatPair(long chat, int user) public async Task MakeChatPair(long chat, long user)
{ {
await databaseContext.Users.AddAsync(new BotUser() await databaseContext.Users.AddAsync(new BotUser()
{ {
+6 -6
View File
@@ -72,11 +72,11 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Handler
var inlineButtons = new InlineKeyboardMarkup(buttons); var inlineButtons = new InlineKeyboardMarkup(buttons);
if (message == null) if (message == null)
{ {
await Bot.SendTextMessageAsync(new ChatId(chat.Id), text, ParseMode.Html, true, true, 0, inlineButtons); await Bot.SendTextMessageAsync(new ChatId(chat.Id), text, ParseMode.Html, null, true, true, 0, replyMarkup: inlineButtons);
} }
else else
{ {
await Bot.EditMessageTextAsync(chat, message.MessageId, text, ParseMode.Html, true, inlineButtons); await Bot.EditMessageTextAsync(chat, message.MessageId, text, ParseMode.Html, null, true, replyMarkup: inlineButtons);
} }
} }
@@ -88,7 +88,7 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Handler
{ {
if (!(await GenerateMenu(query))) if (!(await GenerateMenu(query)))
{ {
await Bot.SendTextMessageAsync(Chat, $"No one feed match by search pattern (<code>{query}</code>).", ParseMode.Html, true); await Bot.SendTextMessageAsync(Chat, $"No one feed match by search pattern (<code>{query}</code>).", ParseMode.Html, null, true);
} }
} }
@@ -195,11 +195,11 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Handler
if (editableMessage == null) if (editableMessage == null)
{ {
await Bot.SendTextMessageAsync(Chat, "Select the feed for viewing details", ParseMode.Default, await Bot.SendTextMessageAsync(Chat, "Select the feed for viewing details", ParseMode.Default,
true, true, 0, new InlineKeyboardMarkup(buttons)); null, true, true, 0, replyMarkup: new InlineKeyboardMarkup(buttons));
} }
else else
{ {
await Bot.EditMessageTextAsync(editableMessage.Chat, editableMessage.MessageId, "Select the feed for viewing details", ParseMode.Default, false, await Bot.EditMessageTextAsync(editableMessage.Chat, editableMessage.MessageId, "Select the feed for viewing details", ParseMode.Default, null, false,
new InlineKeyboardMarkup(buttons)); new InlineKeyboardMarkup(buttons));
} }
@@ -272,7 +272,7 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Handler
} }
await Bot.SendTextMessageAsync(RawUpdate.CallbackQuery.Message.Chat, messageTextBuilder.ToString(), await Bot.SendTextMessageAsync(RawUpdate.CallbackQuery.Message.Chat, messageTextBuilder.ToString(),
ParseMode.Html, true); ParseMode.Html, null, true);
break; break;
} }
@@ -40,11 +40,11 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Service
try try
{ {
if (string.IsNullOrWhiteSpace(message.ImageUrl)) if (string.IsNullOrWhiteSpace(message.ImageUrl))
await _bot.BotClient.SendTextMessageAsync(message.ChatId, message.Text, message.ParseMode, await _bot.BotClient.SendTextMessageAsync(message.ChatId, message.Text, message.ParseMode, null,
message.DisableWebPagePreview); message.DisableWebPagePreview);
else else
await _bot.BotClient.SendPhotoAsync(message.ChatId, message.ImageUrl, message.Text, await _bot.BotClient.SendPhotoAsync(message.ChatId, message.ImageUrl, message.Text,
message.ParseMode, message.DisableWebPagePreview); message.ParseMode, null, message.DisableWebPagePreview);
} }
catch (ApiRequestException e) catch (ApiRequestException e)
{ {
+3 -3
View File
@@ -15,7 +15,7 @@ namespace Kruzya.TelegramBot.UrlLimitations
foreach (var mention in message.Entities.Where(e => foreach (var mention in message.Entities.Where(e =>
e.Type == MessageEntityType.Mention || e.Type == MessageEntityType.TextMention)) e.Type == MessageEntityType.Mention || e.Type == MessageEntityType.TextMention))
{ {
var userId = 0; long userId = 0;
if (mention.Type == MessageEntityType.TextMention) if (mention.Type == MessageEntityType.TextMention)
{ {
userId = mention.User.Id; userId = mention.User.Id;
@@ -34,10 +34,10 @@ namespace Kruzya.TelegramBot.UrlLimitations
return true; return true;
} }
userId = Convert.ToInt32(chat.Id); userId = Convert.ToInt64(chat.Id);
} }
} }
catch (Exception e) catch (Exception)
{ {
return true; return true;
} }