mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[cas] use file-scoped namespaces
This commit is contained in:
@@ -1,31 +1,30 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Kruzya.TelegramBot.CombotAntiSpam.Combot
|
||||
namespace Kruzya.TelegramBot.CombotAntiSpam.Combot;
|
||||
|
||||
internal class CombotApiResponse
|
||||
{
|
||||
internal class CombotApiResponse
|
||||
public class ApiResult
|
||||
{
|
||||
public class ApiResult
|
||||
{
|
||||
[JsonProperty("messages")]
|
||||
public string[] Messages { get; set; }
|
||||
[JsonProperty("messages")]
|
||||
public string[] Messages { get; set; }
|
||||
|
||||
[JsonProperty("time_added")]
|
||||
public int TimeAdded { get; set; }
|
||||
[JsonProperty("time_added")]
|
||||
public int TimeAdded { get; set; }
|
||||
|
||||
[JsonProperty("offenses")]
|
||||
public int Offenses { get; set; }
|
||||
[JsonProperty("offenses")]
|
||||
public int Offenses { get; set; }
|
||||
|
||||
public DateTime AddedAt => DateTimeOffset.FromUnixTimeSeconds(TimeAdded).DateTime;
|
||||
}
|
||||
|
||||
[JsonProperty("ok")]
|
||||
public bool IsSpammer { get; set; }
|
||||
|
||||
[JsonProperty("description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
[JsonProperty("result")]
|
||||
public ApiResult Result { get; set; }
|
||||
public DateTime AddedAt => DateTimeOffset.FromUnixTimeSeconds(TimeAdded).DateTime;
|
||||
}
|
||||
|
||||
[JsonProperty("ok")]
|
||||
public bool IsSpammer { get; set; }
|
||||
|
||||
[JsonProperty("description")]
|
||||
public string Description { get; set; }
|
||||
|
||||
[JsonProperty("result")]
|
||||
public ApiResult Result { get; set; }
|
||||
}
|
||||
@@ -4,27 +4,26 @@ using System.Threading.Tasks;
|
||||
using Kruzya.TelegramBot.Core.Extensions;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace Kruzya.TelegramBot.CombotAntiSpam.Combot
|
||||
namespace Kruzya.TelegramBot.CombotAntiSpam.Combot;
|
||||
|
||||
public class CombotClient : ICombotClient
|
||||
{
|
||||
public class CombotClient : ICombotClient
|
||||
public HttpClient _HttpClient;
|
||||
|
||||
public CombotClient()
|
||||
{
|
||||
public HttpClient _HttpClient;
|
||||
|
||||
public CombotClient()
|
||||
{
|
||||
_HttpClient = new HttpClient();
|
||||
_HttpClient.BaseAddress = new Uri("https://api.cas.chat/check");
|
||||
}
|
||||
_HttpClient = new HttpClient();
|
||||
_HttpClient.BaseAddress = new Uri("https://api.cas.chat/check");
|
||||
}
|
||||
|
||||
public bool IsSpammer(User user)
|
||||
{
|
||||
return IsSpammerAsync(user).GetAwaiter().GetResult();
|
||||
}
|
||||
public bool IsSpammer(User user)
|
||||
{
|
||||
return IsSpammerAsync(user).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public async Task<bool> IsSpammerAsync(User user)
|
||||
{
|
||||
var result = await _HttpClient.GetJsonAsync<CombotApiResponse>($"?user_id={user.Id}");
|
||||
return result.IsSpammer;
|
||||
}
|
||||
public async Task<bool> IsSpammerAsync(User user)
|
||||
{
|
||||
var result = await _HttpClient.GetJsonAsync<CombotApiResponse>($"?user_id={user.Id}");
|
||||
return result.IsSpammer;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
using System.Threading.Tasks;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace Kruzya.TelegramBot.CombotAntiSpam.Combot
|
||||
namespace Kruzya.TelegramBot.CombotAntiSpam.Combot;
|
||||
|
||||
public interface ICombotClient
|
||||
{
|
||||
public interface ICombotClient
|
||||
{
|
||||
public bool IsSpammer(User user);
|
||||
public Task<bool> IsSpammerAsync(User user);
|
||||
}
|
||||
public bool IsSpammer(User user);
|
||||
public Task<bool> IsSpammerAsync(User user);
|
||||
}
|
||||
Reference in New Issue
Block a user