Merge pull request #22 from Bubuni-Team/feature/botapi-6.4

[core] add support of new bot api
This commit is contained in:
Andriy
2023-01-02 21:54:16 +02:00
committed by GitHub
23 changed files with 40 additions and 42 deletions
+1 -1
View File
@@ -8,7 +8,7 @@
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Core' " />
<ItemGroup>
<PackageReference Include="AleXr64.BotFramework" Version="0.6.9-gf1e77653ff" />
<PackageReference Include="AleXr64.BotFramework" Version="0.6.16-g4b4da305e4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
+1 -1
View File
@@ -47,6 +47,6 @@ public class Greet : BotEventHandler
}
await Bot.SendTextMessageAsync(Chat.Id, string.Format(reply.ToString(), membersHtml),
ParseMode.Html, replyToMessageId: message.MessageId);
parseMode: ParseMode.Html, replyToMessageId: message.MessageId);
}
}
+2 -2
View File
@@ -2,7 +2,7 @@
using BotFramework.Attributes;
using BotFramework.Enums;
using Telegram.Bot;
using Telegram.Bot.Types.InputFiles;
using Telegram.Bot.Types;
namespace West.TelegramBot.ChatQuotes.Handler;
@@ -31,7 +31,7 @@ public class Quote : BotEventHandler
return;
}
await Bot.SendStickerAsync(Chat.Id, new InputOnlineFile(quoteImage),
await Bot.SendStickerAsync(Chat.Id, new InputFile(quoteImage),
replyToMessageId: msg.MessageId);
}
}
@@ -19,7 +19,7 @@ public class NullToEmptyObjectValueProvider : IValueProvider
return result;
}
public void SetValue(object target, object value)
public void SetValue(object target, object? value)
{
_memberInfo.SetValue(target, value);
}
+1 -1
View File
@@ -81,7 +81,7 @@ public class Handler : BotEventHandler
var notifyMsg = await Bot.SendTextMessageAsync(Chat.Id,
(message.From?.ToHtml() ?? "") + ", не стоит публиковать столь большой код прямо в чат. " +
"Вместо этого загрузите его на https://pastebin.com и отправьте в виде ссылки.",
ParseMode.Html);
parseMode: ParseMode.Html);
// TODO: maybe write a wrapper-service around collection to avoid direct interactions with the collection, West, 07.07.2022, 16:53
_requests.Add(new DeleteRequest
+1 -1
View File
@@ -49,7 +49,7 @@ namespace Kruzya.TelegramBot.CombotAntiSpam
messageText.Append(
$"More details you can find on <a href=\"https://cas.chat/query?u={member.Id}\">CAS site</a>.");
await Bot.SendTextMessageAsync(Chat, messageText.ToString(), ParseMode.Html);
await Bot.SendTextMessageAsync(Chat, messageText.ToString(), parseMode: ParseMode.Html);
if (canKickMembers)
{
+2 -2
View File
@@ -43,7 +43,7 @@ public class Store : BotEventHandler
var user = From;
var reputation = await _reputation.GetUserReputationAsync(Chat, user);
await Bot.SendTextMessageAsync(Chat.Id, $"<b>{user.ToHtml()} ({reputation})</b>, чего пожелаете?", ParseMode.Html,
await Bot.SendTextMessageAsync(Chat.Id, $"<b>{user.ToHtml()} ({reputation})</b>, чего пожелаете?", parseMode: ParseMode.Html,
replyMarkup: new InlineKeyboardMarkup(
_provider.GetServices<IRandomMediaService>()
.ToAsyncEnumerable()
@@ -116,7 +116,7 @@ public class Store : BotEventHandler
switch (randomMedia.Type)
{
case InputMediaType.Photo:
await Bot.SendPhotoAsync(Chat.Id, file, randomMedia.Caption, replyToMessageId: messageId, parseMode: ParseMode.Html);
await Bot.SendPhotoAsync(Chat.Id, file, 0, randomMedia.Caption, replyToMessageId: messageId, parseMode: ParseMode.Html);
break;
case InputMediaType.Video:
await Bot.SendVideoAsync(Chat.Id, file, caption: randomMedia.Caption, replyToMessageId: messageId, parseMode: ParseMode.Html);
+4 -4
View File
@@ -1,17 +1,17 @@
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.InputFiles;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
namespace West.TelegramBot.ContentStore.Model;
public class RandomMedia
{
public RandomMedia(InputOnlineFile file, string? caption = null)
public RandomMedia(IInputFile file, string? caption = null)
{
File = file;
Caption = caption;
}
public InputOnlineFile File;
public IInputFile File;
public string? Caption;
public InputMediaType Type { get; set; } = InputMediaType.Photo;
@@ -5,7 +5,6 @@ using Kruzya.TelegramBot.Core.Data;
using Kruzya.TelegramBot.Core.Extensions;
using Microsoft.Extensions.Configuration;
using Telegram.Bot.Types;
using Telegram.Bot.Types.InputFiles;
using West.TelegramBot.ContentStore.Model;
namespace West.TelegramBot.ContentStore.Service;
@@ -45,7 +44,7 @@ public abstract class AbstractKittiesService : IRandomMediaService
var videoTitle = Encoding.UTF8.GetString(Convert.FromBase64String(videoTitleBase64));
return new RandomMedia(
new InputOnlineFile(await response.Content.ReadAsStreamAsync()),
new InputFile(await response.Content.ReadAsStreamAsync()),
new HtmlString().Url(videoSource, videoTitle).ToString()
);
}
@@ -24,7 +24,7 @@ public class AnimBoobsService : IRandomMediaService
public async Task<RandomMedia> GetRandomMediaAsync()
{
var fileName = await _httpClient.GetStringAsync("index.php");
return new RandomMedia($"https://westdev.me/_boobs/media/{fileName}")
return new RandomMedia(new InputFileUrl($"https://westdev.me/_boobs/media/{fileName}"))
{
Type = InputMediaType.Video
};
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Telegram.Bot.Types;
using West.TelegramBot.ContentStore.Model;
namespace West.TelegramBot.ContentStore.Service;
@@ -20,7 +21,7 @@ public abstract class AnimalAsAService : IRandomMediaService
public async Task<RandomMedia> GetRandomMediaAsync()
{
var resp = await _httpClient.GetAsync("images/search");
var catImage = JsonConvert.DeserializeObject<List<AnimalImage>>(await resp.Content.ReadAsStringAsync())[0];
return new RandomMedia(catImage.Url);
var catImage = JsonConvert.DeserializeObject<List<AnimalImage>>(await resp.Content.ReadAsStringAsync())![0];
return new RandomMedia(new InputFileUrl(catImage.Url));
}
}
@@ -1,4 +1,5 @@
using West.TelegramBot.ContentStore.Model;
using Telegram.Bot.Types;
using West.TelegramBot.ContentStore.Model;
namespace West.TelegramBot.ContentStore.Service;
@@ -7,6 +8,6 @@ public class CapyApiService : IRandomMediaService
public StoreItem StoreItem { get; } = new("capybara", "Капибара", 60, 25);
public async Task<RandomMedia> GetRandomMediaAsync()
{
return new RandomMedia($"https://api.capy.lol/v1/capybara?{new Random().Next(0, 10000)}");
return new RandomMedia(new InputFileUrl($"https://api.capy.lol/v1/capybara?{new Random().Next(0, 10000)}"));
}
}
@@ -26,10 +26,10 @@ public class OBoobsService : IRandomMediaService
// "/boobs/{start=0; sql offset}/{count=1; sql limit}/{order=-id;[id,rank,-rank,interest,-interest,random]}/
var httpResp = await _httpClient.GetAsync("boobs/1/1/random");
var boobsResponse = JsonConvert.DeserializeObject<List<OBoobsItem>>(await httpResp.Content.ReadAsStringAsync());
var boobsItem = boobsResponse[0];
var boobsItem = boobsResponse![0];
var boobsId = boobsItem.Id.ToString("D5");
return new RandomMedia($"https://media.oboobs.ru/boobs/{boobsId}.jpg", boobsItem.Model);
return new RandomMedia(new InputFileUrl($"https://media.oboobs.ru/boobs/{boobsId}.jpg"), boobsItem.Model);
}
public async Task<bool> CanView(Chat chat, User user)
@@ -1,8 +1,5 @@
using System.Net.Http.Headers;
using BotFramework.Utils;
using Kruzya.TelegramBot.Core.Data;
using Kruzya.TelegramBot.Core.Data;
using Microsoft.Extensions.Configuration;
using Telegram.Bot.Types.InputFiles;
using West.TelegramBot.ContentStore.Model;
namespace West.TelegramBot.ContentStore.Service;
@@ -31,7 +31,7 @@ namespace Kruzya.TelegramBot.Destiny2.WhereIsXur
protected async Task Response(string place)
{
await Bot.SendTextMessageAsync(Chat, $"<b>Xûr</b> place is <code>{place}</code>", ParseMode.Html);
await Bot.SendTextMessageAsync(Chat, $"<b>Xûr</b> place is <code>{place}</code>", parseMode: ParseMode.Html);
}
}
}
+1 -1
View File
@@ -57,7 +57,7 @@ namespace West.Entertainment.Handler
.Br();
}
await Bot.SendTextMessageAsync(Chat.Id, msg.ToString(), ParseMode.Html);
await Bot.SendTextMessageAsync(Chat.Id, msg.ToString(), parseMode: ParseMode.Html);
}
}
}
@@ -82,7 +82,7 @@ namespace West.Entertainment.Handler.Fun
return false;
}
await Bot.SendAnimationAsync(Chat.Id, animationFileId,
await Bot.SendAnimationAsync(Chat.Id, new InputFileId(animationFileId),
replyToMessageId: GetMessageIdToReply() ?? Message?.MessageId);
nextUseOption.SetValue(DateTime.Now + Cooldown);
+1 -1
View File
@@ -176,7 +176,7 @@ public class Reputation : CommonHandler
i++;
}
await Bot.SendTextMessageAsync(Chat!, msg.ToString(), ParseMode.Html,
await Bot.SendTextMessageAsync(Chat!, msg.ToString(), parseMode: ParseMode.Html,
disableNotification: true);
}
+5 -5
View File
@@ -72,7 +72,7 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Handler
var inlineButtons = new InlineKeyboardMarkup(buttons);
if (message == null)
{
await Bot.SendTextMessageAsync(new ChatId(chat.Id), text, ParseMode.Html, null, true, true, 0, replyMarkup: inlineButtons);
await Bot.SendTextMessageAsync(new ChatId(chat.Id), text, 0, ParseMode.Html, null, true, true, false, 0, replyMarkup: inlineButtons);
}
else
{
@@ -88,7 +88,7 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Handler
{
if (!(await GenerateMenu(query)))
{
await Bot.SendTextMessageAsync(Chat, $"No one feed match by search pattern (<code>{query}</code>).", ParseMode.Html, null, true);
await Bot.SendTextMessageAsync(Chat, $"No one feed match by search pattern (<code>{query}</code>).", 0, ParseMode.Html, null, true);
}
}
@@ -192,8 +192,8 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Handler
if (editableMessage == null)
{
await Bot.SendTextMessageAsync(Chat, "Select the feed for viewing details", null,
null, true, true, 0, replyMarkup: new InlineKeyboardMarkup(buttons));
await Bot.SendTextMessageAsync(Chat, "Select the feed for viewing details", 0, null,
null, true, true, false, 0, replyMarkup: new InlineKeyboardMarkup(buttons));
}
else
{
@@ -270,7 +270,7 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Handler
}
await Bot.SendTextMessageAsync(RawUpdate.CallbackQuery.Message.Chat, messageTextBuilder.ToString(),
ParseMode.Html, null, true);
0, ParseMode.Html, null, true);
break;
}
@@ -31,7 +31,7 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Handler
textMessage.Append(
$"- exists <b>{subscriptionsCount} subscriptions on feeds</b> (<b>unique subscribers: {uniqueSubscribers}</b>)");
await Bot.SendTextMessageAsync(Chat, textMessage.ToString(), ParseMode.Html);
await Bot.SendTextMessageAsync(Chat, textMessage.ToString(), parseMode: ParseMode.Html);
}
}
}
@@ -36,13 +36,13 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Service
{
if (string.IsNullOrWhiteSpace(message.ImageUrl))
{
await _bot.BotClient.SendTextMessageAsync(message.ChatId, message.Text, message.ParseMode, null,
await _bot.BotClient.SendTextMessageAsync(message.ChatId, message.Text, 0, message.ParseMode, null,
message.DisableWebPagePreview);
}
else
{
await _bot.BotClient.SendPhotoAsync(message.ChatId, message.ImageUrl, message.Text,
await _bot.BotClient.SendPhotoAsync(message.ChatId, new InputFileUrl(message.ImageUrl), 0, message.Text,
message.ParseMode, null, message.DisableWebPagePreview);
}
}
+1 -1
View File
@@ -52,7 +52,7 @@ namespace Kruzya.TelegramBot.UrlLimitations
Bot.BanChatMemberAsync(new ChatId(Chat.Id), From.Id, DateTime.Now.AddDays(1)),
Bot.DeleteMessageAsync(targetChat, message.MessageId),
Bot.SendTextMessageAsync(targetChat,
$"Member {From.ToHtml(true)} has been banned.\n<b>Reason</b>: <pre>Spam suspicion</pre>", ParseMode.Html)
$"Member {From.ToHtml(true)} has been banned.\n<b>Reason</b>: <pre>Spam suspicion</pre>", parseMode: ParseMode.Html)
});
}
}
+3 -3
View File
@@ -49,7 +49,7 @@ namespace UserGroupTag
if (memberList.Contains(fromId))
{
await Bot.SendTextMessageAsync(chatId, $"{from.ToHtml()} уже находится в группе {groupName}",
ParseMode.Html);
parseMode: ParseMode.Html);
return;
}
memberList.Add(repliedMessage.From.Id);
@@ -60,7 +60,7 @@ namespace UserGroupTag
_userCache.SetValue(repliedMessage.From.Id, repliedMessage.From, Int32.MaxValue);
await Bot.SendTextMessageAsync(chatId, $"{from.ToHtml()} добавлен в группу {groupName}",
ParseMode.Html);
parseMode: ParseMode.Html);
}
[ParametrizedCommand(InChat.Public, "tag_group", CommandParseMode.Both)]
@@ -88,7 +88,7 @@ namespace UserGroupTag
msg.UserMention(await GetUser(userId, Chat)).Text(", ");
}
await Bot.SendTextMessageAsync(Chat.Id, msg.ToString().TrimEnd(',', ' '), ParseMode.Html);
await Bot.SendTextMessageAsync(Chat.Id, msg.ToString().TrimEnd(',', ' '), parseMode: ParseMode.Html);
}
protected async Task<User> GetUser(long userId, Chat chat)