mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Merge pull request #37 from Bubuni-Team/feature/dep-updates-0225
Dependency updates
This commit is contained in:
@@ -8,4 +8,5 @@ obj/
|
|||||||
|
|
||||||
appsettings.json
|
appsettings.json
|
||||||
*.csproj.user
|
*.csproj.user
|
||||||
|
*.DotSettings.user
|
||||||
appsettings.Development.json
|
appsettings.Development.json
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class DeleteService : AbstractTimedHostedService
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _bot.BotClient.DeleteMessageAsync(request.ChatId, request.MessageId);
|
await _bot.BotClient.DeleteMessage(request.ChatId, request.MessageId);
|
||||||
}
|
}
|
||||||
catch (ApiRequestException e)
|
catch (ApiRequestException e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ using BotFramework.Config;
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
@@ -16,14 +16,12 @@ namespace Kruzya.TelegramBot.Core.Controllers
|
|||||||
private const string SecretTokenHeader = "X-Telegram-Bot-Api-Secret-Token";
|
private const string SecretTokenHeader = "X-Telegram-Bot-Api-Secret-Token";
|
||||||
|
|
||||||
private readonly ILogger<Telegram> _logger;
|
private readonly ILogger<Telegram> _logger;
|
||||||
private readonly ITelegramBotClient _client;
|
|
||||||
private readonly IUpdateTarget _updateTarget;
|
private readonly IUpdateTarget _updateTarget;
|
||||||
private readonly string _secretToken;
|
private readonly string _secretToken;
|
||||||
|
|
||||||
public Telegram(ILogger<Telegram> logger, ITelegramBotClient client, IUpdateTarget updateTarget, IOptions<BotConfig> config)
|
public Telegram(ILogger<Telegram> logger, IUpdateTarget updateTarget, IOptions<BotConfig> config)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_client = client;
|
|
||||||
_updateTarget = updateTarget;
|
_updateTarget = updateTarget;
|
||||||
|
|
||||||
_secretToken = config.Value.Webhook.SecretToken;
|
_secretToken = config.Value.Webhook.SecretToken;
|
||||||
@@ -50,7 +48,7 @@ namespace Kruzya.TelegramBot.Core.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
var body = await (new StreamReader(Request.Body)).ReadToEndAsync();
|
var body = await (new StreamReader(Request.Body)).ReadToEndAsync();
|
||||||
LaunchHandle(JsonConvert.DeserializeObject<Update>(body));
|
LaunchHandle(JsonSerializer.Deserialize<Update>(body, JsonBotAPI.Options));
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -4,11 +4,12 @@
|
|||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<AssemblyName>TelegramBot</AssemblyName>
|
<AssemblyName>TelegramBot</AssemblyName>
|
||||||
<RootNamespace>Kruzya.TelegramBot.Core</RootNamespace>
|
<RootNamespace>Kruzya.TelegramBot.Core</RootNamespace>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Core' " />
|
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Core' " />
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="AleXr64.BotFramework" Version="2.0.8-gf720999661" />
|
<PackageReference Include="AleXr64.BotFramework" Version="2.0.12-gae66e70f1a" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.7">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.7">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
@@ -17,6 +18,6 @@
|
|||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.7" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.7" />
|
||||||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
|
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
|
||||||
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
|
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public static class BotExtension
|
|||||||
|
|
||||||
if (victim != null && canUse)
|
if (victim != null && canUse)
|
||||||
{
|
{
|
||||||
var victimMember = await bot.GetChatMemberAsync(chat, victim.Id);
|
var victimMember = await bot.GetChatMember(chat, victim.Id);
|
||||||
canUse = victimMember is not ChatMemberOwner && victimMember is not ChatMemberAdministrator && !victim.IsBot;
|
canUse = victimMember is not ChatMemberOwner && victimMember is not ChatMemberAdministrator && !victim.IsBot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,7 +21,7 @@ public static class BotExtension
|
|||||||
|
|
||||||
public static async Task<bool> IsUserAdminAsync(this ITelegramBotClient bot, Chat chat, User user)
|
public static async Task<bool> IsUserAdminAsync(this ITelegramBotClient bot, Chat chat, User user)
|
||||||
{
|
{
|
||||||
var callerMember = await bot.GetChatMemberAsync(chat, user.Id);
|
var callerMember = await bot.GetChatMember(chat, user.Id);
|
||||||
var isAdmin = callerMember is ChatMemberOwner;
|
var isAdmin = callerMember is ChatMemberOwner;
|
||||||
|
|
||||||
if (callerMember is ChatMemberAdministrator callerAdmin)
|
if (callerMember is ChatMemberAdministrator callerAdmin)
|
||||||
@@ -34,12 +34,12 @@ public static class BotExtension
|
|||||||
|
|
||||||
public static async Task<bool> CanDeleteMessagesAsync(this ITelegramBotClient bot, Chat chat)
|
public static async Task<bool> CanDeleteMessagesAsync(this ITelegramBotClient bot, Chat chat)
|
||||||
{
|
{
|
||||||
return await CanDeleteMessagesAsync(bot, chat, await bot.GetMeAsync());
|
return await CanDeleteMessagesAsync(bot, chat, await bot.GetMe());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<bool> CanDeleteMessagesAsync(this ITelegramBotClient bot, Chat chat, User user)
|
public static async Task<bool> CanDeleteMessagesAsync(this ITelegramBotClient bot, Chat chat, User user)
|
||||||
{
|
{
|
||||||
return await bot.GetChatMemberAsync(chat.Id, user.Id) is ChatMemberOwner
|
return await bot.GetChatMember(chat.Id, user.Id) is ChatMemberOwner
|
||||||
or ChatMemberAdministrator {CanRestrictMembers: true};
|
or ChatMemberAdministrator {CanRestrictMembers: true};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,21 +1,21 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Extensions;
|
namespace Kruzya.TelegramBot.Core.Extensions;
|
||||||
|
|
||||||
public static class HttpClientExtension
|
public static class HttpClientExtension
|
||||||
{
|
{
|
||||||
public static async Task<T> GetJsonAsync<T>(this HttpClient client, Uri requestUri)
|
public static async Task<T?> GetJsonAsync<T>(this HttpClient client, Uri requestUri)
|
||||||
{
|
{
|
||||||
var response = await client.GetStringAsync(requestUri);
|
var response = await client.GetStringAsync(requestUri);
|
||||||
return JsonConvert.DeserializeObject<T>(response);
|
return JsonSerializer.Deserialize<T>(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<T> GetJsonAsync<T>(this HttpClient client, string requestUri)
|
public static async Task<T?> GetJsonAsync<T>(this HttpClient client, string requestUri)
|
||||||
{
|
{
|
||||||
var response = await client.GetStringAsync(requestUri);
|
var response = await client.GetStringAsync(requestUri);
|
||||||
return JsonConvert.DeserializeObject<T>(response);
|
return JsonSerializer.Deserialize<T>(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,8 +26,8 @@ public abstract class CommonHandler : BotEventHandler
|
|||||||
|
|
||||||
protected virtual async Task<Message> Reply(string text)
|
protected virtual async Task<Message> Reply(string text)
|
||||||
{
|
{
|
||||||
return await Bot.SendTextMessageAsync(Chat.Id, text,
|
return await Bot.SendMessage(Chat.Id, text,
|
||||||
replyToMessageId: Message?.MessageId, parseMode: ParseMode.Html);
|
replyParameters: Message?.MessageId, parseMode: ParseMode.Html);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async Task<bool> CanPunish()
|
protected async Task<bool> CanPunish()
|
||||||
@@ -38,14 +38,14 @@ public abstract class CommonHandler : BotEventHandler
|
|||||||
|
|
||||||
protected async Task BanMember(long userId, DateTime banEnd)
|
protected async Task BanMember(long userId, DateTime banEnd)
|
||||||
{
|
{
|
||||||
await Bot.RestrictChatMemberAsync(
|
await Bot.RestrictChatMember(
|
||||||
Chat.Id,
|
Chat.Id,
|
||||||
userId,
|
userId,
|
||||||
new ChatPermissions
|
new ChatPermissions
|
||||||
{
|
{
|
||||||
CanSendMessages = false
|
CanSendMessages = false
|
||||||
},
|
},
|
||||||
banEnd
|
untilDate: banEnd
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,6 +56,6 @@ public abstract class CommonHandler : BotEventHandler
|
|||||||
|
|
||||||
protected async Task AnswerQuery(string id, string? message = null)
|
protected async Task AnswerQuery(string id, string? message = null)
|
||||||
{
|
{
|
||||||
await Bot.AnswerCallbackQueryAsync(id, message);
|
await Bot.AnswerCallbackQuery(id, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ public class SettingsHandler : CommonHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Bot.SendTextMessageAsync(
|
await Bot.SendMessage(
|
||||||
Chat.Id,
|
Chat.Id,
|
||||||
"What do you want to change?",
|
"What do you want to change?",
|
||||||
replyMarkup: GetSettingsMarkup()
|
replyMarkup: GetSettingsMarkup()
|
||||||
@@ -66,7 +66,7 @@ public class SettingsHandler : CommonHandler
|
|||||||
if (paramList[2] == "main_menu")
|
if (paramList[2] == "main_menu")
|
||||||
{
|
{
|
||||||
await AnswerQuery(query.Id);
|
await AnswerQuery(query.Id);
|
||||||
await Bot.EditMessageTextAsync(Chat.Id, query.Message!.MessageId, "What do you want to change?",
|
await Bot.EditMessageText(Chat.Id, query.Message!.MessageId, "What do you want to change?",
|
||||||
replyMarkup: GetSettingsMarkup());
|
replyMarkup: GetSettingsMarkup());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -103,14 +103,14 @@ public class SettingsHandler : CommonHandler
|
|||||||
await onOffOpt.SetValueAsync(chatId, !await onOffOpt.GetValueAsync(chatId));
|
await onOffOpt.SetValueAsync(chatId, !await onOffOpt.GetValueAsync(chatId));
|
||||||
await AnswerQuery(query.Id);
|
await AnswerQuery(query.Id);
|
||||||
|
|
||||||
await Bot.EditMessageReplyMarkupAsync(chatId, messageId, GetSettingsMarkup());
|
await Bot.EditMessageReplyMarkup(chatId, messageId, GetSettingsMarkup());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OptionType.Select:
|
case OptionType.Select:
|
||||||
var selectOpt = (IOption<string>) option;
|
var selectOpt = (IOption<string>) option;
|
||||||
await AnswerQuery(query.Id);
|
await AnswerQuery(query.Id);
|
||||||
|
|
||||||
await Bot.EditMessageTextAsync(Chat.Id, messageId, "Here's what you can choose:",
|
await Bot.EditMessageText(Chat.Id, messageId, "Here's what you can choose:",
|
||||||
replyMarkup: await GetChoiceSelectKeyboard(selectOpt));
|
replyMarkup: await GetChoiceSelectKeyboard(selectOpt));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ public class SettingsHandler : CommonHandler
|
|||||||
await selectOption.SetValueAsync(Chat.Id, choice.Id);
|
await selectOption.SetValueAsync(Chat.Id, choice.Id);
|
||||||
await AnswerQuery(query.Id);
|
await AnswerQuery(query.Id);
|
||||||
|
|
||||||
await Bot.EditMessageReplyMarkupAsync(Chat.Id, query.Message!.MessageId, await GetChoiceSelectKeyboard(selectOption));
|
await Bot.EditMessageReplyMarkup(Chat.Id, query.Message!.MessageId, await GetChoiceSelectKeyboard(selectOption));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<InlineKeyboardButton> GetKeyboardButton(IOption option)
|
private async Task<InlineKeyboardButton> GetKeyboardButton(IOption option)
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class UserService
|
|||||||
|
|
||||||
private async Task<User> GetUserByChat(long chatId, long userId)
|
private async Task<User> GetUserByChat(long chatId, long userId)
|
||||||
{
|
{
|
||||||
return (await _bot.GetChatMemberAsync(chatId, userId)).User;
|
return (await _bot.GetChatMember(chatId, userId)).User;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsUserSuper(User user)
|
public bool IsUserSuper(User user)
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ namespace Kruzya.TelegramBot.Core
|
|||||||
|
|
||||||
public async Task StartAsync(CancellationToken token)
|
public async Task StartAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
await _client.SetWebhookAsync(_config.Webhook.Url, secretToken: _secretToken, cancellationToken: token);
|
await _client.SetWebhook(_config.Webhook.Url, secretToken: _secretToken, cancellationToken: token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task StopAsync(CancellationToken token)
|
public async Task StopAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
await _client.DeleteWebhookAsync(cancellationToken: token);
|
await _client.DeleteWebhook(cancellationToken: token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,11 @@ COPY Kruzya.TelegramBot.sln ./
|
|||||||
COPY ./Core/*.csproj ./Core/
|
COPY ./Core/*.csproj ./Core/
|
||||||
COPY ./tests/*.csproj ./tests/
|
COPY ./tests/*.csproj ./tests/
|
||||||
COPY ./modules/CombotAntiSpam/*.csproj ./modules/CombotAntiSpam/
|
COPY ./modules/CombotAntiSpam/*.csproj ./modules/CombotAntiSpam/
|
||||||
COPY ./modules/Destiny2.WhereIsXur/*.csproj ./modules/Destiny2.WhereIsXur/
|
|
||||||
COPY ./modules/RichSiteSummary/*.csproj ./modules/RichSiteSummary/
|
COPY ./modules/RichSiteSummary/*.csproj ./modules/RichSiteSummary/
|
||||||
COPY ./modules/UrlLimitations/*.csproj ./modules/UrlLimitations/
|
COPY ./modules/UrlLimitations/*.csproj ./modules/UrlLimitations/
|
||||||
COPY ./modules/ChatManagement/*.csproj ./modules/ChatManagement/
|
COPY ./modules/ChatManagement/*.csproj ./modules/ChatManagement/
|
||||||
COPY ./modules/Entertainment/*.csproj ./modules/Entertainment/
|
COPY ./modules/Entertainment/*.csproj ./modules/Entertainment/
|
||||||
COPY ./modules/UserGroupTag/*.csproj ./modules/UserGroupTag/
|
COPY ./modules/UserGroupTag/*.csproj ./modules/UserGroupTag/
|
||||||
COPY ./modules/ChatQuotes/*.csproj ./modules/ChatQuotes/
|
|
||||||
COPY ./modules/Reputation/*.csproj ./modules/Reputation/
|
COPY ./modules/Reputation/*.csproj ./modules/Reputation/
|
||||||
COPY ./modules/ContentStore/*.csproj ./modules/ContentStore/
|
COPY ./modules/ContentStore/*.csproj ./modules/ContentStore/
|
||||||
COPY ./modules/DebugTools/*.csproj ./modules/DebugTools/
|
COPY ./modules/DebugTools/*.csproj ./modules/DebugTools/
|
||||||
|
|||||||
@@ -15,16 +15,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "tests\Tests.csproj
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UrlLimitations", "modules\UrlLimitations\UrlLimitations.csproj", "{B82E3339-3B34-4600-8C59-C5A3640B1982}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UrlLimitations", "modules\UrlLimitations\UrlLimitations.csproj", "{B82E3339-3B34-4600-8C59-C5A3640B1982}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Destiny2.WhereIsXur", "modules\Destiny2.WhereIsXur\Destiny2.WhereIsXur.csproj", "{AE782132-BED8-4D1E-98FA-CB768171D332}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatManagement", "modules\ChatManagement\ChatManagement.csproj", "{55ACF7F7-409A-45EE-A41D-D8417DE7EAA7}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatManagement", "modules\ChatManagement\ChatManagement.csproj", "{55ACF7F7-409A-45EE-A41D-D8417DE7EAA7}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UserGroupTag", "modules\UserGroupTag\UserGroupTag.csproj", "{5B89E22A-78CF-4037-BE0D-5F88EF47022B}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UserGroupTag", "modules\UserGroupTag\UserGroupTag.csproj", "{5B89E22A-78CF-4037-BE0D-5F88EF47022B}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entertainment", "modules\Entertainment\Entertainment.csproj", "{1D62101B-C2B1-4E79-8F7A-690E44E3EE81}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entertainment", "modules\Entertainment\Entertainment.csproj", "{1D62101B-C2B1-4E79-8F7A-690E44E3EE81}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ChatQuotes", "modules\ChatQuotes\ChatQuotes.csproj", "{04F16325-8F44-4250-9B2E-0F77E8F65CBF}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Reputation", "modules\Reputation\Reputation.csproj", "{03F3C7D5-6FEF-4A83-9191-501091BFC1AC}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Reputation", "modules\Reputation\Reputation.csproj", "{03F3C7D5-6FEF-4A83-9191-501091BFC1AC}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContentStore", "modules\ContentStore\ContentStore.csproj", "{4F1E8FE8-640F-4671-87FC-0FFCCB6EDF5E}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ContentStore", "modules\ContentStore\ContentStore.csproj", "{4F1E8FE8-640F-4671-87FC-0FFCCB6EDF5E}"
|
||||||
@@ -61,10 +57,6 @@ Global
|
|||||||
{B82E3339-3B34-4600-8C59-C5A3640B1982}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{B82E3339-3B34-4600-8C59-C5A3640B1982}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{B82E3339-3B34-4600-8C59-C5A3640B1982}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{B82E3339-3B34-4600-8C59-C5A3640B1982}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{B82E3339-3B34-4600-8C59-C5A3640B1982}.Release|Any CPU.Build.0 = Release|Any CPU
|
{B82E3339-3B34-4600-8C59-C5A3640B1982}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{AE782132-BED8-4D1E-98FA-CB768171D332}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{AE782132-BED8-4D1E-98FA-CB768171D332}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{AE782132-BED8-4D1E-98FA-CB768171D332}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{AE782132-BED8-4D1E-98FA-CB768171D332}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{55ACF7F7-409A-45EE-A41D-D8417DE7EAA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{55ACF7F7-409A-45EE-A41D-D8417DE7EAA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{55ACF7F7-409A-45EE-A41D-D8417DE7EAA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{55ACF7F7-409A-45EE-A41D-D8417DE7EAA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{55ACF7F7-409A-45EE-A41D-D8417DE7EAA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{55ACF7F7-409A-45EE-A41D-D8417DE7EAA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
@@ -77,10 +69,6 @@ Global
|
|||||||
{1D62101B-C2B1-4E79-8F7A-690E44E3EE81}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{1D62101B-C2B1-4E79-8F7A-690E44E3EE81}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{1D62101B-C2B1-4E79-8F7A-690E44E3EE81}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{1D62101B-C2B1-4E79-8F7A-690E44E3EE81}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{1D62101B-C2B1-4E79-8F7A-690E44E3EE81}.Release|Any CPU.Build.0 = Release|Any CPU
|
{1D62101B-C2B1-4E79-8F7A-690E44E3EE81}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{04F16325-8F44-4250-9B2E-0F77E8F65CBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{04F16325-8F44-4250-9B2E-0F77E8F65CBF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{04F16325-8F44-4250-9B2E-0F77E8F65CBF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{04F16325-8F44-4250-9B2E-0F77E8F65CBF}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{03F3C7D5-6FEF-4A83-9191-501091BFC1AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{03F3C7D5-6FEF-4A83-9191-501091BFC1AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{03F3C7D5-6FEF-4A83-9191-501091BFC1AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{03F3C7D5-6FEF-4A83-9191-501091BFC1AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{03F3C7D5-6FEF-4A83-9191-501091BFC1AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{03F3C7D5-6FEF-4A83-9191-501091BFC1AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
@@ -109,11 +97,9 @@ Global
|
|||||||
{F1E1FBB7-ABA4-4304-9A42-D4975822B002} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
{F1E1FBB7-ABA4-4304-9A42-D4975822B002} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
||||||
{C50D64C3-204B-4B58-927B-C8D759787252} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
{C50D64C3-204B-4B58-927B-C8D759787252} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
||||||
{B82E3339-3B34-4600-8C59-C5A3640B1982} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
{B82E3339-3B34-4600-8C59-C5A3640B1982} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
||||||
{AE782132-BED8-4D1E-98FA-CB768171D332} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
|
||||||
{55ACF7F7-409A-45EE-A41D-D8417DE7EAA7} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
{55ACF7F7-409A-45EE-A41D-D8417DE7EAA7} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
||||||
{5B89E22A-78CF-4037-BE0D-5F88EF47022B} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
{5B89E22A-78CF-4037-BE0D-5F88EF47022B} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
||||||
{1D62101B-C2B1-4E79-8F7A-690E44E3EE81} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
{1D62101B-C2B1-4E79-8F7A-690E44E3EE81} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
||||||
{04F16325-8F44-4250-9B2E-0F77E8F65CBF} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
|
||||||
{03F3C7D5-6FEF-4A83-9191-501091BFC1AC} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
{03F3C7D5-6FEF-4A83-9191-501091BFC1AC} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
||||||
{4F1E8FE8-640F-4671-87FC-0FFCCB6EDF5E} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
{4F1E8FE8-640F-4671-87FC-0FFCCB6EDF5E} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
||||||
{B95C9180-4893-4A33-BF43-AB2EE998650C} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
{B95C9180-4893-4A33-BF43-AB2EE998650C} = {C7821F15-DEDD-474F-A575-A296D4B58F10}
|
||||||
|
|||||||
@@ -42,11 +42,11 @@ public class Ban : CommonHandler
|
|||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
await Bot.SendTextMessageAsync(Chat.Id, "Нет прав на блокировку пользователя.");
|
await Bot.SendMessage(Chat.Id, "Нет прав на блокировку пользователя.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Bot.SendTextMessageAsync(
|
await Bot.SendMessage(
|
||||||
Chat.Id,
|
Chat.Id,
|
||||||
$"{From.ToHtml()} <code>заблокировал</code> {RepliedUser!.ToHtml()} <code>{banEndMsg}</code>",
|
$"{From.ToHtml()} <code>заблокировал</code> {RepliedUser!.ToHtml()} <code>{banEndMsg}</code>",
|
||||||
disableNotification: true, parseMode: ParseMode.Html);
|
disableNotification: true, parseMode: ParseMode.Html);
|
||||||
@@ -59,18 +59,25 @@ public class Ban : CommonHandler
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Bot.RestrictChatMemberAsync(Chat.Id, RepliedUser!.Id,
|
// TODO: in Telegram.Bot >=22.4.0 this could be replaced with new ChatPermissions(true)
|
||||||
|
await Bot.RestrictChatMember(Chat.Id, RepliedUser!.Id,
|
||||||
new ChatPermissions
|
new ChatPermissions
|
||||||
{
|
{
|
||||||
CanSendMessages = true,
|
CanSendMessages = true,
|
||||||
|
CanAddWebPagePreviews = true,
|
||||||
CanChangeInfo = true,
|
CanChangeInfo = true,
|
||||||
CanInviteUsers = true,
|
CanInviteUsers = true,
|
||||||
|
CanManageTopics = true,
|
||||||
CanPinMessages = true,
|
CanPinMessages = true,
|
||||||
CanSendPolls = true,
|
CanSendAudios = true,
|
||||||
CanSendMediaMessages = true,
|
CanSendDocuments = true,
|
||||||
CanSendOtherMessages = true,
|
CanSendOtherMessages = true,
|
||||||
CanAddWebPagePreviews = true
|
CanSendPhotos = true,
|
||||||
|
CanSendPolls = true,
|
||||||
|
CanSendVideos = true,
|
||||||
|
CanSendVideoNotes = true,
|
||||||
|
CanSendVoiceNotes = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
await Reply($"{From.ToHtml()} <code>разблокировал</code> {RepliedUser!.ToHtml()}");
|
await Reply($"{From.ToHtml()} <code>разблокировал</code> {RepliedUser!.ToHtml()}");
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public partial class BanStickerSet
|
|||||||
var replyToMsgId = Message?.ReplyToMessage?.MessageId;
|
var replyToMsgId = Message?.ReplyToMessage?.MessageId;
|
||||||
if (replyToMsgId != null)
|
if (replyToMsgId != null)
|
||||||
{
|
{
|
||||||
await Bot.DeleteMessageAsync(Chat.Id, (int) replyToMsgId);
|
await Bot.DeleteMessage(Chat.Id, (int) replyToMsgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
await Reply(FormatStickerSetAction(stickerSet.Set, "заблокирован"));
|
await Reply(FormatStickerSetAction(stickerSet.Set, "заблокирован"));
|
||||||
@@ -90,7 +90,7 @@ public partial class BanStickerSet
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var stickerSet = await Bot.GetStickerSetAsync(list[i]);
|
var stickerSet = await Bot.GetStickerSet(list[i]);
|
||||||
htmlString.Text($"{i + 1}. ")
|
htmlString.Text($"{i + 1}. ")
|
||||||
.Url("https://t.me/addstickers/" + stickerSet.Name, stickerSet.Title)
|
.Url("https://t.me/addstickers/" + stickerSet.Name, stickerSet.Title)
|
||||||
.Br();
|
.Br();
|
||||||
@@ -125,7 +125,7 @@ public partial class BanStickerSet
|
|||||||
"Этот набор стикеров заблокирован. Чтобы я мог его удалить, выдайте мне право на удаление сообщений.");
|
"Этот набор стикеров заблокирован. Чтобы я мог его удалить, выдайте мне право на удаление сообщений.");
|
||||||
}
|
}
|
||||||
|
|
||||||
await Bot.DeleteMessageAsync(Chat.Id, message.MessageId);
|
await Bot.DeleteMessage(Chat.Id, message.MessageId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,9 +14,9 @@ public partial class BanStickerSet
|
|||||||
{
|
{
|
||||||
private async Task<bool> CanBotDeleteMessages()
|
private async Task<bool> CanBotDeleteMessages()
|
||||||
{
|
{
|
||||||
return await Bot.GetChatMemberAsync(
|
return await Bot.GetChatMember(
|
||||||
Chat.Id,
|
Chat.Id,
|
||||||
(await Bot.GetMeAsync()).Id
|
(await Bot.GetMe()).Id
|
||||||
) is ChatMemberAdministrator {CanDeleteMessages: true};
|
) is ChatMemberAdministrator {CanDeleteMessages: true};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ public partial class BanStickerSet
|
|||||||
|
|
||||||
private async Task<bool> CanUseCommands()
|
private async Task<bool> CanUseCommands()
|
||||||
{
|
{
|
||||||
return await Bot.GetChatMemberAsync(Chat.Id, From.Id) is ChatMemberAdministrator {CanDeleteMessages: true}
|
return await Bot.GetChatMember(Chat.Id, From.Id) is ChatMemberAdministrator {CanDeleteMessages: true}
|
||||||
or ChatMemberOwner;
|
or ChatMemberOwner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -46,7 +46,7 @@ public class Greet : BotEventHandler
|
|||||||
reply.Text("Пожалуйста, ознакомьтесь с правилами. /rules");
|
reply.Text("Пожалуйста, ознакомьтесь с правилами. /rules");
|
||||||
}
|
}
|
||||||
|
|
||||||
await Bot.SendTextMessageAsync(Chat.Id, string.Format(reply.ToString(), membersHtml),
|
await Bot.SendMessage(Chat.Id, string.Format(reply.ToString(), membersHtml),
|
||||||
parseMode: ParseMode.Html, replyToMessageId: message.MessageId);
|
parseMode: ParseMode.Html, replyParameters: message.MessageId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,7 +39,7 @@ class Rules : CommonHandler
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Bot.CopyMessageAsync(Chat.Id, Chat.Id, await _rulesService.GetRulesMessageIdAsync(Chat) ?? 0);
|
await Bot.CopyMessage(Chat.Id, Chat.Id, await _rulesService.GetRulesMessageIdAsync(Chat) ?? 0);
|
||||||
}
|
}
|
||||||
catch (ApiRequestException)
|
catch (ApiRequestException)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class WhoIs : CommonHandler
|
|||||||
return customStatus;
|
return customStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
var chatMember = await Bot.GetChatMemberAsync(Chat.Id, user.Id);
|
var chatMember = await Bot.GetChatMember(Chat.Id, user.Id);
|
||||||
return chatMember.Status switch
|
return chatMember.Status switch
|
||||||
{
|
{
|
||||||
ChatMemberStatus.Creator => "Владелец",
|
ChatMemberStatus.Creator => "Владелец",
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ public class Notifier
|
|||||||
{
|
{
|
||||||
public static async void WarnNotify(ITelegramBotClient bot, Chat chat, User from, User to, int count, bool isBanned = false)
|
public static async void WarnNotify(ITelegramBotClient bot, Chat chat, User from, User to, int count, bool isBanned = false)
|
||||||
{
|
{
|
||||||
await bot.SendTextMessageAsync(chat.Id, $"{to.ToHtml()}<code>, Вам выдано предупреждение! " +
|
await bot.SendMessage(chat.Id, $"{to.ToHtml()}<code>, Вам выдано предупреждение! " +
|
||||||
$"Текущее кол-во: {count}/3</code>",
|
$"Текущее кол-во: {count}/3</code>",
|
||||||
disableNotification: true,
|
disableNotification: true,
|
||||||
parseMode: ParseMode.Html);
|
parseMode: ParseMode.Html);
|
||||||
|
|
||||||
if (isBanned)
|
if (isBanned)
|
||||||
{
|
{
|
||||||
await bot.SendTextMessageAsync(
|
await bot.SendMessage(
|
||||||
chat.Id,
|
chat.Id,
|
||||||
$"{from.ToHtml()} <code>заблокировал</code> {to.ToHtml()} <code>на 7 дней</code>",
|
$"{from.ToHtml()} <code>заблокировал</code> {to.ToHtml()} <code>на 7 дней</code>",
|
||||||
disableNotification: true, parseMode: ParseMode.Html);
|
disableNotification: true, parseMode: ParseMode.Html);
|
||||||
@@ -25,7 +25,7 @@ public class Notifier
|
|||||||
|
|
||||||
public static async void UnWarnNotify(ITelegramBotClient bot, Chat chat, User from, User to, int count)
|
public static async void UnWarnNotify(ITelegramBotClient bot, Chat chat, User from, User to, int count)
|
||||||
{
|
{
|
||||||
await bot.SendTextMessageAsync(chat.Id,
|
await bot.SendMessage(chat.Id,
|
||||||
$"{to.ToHtml()}<code>, с Вас снято предупреждение! " +
|
$"{to.ToHtml()}<code>, с Вас снято предупреждение! " +
|
||||||
$"Текущее кол-во: {count}/3</code>",
|
$"Текущее кол-во: {count}/3</code>",
|
||||||
disableNotification: true,
|
disableNotification: true,
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class StickerSet
|
|||||||
var sticker = message?.ReplyToMessage?.Sticker;
|
var sticker = message?.ReplyToMessage?.Sticker;
|
||||||
if (sticker is { SetName: { } })
|
if (sticker is { SetName: { } })
|
||||||
{
|
{
|
||||||
result.Set = bot.GetStickerSetAsync(sticker.SetName).GetAwaiter().GetResult();
|
result.Set = bot.GetStickerSet(sticker.SetName).GetAwaiter().GetResult();
|
||||||
result.IsValid = true;
|
result.IsValid = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ public class StickerSet
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
result.Set = bot.GetStickerSetAsync(setName.First())
|
result.Set = bot.GetStickerSet(setName.First())
|
||||||
.GetAwaiter()
|
.GetAwaiter()
|
||||||
.GetResult();
|
.GetResult();
|
||||||
result.IsValid = true;
|
result.IsValid = true;
|
||||||
|
|||||||
@@ -36,20 +36,20 @@ public class WarnService
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await _bot.RestrictChatMemberAsync(
|
await _bot.RestrictChatMember(
|
||||||
chat.Id,
|
chat.Id,
|
||||||
to.Id,
|
to.Id,
|
||||||
new ChatPermissions
|
new ChatPermissions
|
||||||
{
|
{
|
||||||
CanSendMessages = false
|
CanSendMessages = false
|
||||||
},
|
},
|
||||||
DateTime.Now.AddDays(7)
|
untilDate: DateTime.Now.AddDays(7)
|
||||||
);
|
);
|
||||||
warnCount = 0;
|
warnCount = 0;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
await _bot.SendTextMessageAsync(chat.Id, "У меня нет прав на блокировку пользователя.");
|
await _bot.SendMessage(chat.Id, "У меня нет прав на блокировку пользователя.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,31 +0,0 @@
|
|||||||
using System.Globalization;
|
|
||||||
using Kruzya.TelegramBot.Core;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Converters;
|
|
||||||
using Newtonsoft.Json.Serialization;
|
|
||||||
using West.TelegramBot.ChatQuotes.Json;
|
|
||||||
|
|
||||||
namespace West.TelegramBot.ChatQuotes;
|
|
||||||
|
|
||||||
public class ChatQuotes : Module
|
|
||||||
{
|
|
||||||
public static readonly JsonSerializerSettings SerializerSettings = new()
|
|
||||||
{
|
|
||||||
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
|
|
||||||
DateParseHandling = DateParseHandling.None,
|
|
||||||
Converters =
|
|
||||||
{
|
|
||||||
new IsoDateTimeConverter { DateTimeStyles = DateTimeStyles.AssumeUniversal },
|
|
||||||
new StringEnumConverter(new CamelCaseNamingStrategy())
|
|
||||||
},
|
|
||||||
ContractResolver = new NullToEmptyObjectResolver()
|
|
||||||
};
|
|
||||||
|
|
||||||
public ChatQuotes(Core core) : base(core) { }
|
|
||||||
|
|
||||||
public override void ConfigureServices(IServiceCollection services)
|
|
||||||
{
|
|
||||||
services.AddSingleton<QuoteGeneratorService>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
<RootNamespace>West.TelegramBot.ChatQuotes</RootNamespace>
|
|
||||||
<AssemblyName>TelegramBot.ChatQuotes</AssemblyName>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Handler\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\Core\Core.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
|
||||||
<Delete Files="$(OutDir)\TelegramBot.dll" />
|
|
||||||
</Target>
|
|
||||||
</Project>
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
using BotFramework;
|
|
||||||
using BotFramework.Attributes;
|
|
||||||
using BotFramework.Enums;
|
|
||||||
using Telegram.Bot;
|
|
||||||
using Telegram.Bot.Types;
|
|
||||||
|
|
||||||
namespace West.TelegramBot.ChatQuotes.Handler;
|
|
||||||
|
|
||||||
public class Quote : BotEventHandler
|
|
||||||
{
|
|
||||||
private readonly QuoteGeneratorService _quoteGenerator;
|
|
||||||
|
|
||||||
public Quote(QuoteGeneratorService quoteGenerator)
|
|
||||||
{
|
|
||||||
_quoteGenerator = quoteGenerator;
|
|
||||||
}
|
|
||||||
|
|
||||||
[InChat(InChat.Public)]
|
|
||||||
[Command("q", CommandParseMode.Both)]
|
|
||||||
public async Task HandleQuote()
|
|
||||||
{
|
|
||||||
var msg = RawUpdate.Message;
|
|
||||||
var replyToMessage = msg?.ReplyToMessage;
|
|
||||||
if (msg == null || replyToMessage == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var quoteImage = await _quoteGenerator.GenerateQuoteImage(replyToMessage);
|
|
||||||
if (quoteImage == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await Bot.SendStickerAsync(Chat.Id, new InputFile(quoteImage),
|
|
||||||
replyToMessageId: msg.MessageId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Serialization;
|
|
||||||
|
|
||||||
namespace West.TelegramBot.ChatQuotes.Json;
|
|
||||||
|
|
||||||
class NullToEmptyObjectResolver : DefaultContractResolver
|
|
||||||
{
|
|
||||||
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
|
|
||||||
{
|
|
||||||
return type.GetProperties()
|
|
||||||
.Select(p => {
|
|
||||||
var jp = base.CreateProperty(p, memberSerialization);
|
|
||||||
jp.ValueProvider = new NullToEmptyObjectValueProvider(p);
|
|
||||||
return jp;
|
|
||||||
}).ToList();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
using System.Reflection;
|
|
||||||
using Newtonsoft.Json.Serialization;
|
|
||||||
using Telegram.Bot.Types;
|
|
||||||
|
|
||||||
namespace West.TelegramBot.ChatQuotes.Json;
|
|
||||||
|
|
||||||
public class NullToEmptyObjectValueProvider : IValueProvider
|
|
||||||
{
|
|
||||||
private readonly PropertyInfo _memberInfo;
|
|
||||||
public NullToEmptyObjectValueProvider(PropertyInfo memberInfo)
|
|
||||||
{
|
|
||||||
_memberInfo = memberInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public object? GetValue(object target)
|
|
||||||
{
|
|
||||||
var result = _memberInfo.GetValue(target);
|
|
||||||
if (_memberInfo.PropertyType == typeof(Message) && result == null) result = new object();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetValue(object target, object? value)
|
|
||||||
{
|
|
||||||
_memberInfo.SetValue(target, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace West.TelegramBot.ChatQuotes.Model.Quote;
|
|
||||||
|
|
||||||
public enum MediaType
|
|
||||||
{
|
|
||||||
Sticker = 0
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Serialization;
|
|
||||||
using File = Telegram.Bot.Types.File;
|
|
||||||
using TgUser = Telegram.Bot.Types.User;
|
|
||||||
|
|
||||||
namespace West.TelegramBot.ChatQuotes.Model.Quote;
|
|
||||||
|
|
||||||
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
|
|
||||||
public class Message
|
|
||||||
{
|
|
||||||
public List<File>? Media { get; set; }
|
|
||||||
public MediaType? MediaType { get; set; }
|
|
||||||
public long ChatId { get; set; }
|
|
||||||
public bool Avatar { get; set; } = true;
|
|
||||||
public User? From { get; set; }
|
|
||||||
public string? Text { get; set; }
|
|
||||||
public Telegram.Bot.Types.Message? ReplyMessage { get; set; }
|
|
||||||
|
|
||||||
public static Message FromMessage(Telegram.Bot.Types.Message msg)
|
|
||||||
{
|
|
||||||
var quoteMessage = new Message();
|
|
||||||
|
|
||||||
if (msg.Text != null)
|
|
||||||
{
|
|
||||||
quoteMessage.Text = msg.Text;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sticker = msg.Sticker;
|
|
||||||
if (sticker != null)
|
|
||||||
{
|
|
||||||
var file = new File
|
|
||||||
{
|
|
||||||
FileId = sticker.FileId,
|
|
||||||
FileSize = sticker.FileSize,
|
|
||||||
FileUniqueId = sticker.FileUniqueId
|
|
||||||
};
|
|
||||||
quoteMessage.Media = new List<File> { file };
|
|
||||||
quoteMessage.MediaType = Quote.MediaType.Sticker;
|
|
||||||
}
|
|
||||||
|
|
||||||
TgUser? user = null;
|
|
||||||
if (msg.ForwardSenderName != null && msg.ForwardFrom == null)
|
|
||||||
{
|
|
||||||
user = new TgUser
|
|
||||||
{
|
|
||||||
FirstName = msg.ForwardSenderName
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
quoteMessage.ChatId = msg.From?.Id ?? msg.Chat.Id;
|
|
||||||
quoteMessage.ReplyMessage = msg.ReplyToMessage;
|
|
||||||
quoteMessage.From = User.FromTgUser(user ?? msg.ForwardFrom ?? msg.From!);
|
|
||||||
|
|
||||||
return quoteMessage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
#nullable enable
|
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Serialization;
|
|
||||||
|
|
||||||
namespace West.TelegramBot.ChatQuotes.Model.Quote;
|
|
||||||
|
|
||||||
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
|
|
||||||
public class Request
|
|
||||||
{
|
|
||||||
public Request(Telegram.Bot.Types.Message msg)
|
|
||||||
{
|
|
||||||
// TODO: move default values to config
|
|
||||||
Format = "webp";
|
|
||||||
BackgroundColor = "#1b1429";
|
|
||||||
Width = 512;
|
|
||||||
Height = 768;
|
|
||||||
Scale = 2;
|
|
||||||
|
|
||||||
Messages = new List<Message> {Message.FromMessage(msg)};
|
|
||||||
}
|
|
||||||
|
|
||||||
public Type Type { get; set; }
|
|
||||||
public string Format { get; set; }
|
|
||||||
public string BackgroundColor { get; set; }
|
|
||||||
public int Width { get; set; }
|
|
||||||
public int Height { get; set; }
|
|
||||||
public int Scale { get; set; }
|
|
||||||
public List<Message>? Messages { get; set; }
|
|
||||||
|
|
||||||
public string ToJson()
|
|
||||||
{
|
|
||||||
return JsonConvert.SerializeObject(this, ChatQuotes.SerializerSettings);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#nullable disable
|
|
||||||
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Serialization;
|
|
||||||
|
|
||||||
namespace West.TelegramBot.ChatQuotes.Model.Quote;
|
|
||||||
|
|
||||||
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
|
|
||||||
public class Response
|
|
||||||
{
|
|
||||||
public bool Ok { get; set; }
|
|
||||||
|
|
||||||
public Result Result { get; set; }
|
|
||||||
public static Response FromJson(string json)
|
|
||||||
=> JsonConvert.DeserializeObject<Response>(json, ChatQuotes.SerializerSettings);
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
using Newtonsoft.Json.Serialization;
|
|
||||||
|
|
||||||
namespace West.TelegramBot.ChatQuotes.Model.Quote;
|
|
||||||
|
|
||||||
[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
|
|
||||||
public class Result
|
|
||||||
{
|
|
||||||
public string Image { get; set; } = "";
|
|
||||||
public Type Type { get; set; }
|
|
||||||
public long Width { get; set; }
|
|
||||||
public long Height { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
namespace West.TelegramBot.ChatQuotes.Model.Quote;
|
|
||||||
|
|
||||||
public enum Type
|
|
||||||
{
|
|
||||||
Quote = 0,
|
|
||||||
Image,
|
|
||||||
Null
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
using Newtonsoft.Json;
|
|
||||||
|
|
||||||
namespace West.TelegramBot.ChatQuotes.Model;
|
|
||||||
|
|
||||||
public class User : Telegram.Bot.Types.User
|
|
||||||
{
|
|
||||||
[JsonProperty]
|
|
||||||
public string Name => LastName != null ? $"{FirstName} {LastName}" : FirstName;
|
|
||||||
|
|
||||||
public static User FromTgUser(Telegram.Bot.Types.User user)
|
|
||||||
{
|
|
||||||
return new User
|
|
||||||
{
|
|
||||||
Id = user.Id,
|
|
||||||
FirstName = user.FirstName,
|
|
||||||
LastName = user.LastName,
|
|
||||||
Username = user.Username,
|
|
||||||
LanguageCode = user.LanguageCode,
|
|
||||||
IsBot = user.IsBot
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Text;
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using West.TelegramBot.ChatQuotes.Model.Quote;
|
|
||||||
using Message = Telegram.Bot.Types.Message;
|
|
||||||
|
|
||||||
namespace West.TelegramBot.ChatQuotes;
|
|
||||||
|
|
||||||
public class QuoteGeneratorService
|
|
||||||
{
|
|
||||||
private readonly HttpClient _httpClient;
|
|
||||||
private readonly MediaTypeHeaderValue _mediaType;
|
|
||||||
|
|
||||||
public QuoteGeneratorService(IConfiguration configuration)
|
|
||||||
{
|
|
||||||
_httpClient = new HttpClient
|
|
||||||
{
|
|
||||||
BaseAddress = new Uri(configuration.GetValue<string>("QuoteApiUrl"))
|
|
||||||
};
|
|
||||||
|
|
||||||
_mediaType = MediaTypeHeaderValue.Parse("application/json");
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<Stream?> GenerateQuoteImage(Message msg)
|
|
||||||
{
|
|
||||||
var request = new Request(msg);
|
|
||||||
var content = new ByteArrayContent(Encoding.UTF8.GetBytes(request.ToJson().ToCharArray()))
|
|
||||||
{
|
|
||||||
Headers =
|
|
||||||
{
|
|
||||||
ContentType = _mediaType
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
var resp = await _httpClient.PostAsync("/generate", content);
|
|
||||||
var quoteResponse = JsonConvert.DeserializeObject<Response>(await resp.Content.ReadAsStringAsync());
|
|
||||||
|
|
||||||
return quoteResponse.Ok ? new MemoryStream(Convert.FromBase64String(quoteResponse.Result.Image)) : null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -103,9 +103,9 @@ public class Handler : BotEventHandler
|
|||||||
public async Task UploadDetectedCode(Message message)
|
public async Task UploadDetectedCode(Message message)
|
||||||
{
|
{
|
||||||
var resp = await _haste.PostDocumentAsync(message.Text!);
|
var resp = await _haste.PostDocumentAsync(message.Text!);
|
||||||
await Bot.DeleteMessageAsync(Chat.Id, message.MessageId);
|
await Bot.DeleteMessage(Chat.Id, message.MessageId);
|
||||||
|
|
||||||
await Bot.SendTextMessageAsync(Chat.Id,
|
await Bot.SendMessage(Chat.Id,
|
||||||
$"{message.From?.ToHtml()}, you posted something long and pre-escaped, so I decided to upload it to our paste service for you.\n" +
|
$"{message.From?.ToHtml()}, you posted something long and pre-escaped, so I decided to upload it to our paste service for you.\n" +
|
||||||
$"Here is the link: {_haste.GetHasteUri() + resp.Key}",
|
$"Here is the link: {_haste.GetHasteUri() + resp.Key}",
|
||||||
parseMode: ParseMode.Html);
|
parseMode: ParseMode.Html);
|
||||||
@@ -113,8 +113,8 @@ public class Handler : BotEventHandler
|
|||||||
|
|
||||||
public async Task RemoveDetectedCode(Message message)
|
public async Task RemoveDetectedCode(Message message)
|
||||||
{
|
{
|
||||||
await Bot.DeleteMessageAsync(Chat.Id, message.MessageId);
|
await Bot.DeleteMessage(Chat.Id, message.MessageId);
|
||||||
var notifyMsg = await Bot.SendTextMessageAsync(Chat.Id,
|
var notifyMsg = await Bot.SendMessage(Chat.Id,
|
||||||
(message.From?.ToHtml() ?? "") + ", не стоит публиковать столь большой код прямо в чат. " +
|
(message.From?.ToHtml() ?? "") + ", не стоит публиковать столь большой код прямо в чат. " +
|
||||||
"Вместо этого загрузите его на https://pastebin.com и отправьте в виде ссылки.",
|
"Вместо этого загрузите его на https://pastebin.com и отправьте в виде ссылки.",
|
||||||
parseMode: ParseMode.Html);
|
parseMode: ParseMode.Html);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.CombotAntiSpam.Combot;
|
namespace Kruzya.TelegramBot.CombotAntiSpam.Combot;
|
||||||
|
|
||||||
@@ -7,24 +7,24 @@ internal class CombotApiResponse
|
|||||||
{
|
{
|
||||||
public class ApiResult
|
public class ApiResult
|
||||||
{
|
{
|
||||||
[JsonProperty("messages")]
|
[JsonPropertyName("messages")]
|
||||||
public string[] Messages { get; set; }
|
public string[] Messages { get; set; }
|
||||||
|
|
||||||
[JsonProperty("time_added")]
|
[JsonPropertyName("time_added")]
|
||||||
public int TimeAdded { get; set; }
|
public int TimeAdded { get; set; }
|
||||||
|
|
||||||
[JsonProperty("offenses")]
|
[JsonPropertyName("offenses")]
|
||||||
public int Offenses { get; set; }
|
public int Offenses { get; set; }
|
||||||
|
|
||||||
public DateTime AddedAt => DateTimeOffset.FromUnixTimeSeconds(TimeAdded).DateTime;
|
public DateTime AddedAt => DateTimeOffset.FromUnixTimeSeconds(TimeAdded).DateTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty("ok")]
|
[JsonPropertyName("ok")]
|
||||||
public bool IsSpammer { get; set; }
|
public bool IsSpammer { get; set; }
|
||||||
|
|
||||||
[JsonProperty("description")]
|
[JsonPropertyName("description")]
|
||||||
public string Description { get; set; }
|
public string Description { get; set; }
|
||||||
|
|
||||||
[JsonProperty("result")]
|
[JsonPropertyName("result")]
|
||||||
public ApiResult Result { get; set; }
|
public ApiResult Result { get; set; }
|
||||||
}
|
}
|
||||||
@@ -22,6 +22,6 @@ public class CombotClient : ICombotClient
|
|||||||
public async Task<bool> IsSpammerAsync(User user)
|
public async Task<bool> IsSpammerAsync(User user)
|
||||||
{
|
{
|
||||||
var result = await _httpClient.GetJsonAsync<CombotApiResponse>($"?user_id={user.Id}");
|
var result = await _httpClient.GetJsonAsync<CombotApiResponse>($"?user_id={user.Id}");
|
||||||
return result.IsSpammer;
|
return result?.IsSpammer ?? false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<AssemblyName>TelegramBot.CombotAntiSpam</AssemblyName>
|
<AssemblyName>TelegramBot.CombotAntiSpam</AssemblyName>
|
||||||
<RootNamespace>Kruzya.TelegramBot.CombotAntiSpam</RootNamespace>
|
<RootNamespace>Kruzya.TelegramBot.CombotAntiSpam</RootNamespace>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class UserJoinHandler : BotEventHandler
|
|||||||
[Message(MessageFlag.HasNewChatMembers)]
|
[Message(MessageFlag.HasNewChatMembers)]
|
||||||
public async Task OnUserJoined()
|
public async Task OnUserJoined()
|
||||||
{
|
{
|
||||||
var canKickMembers = await Bot.IsUserAdminAsync(Chat, await Bot.GetMeAsync());
|
var canKickMembers = await Bot.IsUserAdminAsync(Chat, await Bot.GetMe());
|
||||||
|
|
||||||
foreach (var member in RawUpdate.Message!.NewChatMembers!)
|
foreach (var member in RawUpdate.Message!.NewChatMembers!)
|
||||||
{
|
{
|
||||||
@@ -38,11 +38,11 @@ public class UserJoinHandler : BotEventHandler
|
|||||||
messageText.Append(
|
messageText.Append(
|
||||||
$"More details you can find on <a href=\"https://cas.chat/query?u={member.Id}\">CAS site</a>.");
|
$"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: ParseMode.Html);
|
await Bot.SendMessage(Chat, messageText.ToString(), parseMode: ParseMode.Html);
|
||||||
|
|
||||||
if (canKickMembers)
|
if (canKickMembers)
|
||||||
{
|
{
|
||||||
await Bot.BanChatMemberAsync(Chat, member.Id);
|
await Bot.BanChatMember(Chat, member.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using Kruzya.TelegramBot.Core.Handler;
|
|||||||
using Kruzya.TelegramBot.Core.Service;
|
using Kruzya.TelegramBot.Core.Service;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegram.Bot.Types.ReplyMarkups;
|
using Telegram.Bot.Types.ReplyMarkups;
|
||||||
using West.TelegramBot.ContentStore.Service;
|
using West.TelegramBot.ContentStore.Service;
|
||||||
@@ -38,14 +39,14 @@ public class Store : CommonHandler
|
|||||||
|
|
||||||
if (_reputation == null)
|
if (_reputation == null)
|
||||||
{
|
{
|
||||||
await Bot.SendTextMessageAsync(Chat.Id, "Reputation is unavailable.");
|
await Bot.SendMessage(Chat.Id, "Reputation is unavailable.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var user = From;
|
var user = From;
|
||||||
var reputation = await _reputation.GetUserReputationAsync(Chat, user);
|
var reputation = await _reputation.GetUserReputationAsync(Chat, user);
|
||||||
|
|
||||||
await Bot.SendTextMessageAsync(Chat.Id, $"<b>{user.ToHtml()} ({reputation})</b>, чего пожелаете?", parseMode: ParseMode.Html,
|
await Bot.SendMessage(Chat.Id, $"<b>{user.ToHtml()} ({reputation})</b>, чего пожелаете?", parseMode: ParseMode.Html,
|
||||||
replyMarkup: new InlineKeyboardMarkup(
|
replyMarkup: new InlineKeyboardMarkup(
|
||||||
_provider.GetServices<IRandomMediaService>()
|
_provider.GetServices<IRandomMediaService>()
|
||||||
.ToAsyncEnumerable()
|
.ToAsyncEnumerable()
|
||||||
@@ -99,7 +100,7 @@ public class Store : CommonHandler
|
|||||||
var reputation = await _reputation.GetUserReputationAsync(Chat, From);
|
var reputation = await _reputation.GetUserReputationAsync(Chat, From);
|
||||||
if (reputation < storeItem.Price)
|
if (reputation < storeItem.Price)
|
||||||
{
|
{
|
||||||
await Bot.EditMessageTextAsync(
|
await Bot.EditMessageText(
|
||||||
Chat.Id,
|
Chat.Id,
|
||||||
messageId,
|
messageId,
|
||||||
$"<b>{From.ToHtml()} ({reputation})</b>, продолжай работать и тебе обязательно хватит на покупку.",
|
$"<b>{From.ToHtml()} ({reputation})</b>, продолжай работать и тебе обязательно хватит на покупку.",
|
||||||
@@ -112,19 +113,19 @@ public class Store : CommonHandler
|
|||||||
{
|
{
|
||||||
await PerformPurchase(mediaService, messageId);
|
await PerformPurchase(mediaService, messageId);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch
|
||||||
{
|
{
|
||||||
answer = "Товар недоступен";
|
answer = "Товар недоступен";
|
||||||
await Bot.EditMessageTextAsync(Chat.Id,
|
await Bot.EditMessageText(Chat.Id,
|
||||||
messageId,
|
messageId,
|
||||||
$"<b>{From.ToHtml()} попытался купить \"{storeItem.Name}\", но товара в наличии не оказалось.",
|
$"<b>{From.ToHtml()}</b> попытался купить \"{storeItem.Name}\", но товара в наличии не оказалось.",
|
||||||
ParseMode.Html);
|
ParseMode.Html);
|
||||||
await AnswerQuery(query.Id, answer);
|
await AnswerQuery(query.Id, answer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
reputation = await _reputation.SetUserReputationAsync(Chat, From, reputation - storeItem.Price);
|
reputation = await _reputation.SetUserReputationAsync(Chat, From, reputation - storeItem.Price);
|
||||||
await Bot.EditMessageTextAsync(Chat.Id,
|
await Bot.EditMessageText(Chat.Id,
|
||||||
messageId,
|
messageId,
|
||||||
$"<b>{From.ToHtml()} ({reputation})</b> купил \"{storeItem.Name}\".",
|
$"<b>{From.ToHtml()} ({reputation})</b> купил \"{storeItem.Name}\".",
|
||||||
ParseMode.Html);
|
ParseMode.Html);
|
||||||
@@ -141,17 +142,17 @@ public class Store : CommonHandler
|
|||||||
switch (randomMedia.Type)
|
switch (randomMedia.Type)
|
||||||
{
|
{
|
||||||
case InputMediaType.Photo:
|
case InputMediaType.Photo:
|
||||||
await Bot.SendPhotoAsync(Chat.Id, file,
|
await Bot.SendPhoto(Chat.Id, file,
|
||||||
caption: randomMedia.Caption,
|
caption: randomMedia.Caption,
|
||||||
replyToMessageId: messageId,
|
replyParameters: messageId,
|
||||||
parseMode: ParseMode.Html,
|
parseMode: ParseMode.Html,
|
||||||
hasSpoiler: randomMedia.Nsfw
|
hasSpoiler: randomMedia.Nsfw
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case InputMediaType.Video:
|
case InputMediaType.Video:
|
||||||
await Bot.SendVideoAsync(Chat.Id, file,
|
await Bot.SendVideo(Chat.Id, file,
|
||||||
caption: randomMedia.Caption,
|
caption: randomMedia.Caption,
|
||||||
replyToMessageId: messageId,
|
replyParameters: messageId,
|
||||||
parseMode: ParseMode.Html,
|
parseMode: ParseMode.Html,
|
||||||
hasSpoiler: randomMedia.Nsfw
|
hasSpoiler: randomMedia.Nsfw
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
namespace West.TelegramBot.ContentStore.Model;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
public class AnimalImage
|
namespace West.TelegramBot.ContentStore.Model;
|
||||||
|
|
||||||
|
public record AnimalImage
|
||||||
{
|
{
|
||||||
public string Id { get; set; } = null!;
|
[JsonPropertyName("id")]
|
||||||
public string Url { get; set; } = null!;
|
public required string Id { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("url")]
|
||||||
|
public required string Url { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,21 @@
|
|||||||
namespace West.TelegramBot.ContentStore.Model;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
public class OBoobsItem
|
namespace West.TelegramBot.ContentStore.Model;
|
||||||
|
|
||||||
|
public record OBoobsItem
|
||||||
{
|
{
|
||||||
|
[JsonPropertyName("id")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("rank")]
|
||||||
public int Rank { get; set; }
|
public int Rank { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("author")]
|
||||||
public string? Author { get; set; }
|
public string? Author { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("model")]
|
||||||
public string? Model { get; set; }
|
public string? Model { get; set; }
|
||||||
|
|
||||||
|
[JsonPropertyName("rank")]
|
||||||
public string Preview { get; set; } = string.Empty;
|
public string Preview { get; set; } = string.Empty;
|
||||||
}
|
}
|
||||||
@@ -5,14 +5,14 @@ namespace West.TelegramBot.ContentStore.Model;
|
|||||||
|
|
||||||
public class RandomMedia
|
public class RandomMedia
|
||||||
{
|
{
|
||||||
public RandomMedia(IInputFile file, string? caption = null, bool nsfw = false)
|
public RandomMedia(InputFile file, string? caption = null, bool nsfw = false)
|
||||||
{
|
{
|
||||||
File = file;
|
File = file;
|
||||||
Caption = caption;
|
Caption = caption;
|
||||||
Nsfw = nsfw;
|
Nsfw = nsfw;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IInputFile File;
|
public InputFile File;
|
||||||
public string? Caption;
|
public string? Caption;
|
||||||
public bool Nsfw;
|
public bool Nsfw;
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class AnimBoobsService : AbstractNsfwService
|
|||||||
// https://bugs.telegram.org/c/23674 workaround
|
// https://bugs.telegram.org/c/23674 workaround
|
||||||
var video = await _httpClient.GetStreamAsync($"https://westdev.me/_boobs/media/{fileName}");
|
var video = await _httpClient.GetStreamAsync($"https://westdev.me/_boobs/media/{fileName}");
|
||||||
|
|
||||||
return new RandomMedia(new InputFile(video, fileName))
|
return new RandomMedia(new InputFileStream(video, fileName))
|
||||||
{
|
{
|
||||||
Type = InputMediaType.Video,
|
Type = InputMediaType.Video,
|
||||||
Nsfw = true
|
Nsfw = true
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using West.TelegramBot.ContentStore.Model;
|
using West.TelegramBot.ContentStore.Model;
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ public abstract class AnimalAsAService : IRandomMediaService
|
|||||||
public async Task<RandomMedia> GetRandomMediaAsync(Chat chat, User user)
|
public async Task<RandomMedia> GetRandomMediaAsync(Chat chat, User user)
|
||||||
{
|
{
|
||||||
var resp = await _httpClient.GetAsync("images/search");
|
var resp = await _httpClient.GetAsync("images/search");
|
||||||
var catImage = JsonConvert.DeserializeObject<List<AnimalImage>>(await resp.Content.ReadAsStringAsync())![0];
|
var catImage = JsonSerializer.Deserialize<List<AnimalImage>>(await resp.Content.ReadAsStringAsync())![0];
|
||||||
return new RandomMedia(new InputFileUrl(catImage.Url));
|
return new RandomMedia(new InputFileUrl(catImage.Url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ public abstract class AbstractKittiesService : IRandomMediaService
|
|||||||
var response = await _api.GetKittiesImageAsync(VideoType);
|
var response = await _api.GetKittiesImageAsync(VideoType);
|
||||||
|
|
||||||
return new RandomMedia(
|
return new RandomMedia(
|
||||||
new InputFile(response.Content),
|
new InputFileStream(response.Content),
|
||||||
new HtmlString().Url(response.Source, response.Title).ToString(),
|
new HtmlString().Url(response.Source, response.Title).ToString(),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using West.TelegramBot.ContentStore.Model;
|
using West.TelegramBot.ContentStore.Model;
|
||||||
using West.TelegramBot.ContentStore.Option;
|
using West.TelegramBot.ContentStore.Option;
|
||||||
@@ -20,7 +20,7 @@ public class OBoobsService : AbstractNsfwService
|
|||||||
{
|
{
|
||||||
// "/boobs/{start=0; sql offset}/{count=1; sql limit}/{order=-id;[id,rank,-rank,interest,-interest,random]}/
|
// "/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 httpResp = await _httpClient.GetAsync("boobs/1/1/random");
|
||||||
var boobsResponse = JsonConvert.DeserializeObject<List<OBoobsItem>>(await httpResp.Content.ReadAsStringAsync());
|
var boobsResponse = JsonSerializer.Deserialize<List<OBoobsItem>>(await httpResp.Content.ReadAsStringAsync());
|
||||||
var boobsItem = boobsResponse![0];
|
var boobsItem = boobsResponse![0];
|
||||||
var boobsId = boobsItem.Id.ToString("D5");
|
var boobsId = boobsItem.Id.ToString("D5");
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,15 @@ using BotFramework.Enums;
|
|||||||
using BotFramework.Utils;
|
using BotFramework.Utils;
|
||||||
using Kruzya.TelegramBot.Core.Extensions;
|
using Kruzya.TelegramBot.Core.Extensions;
|
||||||
using Kruzya.TelegramBot.Core.Service;
|
using Kruzya.TelegramBot.Core.Service;
|
||||||
using Newtonsoft.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace West.TelegramBot.DebugTools;
|
namespace West.TelegramBot.DebugTools;
|
||||||
|
|
||||||
public class Handler : BotEventHandler
|
public class Handler : BotEventHandler
|
||||||
{
|
{
|
||||||
private readonly UserService _userService;
|
private readonly UserService _userService;
|
||||||
|
private static readonly JsonSerializerOptions DumpOptions = new() { WriteIndented = true };
|
||||||
|
|
||||||
|
|
||||||
public Handler(UserService userService)
|
public Handler(UserService userService)
|
||||||
{
|
{
|
||||||
@@ -26,7 +28,7 @@ public class Handler : BotEventHandler
|
|||||||
}
|
}
|
||||||
var message = RawUpdate.Message!.ReplyToMessage ?? RawUpdate.Message;
|
var message = RawUpdate.Message!.ReplyToMessage ?? RawUpdate.Message;
|
||||||
var text = HtmlString.Empty
|
var text = HtmlString.Empty
|
||||||
.CodeWithStyle("language-json", JsonConvert.SerializeObject(message, Formatting.Indented));
|
.CodeWithStyle("language-json", JsonSerializer.Serialize(message, DumpOptions));
|
||||||
|
|
||||||
await Bot.SendHtmlStringAsync(Chat, text, replyTo: message.MessageId);
|
await Bot.SendHtmlStringAsync(Chat, text, replyTo: message.MessageId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
|
||||||
<AssemblyName>TelegramBot.D2_WhereIsXur</AssemblyName>
|
|
||||||
<RootNamespace>Kruzya.TelegramBot.Destiny2.WhereIsXur</RootNamespace>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\..\Core\Core.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Fizzler.Systems.HtmlAgilityPack" Version="1.2.1" />
|
|
||||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.39" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider;
|
|
||||||
|
|
||||||
public interface IXurPlaceProvider
|
|
||||||
{
|
|
||||||
public Task<string> GetPlaceAsync();
|
|
||||||
public string GetPlace();
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
using System.Threading.Tasks;
|
|
||||||
using Fizzler.Systems.HtmlAgilityPack;
|
|
||||||
using HtmlAgilityPack;
|
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider;
|
|
||||||
|
|
||||||
public class XurWiki : IXurPlaceProvider
|
|
||||||
{
|
|
||||||
public async Task<string> GetPlaceAsync()
|
|
||||||
{
|
|
||||||
var web = new HtmlWeb();
|
|
||||||
var document = await web.LoadFromWebAsync("https://xur.wiki");
|
|
||||||
|
|
||||||
var place = document.DocumentNode.QuerySelector(".location_name");
|
|
||||||
if (place != null)
|
|
||||||
{
|
|
||||||
return place.InnerText.Trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public string GetPlace()
|
|
||||||
{
|
|
||||||
return GetPlaceAsync().GetAwaiter().GetResult();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
using System.Threading.Tasks;
|
|
||||||
using BotFramework;
|
|
||||||
using BotFramework.Attributes;
|
|
||||||
using Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider;
|
|
||||||
using Telegram.Bot;
|
|
||||||
using Telegram.Bot.Types.Enums;
|
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur;
|
|
||||||
|
|
||||||
public class RequestHandler : BotEventHandler
|
|
||||||
{
|
|
||||||
protected readonly IXurPlaceProvider _placeProvider;
|
|
||||||
|
|
||||||
public RequestHandler(IXurPlaceProvider xurPlaceProvider)
|
|
||||||
{
|
|
||||||
_placeProvider = xurPlaceProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Command("d2_xur")]
|
|
||||||
public async Task WhereIsXur()
|
|
||||||
{
|
|
||||||
var place = await _placeProvider.GetPlaceAsync();
|
|
||||||
if (string.IsNullOrWhiteSpace(place))
|
|
||||||
{
|
|
||||||
await Response("unknown");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await Response(place);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async Task Response(string place)
|
|
||||||
{
|
|
||||||
await Bot.SendTextMessageAsync(Chat, $"<b>Xûr</b> place is <code>{place}</code>", parseMode: ParseMode.Html);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using Kruzya.TelegramBot.Core;
|
|
||||||
using Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider;
|
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur;
|
|
||||||
|
|
||||||
public class WhereIsXur : Module
|
|
||||||
{
|
|
||||||
public WhereIsXur(Core.Core core) : base(core)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void ConfigureServices(IServiceCollection services)
|
|
||||||
{
|
|
||||||
services.AddSingleton<IXurPlaceProvider, XurWiki>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -58,6 +58,6 @@ public class Common : BotEventHandler
|
|||||||
.Br();
|
.Br();
|
||||||
}
|
}
|
||||||
|
|
||||||
await Bot.SendTextMessageAsync(Chat.Id, msg.ToString(), parseMode: ParseMode.Html);
|
await Bot.SendMessage(Chat.Id, msg.ToString(), parseMode: ParseMode.Html);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ public abstract class AbstractAnimationReply : BotEventHandler
|
|||||||
animationFileOption.SetValue(animation.FileId);
|
animationFileOption.SetValue(animation.FileId);
|
||||||
_db.AddOrUpdate(animationFileOption);
|
_db.AddOrUpdate(animationFileOption);
|
||||||
|
|
||||||
await Bot.SendTextMessageAsync(Chat.Id, "Animation has been set.", replyToMessageId: Message!.ReplyToMessage!.MessageId);
|
await Bot.SendMessage(Chat.Id, "Animation has been set.", replyParameters: Message!.ReplyToMessage!.MessageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual async Task<bool> HandleAnimation()
|
protected virtual async Task<bool> HandleAnimation()
|
||||||
@@ -84,8 +84,8 @@ public abstract class AbstractAnimationReply : BotEventHandler
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Bot.SendAnimationAsync(Chat.Id, new InputFileId(animationFileId),
|
await Bot.SendAnimation(Chat.Id, new InputFileId(animationFileId),
|
||||||
replyToMessageId: GetMessageIdToReply() ?? Message?.MessageId);
|
replyParameters: GetMessageIdToReply() ?? Message?.MessageId);
|
||||||
|
|
||||||
nextUseOption.SetValue(DateTime.Now + Cooldown);
|
nextUseOption.SetValue(DateTime.Now + Cooldown);
|
||||||
_db.AddOrUpdate(nextUseOption);
|
_db.AddOrUpdate(nextUseOption);
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public class Bayan : AbstractAnimationReply
|
|||||||
{
|
{
|
||||||
if (await HandleAnimation())
|
if (await HandleAnimation())
|
||||||
{
|
{
|
||||||
await Bot.DeleteMessageAsync(Chat.Id, Message!.MessageId);
|
await Bot.DeleteMessage(Chat.Id, Message!.MessageId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class Guess : CommonHandler
|
|||||||
var doesExist = guessDict.Any(pair => pair.Value.UserId == From.Id);
|
var doesExist = guessDict.Any(pair => pair.Value.UserId == From.Id);
|
||||||
if (doesExist)
|
if (doesExist)
|
||||||
{
|
{
|
||||||
await Bot.SendTextMessageAsync(Chat, "Вы уже запустили игру.");
|
await Bot.SendMessage(Chat, "Вы уже запустили игру.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +81,8 @@ public class Guess : CommonHandler
|
|||||||
new("3") { CallbackData = $"guess|{From.Id}|answer|3" }
|
new("3") { CallbackData = $"guess|{From.Id}|answer|3" }
|
||||||
});
|
});
|
||||||
|
|
||||||
var message = await Bot.SendTextMessageAsync(Chat.Id, "Выберите число от 1 до 3.",
|
var message = await Bot.SendMessage(Chat.Id, "Выберите число от 1 до 3.",
|
||||||
replyToMessageId: messageId,
|
replyParameters: messageId,
|
||||||
replyMarkup: keyBoard
|
replyMarkup: keyBoard
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -127,7 +127,7 @@ public class Guess : CommonHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Bot.AnswerCallbackQueryAsync(CallbackQuery.Id);
|
await Bot.AnswerCallbackQuery(CallbackQuery.Id);
|
||||||
|
|
||||||
guessDict.TryRemove((int) messageId, out _);
|
guessDict.TryRemove((int) messageId, out _);
|
||||||
_guessCache.SetValue(Chat.Id, guessDict, -1);
|
_guessCache.SetValue(Chat.Id, guessDict, -1);
|
||||||
@@ -152,7 +152,7 @@ public class Guess : CommonHandler
|
|||||||
|
|
||||||
_db.AddOrUpdate(cooldownOption);
|
_db.AddOrUpdate(cooldownOption);
|
||||||
|
|
||||||
await Bot.EditMessageTextAsync(Chat, (int) messageId, message + postFix, parseMode: ParseMode.Html);
|
await Bot.EditMessageText(Chat, (int) messageId, message + postFix, parseMode: ParseMode.Html);
|
||||||
|
|
||||||
// Drop bot message.
|
// Drop bot message.
|
||||||
_requests.Add(new DeleteRequest
|
_requests.Add(new DeleteRequest
|
||||||
@@ -166,8 +166,8 @@ public class Guess : CommonHandler
|
|||||||
protected override async Task<Message> Reply(string text)
|
protected override async Task<Message> Reply(string text)
|
||||||
{
|
{
|
||||||
// TODO: move feature with autocleaning to Core CommonHandler.
|
// TODO: move feature with autocleaning to Core CommonHandler.
|
||||||
var message = await Bot.SendTextMessageAsync(Chat.Id, text,
|
var message = await Bot.SendMessage(Chat.Id, text,
|
||||||
replyToMessageId: Message?.MessageId, parseMode: ParseMode.Html);
|
replyParameters: Message?.MessageId, parseMode: ParseMode.Html);
|
||||||
|
|
||||||
_requests.Add(new DeleteRequest
|
_requests.Add(new DeleteRequest
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -132,14 +132,14 @@ public class Roll : CommonHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await Bot.SendTextMessageAsync(Chat, $"{string.Join(", ", numbers)}\n\nPositive: {positive}.\nNegative: {negative}");
|
await Bot.SendMessage(Chat, $"{string.Join(", ", numbers)}\n\nPositive: {positive}.\nNegative: {negative}");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task<Message> Reply(string text)
|
protected override async Task<Message> Reply(string text)
|
||||||
{
|
{
|
||||||
// TODO: move feature with autocleaning to Core CommonHandler.
|
// TODO: move feature with autocleaning to Core CommonHandler.
|
||||||
var message = await Bot.SendTextMessageAsync(Chat.Id, text,
|
var message = await Bot.SendMessage(Chat.Id, text,
|
||||||
replyToMessageId: Message?.MessageId, parseMode: ParseMode.Html);
|
replyParameters: Message?.MessageId, parseMode: ParseMode.Html);
|
||||||
|
|
||||||
_requests.Add(new DeleteRequest
|
_requests.Add(new DeleteRequest
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -182,7 +182,7 @@ public class Reputation : CommonHandler
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Bot.SendTextMessageAsync(Chat!, msg.ToString(), parseMode: ParseMode.Html,
|
await Bot.SendMessage(Chat!, msg.ToString(), parseMode: ParseMode.Html,
|
||||||
disableNotification: true);
|
disableNotification: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using Telegram.Bot;
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegram.Bot.Types.ReplyMarkups;
|
using Telegram.Bot.Types.ReplyMarkups;
|
||||||
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary.Handler;
|
namespace Kruzya.TelegramBot.RichSiteSummary.Handler;
|
||||||
|
|
||||||
@@ -71,11 +72,12 @@ public class FeedList : AbstractHandler
|
|||||||
var inlineButtons = new InlineKeyboardMarkup(buttons);
|
var inlineButtons = new InlineKeyboardMarkup(buttons);
|
||||||
if (message == null)
|
if (message == null)
|
||||||
{
|
{
|
||||||
await Bot.SendTextMessageAsync(new ChatId(chat.Id), text, 0, ParseMode.Html, null, true, true, false, 0, replyMarkup: inlineButtons);
|
await Bot.SendMessage(chat, text, ParseMode.Html, linkPreviewOptions: true,
|
||||||
|
disableNotification: true, replyMarkup: inlineButtons);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await Bot.EditMessageTextAsync(chat, message.MessageId, text, ParseMode.Html, null, true, replyMarkup: inlineButtons);
|
await Bot.EditMessageText(chat, message.MessageId, text, ParseMode.Html, linkPreviewOptions: true, replyMarkup: inlineButtons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +89,8 @@ public class FeedList : AbstractHandler
|
|||||||
{
|
{
|
||||||
if (!(await GenerateMenu(query)))
|
if (!(await GenerateMenu(query)))
|
||||||
{
|
{
|
||||||
await Bot.SendTextMessageAsync(Chat, $"No one feed match by search pattern (<code>{query}</code>).", 0, ParseMode.Html, null, true);
|
await Bot.SendMessage(Chat, $"No one feed match by search pattern (<code>{query}</code>).", ParseMode.Html,
|
||||||
|
linkPreviewOptions: true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,8 +99,7 @@ public class FeedList : AbstractHandler
|
|||||||
{
|
{
|
||||||
if (!(await GenerateMenu(":sub")))
|
if (!(await GenerateMenu(":sub")))
|
||||||
{
|
{
|
||||||
await Bot.SendTextMessageAsync(Chat,
|
await Bot.SendMessage(Chat, "There are no one subscription. Add new with /feed_list or /feed_search.");
|
||||||
"There are no one subscription. Add new with /feed_list or /feed_search.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,13 +193,13 @@ public class FeedList : AbstractHandler
|
|||||||
|
|
||||||
if (editableMessage == null)
|
if (editableMessage == null)
|
||||||
{
|
{
|
||||||
await Bot.SendTextMessageAsync(Chat, "Select the feed for viewing details", 0, null,
|
await Bot.SendMessage(Chat, "Select the feed for viewing details", linkPreviewOptions: true,
|
||||||
null, true, true, false, 0, replyMarkup: new InlineKeyboardMarkup(buttons));
|
disableNotification: true, replyMarkup: new InlineKeyboardMarkup(buttons));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await Bot.EditMessageTextAsync(editableMessage.Chat, editableMessage.MessageId, "Select the feed for viewing details", null, null, false,
|
await Bot.EditMessageText(editableMessage.Chat, editableMessage.MessageId,
|
||||||
new InlineKeyboardMarkup(buttons));
|
"Select the feed for viewing details", replyMarkup: new InlineKeyboardMarkup(buttons));
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -219,7 +221,7 @@ public class FeedList : AbstractHandler
|
|||||||
var fromId = Int64.Parse(data[1]);
|
var fromId = Int64.Parse(data[1]);
|
||||||
if (fromId != From.Id)
|
if (fromId != From.Id)
|
||||||
{
|
{
|
||||||
await Bot.AnswerCallbackQueryAsync(RawUpdate.CallbackQuery.Id,
|
await Bot.AnswerCallbackQuery(RawUpdate.CallbackQuery.Id,
|
||||||
"You can't perform this action: command called by another user.", true);
|
"You can't perform this action: command called by another user.", true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -238,13 +240,13 @@ public class FeedList : AbstractHandler
|
|||||||
case "do":
|
case "do":
|
||||||
if (RawUpdate.CallbackQuery.From.Id != RawUpdate.CallbackQuery.Message.Chat.Id)
|
if (RawUpdate.CallbackQuery.From.Id != RawUpdate.CallbackQuery.Message.Chat.Id)
|
||||||
{
|
{
|
||||||
var userStatus = (await Bot.GetChatMemberAsync(RawUpdate.CallbackQuery.Message.Chat, RawUpdate.CallbackQuery.From.Id)).Status;
|
var userStatus = (await Bot.GetChatMember(RawUpdate.CallbackQuery.Message.Chat, RawUpdate.CallbackQuery.From.Id)).Status;
|
||||||
var allowedUserStatuses = new ChatMemberStatus[]
|
var allowedUserStatuses = new ChatMemberStatus[]
|
||||||
{ChatMemberStatus.Administrator, ChatMemberStatus.Creator};
|
{ChatMemberStatus.Administrator, ChatMemberStatus.Creator};
|
||||||
|
|
||||||
if (!allowedUserStatuses.Contains(userStatus))
|
if (!allowedUserStatuses.Contains(userStatus))
|
||||||
{
|
{
|
||||||
await Bot.AnswerCallbackQueryAsync(RawUpdate.CallbackQuery.Id,
|
await Bot.AnswerCallbackQuery(RawUpdate.CallbackQuery.Id,
|
||||||
"You can't perform this action: you don't have administrator permissions.", true);
|
"You can't perform this action: you don't have administrator permissions.", true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -268,12 +270,12 @@ public class FeedList : AbstractHandler
|
|||||||
idx++;
|
idx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Bot.SendTextMessageAsync(RawUpdate.CallbackQuery.Message.Chat, messageTextBuilder.ToString(),
|
await Bot.SendMessage(RawUpdate.CallbackQuery.Message.Chat, messageTextBuilder.ToString(),
|
||||||
0, ParseMode.Html, null, true);
|
ParseMode.Html, linkPreviewOptions: true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Bot.AnswerCallbackQueryAsync(RawUpdate.CallbackQuery.Id);
|
await Bot.AnswerCallbackQuery(RawUpdate.CallbackQuery.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async Task ChangeFeedSubscription(Guid feedId, Chat chat, User from, Message message)
|
protected async Task ChangeFeedSubscription(Guid feedId, Chat chat, User from, Message message)
|
||||||
|
|||||||
@@ -31,6 +31,6 @@ public class StatsHandler : AbstractHandler
|
|||||||
textMessage.Append(
|
textMessage.Append(
|
||||||
$"- exists <b>{subscriptionsCount} subscriptions on feeds</b> (<b>unique subscribers: {uniqueSubscribers}</b>)");
|
$"- exists <b>{subscriptionsCount} subscriptions on feeds</b> (<b>unique subscribers: {uniqueSubscribers}</b>)");
|
||||||
|
|
||||||
await Bot.SendTextMessageAsync(Chat, textMessage.ToString(), parseMode: ParseMode.Html);
|
await Bot.SendMessage(Chat, textMessage.ToString(), parseMode: ParseMode.Html);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<AssemblyName>TelegramBot.RichSiteSummary</AssemblyName>
|
<AssemblyName>TelegramBot.RichSiteSummary</AssemblyName>
|
||||||
<RootNamespace>Kruzya.TelegramBot.RichSiteSummary</RootNamespace>
|
<RootNamespace>Kruzya.TelegramBot.RichSiteSummary</RootNamespace>
|
||||||
|
|
||||||
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -36,14 +36,12 @@ public class MessageSender : AbstractTimedHostedService
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(message.ImageUrl))
|
if (string.IsNullOrWhiteSpace(message.ImageUrl))
|
||||||
{
|
{
|
||||||
await _bot.BotClient.SendTextMessageAsync(message.ChatId, message.Text, 0, message.ParseMode, null,
|
await _bot.BotClient.SendMessage(message.ChatId, message.Text, message.ParseMode, linkPreviewOptions: message.DisableWebPagePreview);
|
||||||
message.DisableWebPagePreview);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await _bot.BotClient.SendPhotoAsync(message.ChatId, new InputFileUrl(message.ImageUrl), 0, message.Text,
|
await _bot.BotClient.SendPhoto(message.ChatId, new InputFileUrl(message.ImageUrl), message.Text, message.ParseMode);
|
||||||
message.ParseMode, null, false, message.DisableWebPagePreview);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (ApiRequestException e)
|
catch (ApiRequestException e)
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ public class Handler : BotEventHandler
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await Bot.SendChatActionAsync(Chat.Id, ChatAction.UploadDocument);
|
await Bot.SendChatAction(Chat.Id, ChatAction.UploadDocument);
|
||||||
using var file = new MemoryStream();
|
using var file = new MemoryStream();
|
||||||
await Bot.GetInfoAndDownloadFileAsync(sticker.FileId, file);
|
await Bot.GetInfoAndDownloadFile(sticker.FileId, file);
|
||||||
file.Position = 0;
|
file.Position = 0;
|
||||||
|
|
||||||
using var img = await Image.LoadAsync(file);
|
using var img = await Image.LoadAsync(file);
|
||||||
@@ -30,7 +30,7 @@ public class Handler : BotEventHandler
|
|||||||
using var outfile = new MemoryStream();
|
using var outfile = new MemoryStream();
|
||||||
await img.SaveAsPngAsync(outfile);
|
await img.SaveAsPngAsync(outfile);
|
||||||
outfile.Position = 0;
|
outfile.Position = 0;
|
||||||
await Bot.SendDocumentAsync(Chat.Id, new InputFile(outfile, "sticker.png"),
|
await Bot.SendDocument(Chat.Id, new InputFileStream(outfile, "sticker.png"),
|
||||||
replyToMessageId: RawUpdate?.Message?.MessageId);
|
replyParameters: RawUpdate?.Message?.MessageId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,10 +6,12 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<AssemblyName>TelegramBot.StickerTools</AssemblyName>
|
<AssemblyName>TelegramBot.StickerTools</AssemblyName>
|
||||||
<RootNamespace>West.TelegramBot.StickerTools</RootNamespace>
|
<RootNamespace>West.TelegramBot.StickerTools</RootNamespace>
|
||||||
|
|
||||||
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.4" />
|
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.6" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public static class MessageExtension
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var chat = await bot.GetChatAsync(
|
var chat = await bot.GetChat(
|
||||||
new ChatId(message.Text.Substring(mention.Offset, mention.Length)));
|
new ChatId(message.Text.Substring(mention.Offset, mention.Length)));
|
||||||
|
|
||||||
if (chat != null)
|
if (chat != null)
|
||||||
@@ -42,7 +42,7 @@ public static class MessageExtension
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var status = (await bot.GetChatMemberAsync(message.Chat, userId)).Status;
|
var status = (await bot.GetChatMember(message.Chat, userId)).Status;
|
||||||
|
|
||||||
if ((new ChatMemberStatus[]
|
if ((new ChatMemberStatus[]
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ using Kruzya.TelegramBot.Core.Data;
|
|||||||
using Kruzya.TelegramBot.Core.Extensions;
|
using Kruzya.TelegramBot.Core.Extensions;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.UrlLimitations;
|
namespace Kruzya.TelegramBot.UrlLimitations;
|
||||||
@@ -46,11 +45,11 @@ public class MessageHandler : BotEventHandler
|
|||||||
if (message.Entities.Count(e => e.Type == MessageEntityType.Url || e.Type == MessageEntityType.TextLink) >
|
if (message.Entities.Count(e => e.Type == MessageEntityType.Url || e.Type == MessageEntityType.TextLink) >
|
||||||
0 || await message.HasUnknownMention(Bot))
|
0 || await message.HasUnknownMention(Bot))
|
||||||
{
|
{
|
||||||
var targetChat = new ChatId(Chat.Id);
|
var targetChat = Chat.Id;
|
||||||
Task.WaitAll(
|
Task.WaitAll(
|
||||||
Bot.BanChatMemberAsync(new ChatId(Chat.Id), From.Id, DateTime.Now.AddDays(1)),
|
Bot.BanChatMember(targetChat, From.Id, DateTime.Now.AddDays(1)),
|
||||||
Bot.DeleteMessageAsync(targetChat, message.MessageId),
|
Bot.DeleteMessage(targetChat, message.MessageId),
|
||||||
Bot.SendTextMessageAsync(targetChat,
|
Bot.SendMessage(targetChat,
|
||||||
$"Member {From.ToHtml(true)} has been banned.\n<b>Reason</b>: <pre>Spam suspicion</pre>", parseMode: ParseMode.Html)
|
$"Member {From.ToHtml(true)} has been banned.\n<b>Reason</b>: <pre>Spam suspicion</pre>", parseMode: ParseMode.Html)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class Handler : BotEventHandler
|
|||||||
var memberList = tagDictionary.GetValueOrDefault(groupName, new List<long>());
|
var memberList = tagDictionary.GetValueOrDefault(groupName, new List<long>());
|
||||||
if (memberList.Contains(fromId))
|
if (memberList.Contains(fromId))
|
||||||
{
|
{
|
||||||
await Bot.SendTextMessageAsync(chatId, $"{from.ToHtml()} уже находится в группе {groupName}",
|
await Bot.SendMessage(chatId, $"{from.ToHtml()} уже находится в группе {groupName}",
|
||||||
parseMode: ParseMode.Html);
|
parseMode: ParseMode.Html);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -58,8 +58,8 @@ public class Handler : BotEventHandler
|
|||||||
userGroupOption.SetValue(tagDictionary);
|
userGroupOption.SetValue(tagDictionary);
|
||||||
_db.AddOrUpdate(userGroupOption);
|
_db.AddOrUpdate(userGroupOption);
|
||||||
|
|
||||||
_userCache.SetValue(repliedMessage.From.Id, repliedMessage.From, Int32.MaxValue);
|
_userCache.SetValue(repliedMessage.From.Id, repliedMessage.From, int.MaxValue);
|
||||||
await Bot.SendTextMessageAsync(chatId, $"{from.ToHtml()} добавлен в группу {groupName}",
|
await Bot.SendMessage(chatId, $"{from.ToHtml()} добавлен в группу {groupName}",
|
||||||
parseMode: ParseMode.Html);
|
parseMode: ParseMode.Html);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,16 +89,15 @@ public class Handler : BotEventHandler
|
|||||||
msg.UserMention(await GetUser(userId, Chat)).Text(", ");
|
msg.UserMention(await GetUser(userId, Chat)).Text(", ");
|
||||||
}
|
}
|
||||||
|
|
||||||
await Bot.SendTextMessageAsync(Chat.Id, msg.ToString().TrimEnd(',', ' '), parseMode: ParseMode.Html);
|
await Bot.SendMessage(Chat.Id, msg.ToString().TrimEnd(',', ' '), parseMode: ParseMode.Html);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async Task<User> GetUser(long userId, Chat chat)
|
protected async Task<User> GetUser(long userId, Chat chat)
|
||||||
{
|
{
|
||||||
User user;
|
if (!_userCache.TryGetValue(userId, out var user))
|
||||||
if (!_userCache.TryGetValue(userId, out user))
|
|
||||||
{
|
{
|
||||||
user = (await Bot.GetChatMemberAsync(Chat.Id, userId)).User;
|
user = (await Bot.GetChatMember(Chat.Id, userId)).User;
|
||||||
_userCache.SetValue(userId, user, Int32.MaxValue);
|
_userCache.SetValue(userId, user, int.MaxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
|
|||||||
Reference in New Issue
Block a user