mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
🚧 Core improvements
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Extensions
|
||||
{
|
||||
public static class HttpClientExtension
|
||||
{
|
||||
public static async Task<T> GetJsonAsync<T>(this HttpClient client, Uri requestUri)
|
||||
{
|
||||
var response = await client.GetStringAsync(requestUri);
|
||||
return JsonConvert.DeserializeObject<T>(response);
|
||||
}
|
||||
|
||||
public static async Task<T> GetJsonAsync<T>(this HttpClient client, string requestUri)
|
||||
{
|
||||
var response = await client.GetStringAsync(requestUri);
|
||||
return JsonConvert.DeserializeObject<T>(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Extensions
|
||||
{
|
||||
internal static class ModuleArrayExtension
|
||||
{
|
||||
public static void ConfigureServices(this Module[] modules, IServiceCollection services)
|
||||
{
|
||||
foreach (var module in modules) module.ConfigureServices(services);
|
||||
}
|
||||
|
||||
public static void Configure(this Module[] modules, IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
foreach (var module in modules) module.Configure(app, env);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Web;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Extensions
|
||||
{
|
||||
public static class StringExtension
|
||||
{
|
||||
public static string HtmlEncode(this string content)
|
||||
{
|
||||
return HttpUtility.HtmlEncode(content);
|
||||
}
|
||||
|
||||
public static string HtmlDecode(this string content)
|
||||
{
|
||||
return HttpUtility.HtmlDecode(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Text;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Extensions
|
||||
{
|
||||
public static class UserExtension
|
||||
{
|
||||
public static string ToHtml(this User user)
|
||||
{
|
||||
var text = new StringBuilder();
|
||||
text.Append("<a href=\"tg://user?id={member.Id}\">");
|
||||
if (!string.IsNullOrWhiteSpace(user.Username))
|
||||
text.Append(user.Username);
|
||||
else
|
||||
text.Append($"{user.FirstName} {user.LastName}".Trim().HtmlEncode());
|
||||
text.Append("</a>");
|
||||
|
||||
return text.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user