mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Use file-scoped namespaces
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
namespace Kruzya.TelegramBot.Core.Cache
|
namespace Kruzya.TelegramBot.Core.Cache;
|
||||||
|
|
||||||
|
public interface ICacheStorage<TKey, TValue>
|
||||||
{
|
{
|
||||||
public interface ICacheStorage<TKey, TValue>
|
|
||||||
{
|
|
||||||
public bool TryGetValue(TKey key, out TValue value);
|
public bool TryGetValue(TKey key, out TValue value);
|
||||||
public void SetValue(TKey key, TValue value, int timeToLive);
|
public void SetValue(TKey key, TValue value, int timeToLive);
|
||||||
public TValue GetOr(TKey key, TValue value);
|
public TValue GetOr(TKey key, TValue value);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Cache
|
namespace Kruzya.TelegramBot.Core.Cache;
|
||||||
|
|
||||||
|
public class MemoryCache<TKey, TValue> : ICacheStorage<TKey, TValue>
|
||||||
{
|
{
|
||||||
public class MemoryCache<TKey, TValue> : ICacheStorage<TKey, TValue>
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a cache entry in internal dictionary.
|
/// Represents a cache entry in internal dictionary.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -100,5 +100,4 @@ namespace Kruzya.TelegramBot.Core.Cache
|
|||||||
Value = value
|
Value = value
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+3
-4
@@ -7,10 +7,10 @@ using System.Linq;
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core
|
namespace Kruzya.TelegramBot.Core;
|
||||||
|
|
||||||
|
public sealed class Core
|
||||||
{
|
{
|
||||||
public sealed class Core
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Core API version.
|
/// The Core API version.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -203,5 +203,4 @@ namespace Kruzya.TelegramBot.Core
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Data
|
namespace Kruzya.TelegramBot.Core.Data;
|
||||||
|
|
||||||
|
public class BotUser
|
||||||
{
|
{
|
||||||
public class BotUser
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The unique bot user identifier.
|
/// The unique bot user identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -20,5 +20,4 @@ namespace Kruzya.TelegramBot.Core.Data
|
|||||||
/// The Telegram User identifier.
|
/// The Telegram User identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long UserId { get; set; }
|
public long UserId { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,10 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Data
|
namespace Kruzya.TelegramBot.Core.Data;
|
||||||
|
|
||||||
|
public class BotUserValue
|
||||||
{
|
{
|
||||||
public class BotUserValue
|
|
||||||
{
|
|
||||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
[Key]
|
[Key]
|
||||||
public Guid BotUserValueId { get; set; }
|
public Guid BotUserValueId { get; set; }
|
||||||
@@ -37,5 +37,4 @@ namespace Kruzya.TelegramBot.Core.Data
|
|||||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull });
|
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull });
|
||||||
ValueType = value.GetType().FullName;
|
ValueType = value.GetType().FullName;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
using Kruzya.TelegramBot.Core.EF;
|
using Kruzya.TelegramBot.Core.EF;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Data
|
namespace Kruzya.TelegramBot.Core.Data;
|
||||||
|
|
||||||
|
public class CoreContext : AutoSaveDbContext
|
||||||
{
|
{
|
||||||
public class CoreContext : AutoSaveDbContext
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The all known users.
|
/// The all known users.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -21,5 +21,4 @@ namespace Kruzya.TelegramBot.Core.Data
|
|||||||
{
|
{
|
||||||
Database.Migrate();
|
Database.Migrate();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,17 +2,17 @@
|
|||||||
using BotFramework;
|
using BotFramework;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core
|
namespace Kruzya.TelegramBot.Core;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Resolves the GUIDs from database to entities.
|
/// Resolves the GUIDs from database to entities.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TResolvedEntity">Entity type</typeparam>
|
/// <typeparam name="TResolvedEntity">Entity type</typeparam>
|
||||||
/// <typeparam name="TAppContext">Database context where entity should be finded</typeparam>
|
/// <typeparam name="TAppContext">Database context where entity should be finded</typeparam>
|
||||||
public class DbResolverParameter<TResolvedEntity, TAppContext> : IParameterParser<TResolvedEntity>
|
public class DbResolverParameter<TResolvedEntity, TAppContext> : IParameterParser<TResolvedEntity>
|
||||||
where TAppContext : DbContext
|
where TAppContext : DbContext
|
||||||
where TResolvedEntity : class
|
where TResolvedEntity : class
|
||||||
{
|
{
|
||||||
private TAppContext _dbContext;
|
private TAppContext _dbContext;
|
||||||
|
|
||||||
public DbResolverParameter(TAppContext dbContext)
|
public DbResolverParameter(TAppContext dbContext)
|
||||||
@@ -37,5 +37,4 @@ namespace Kruzya.TelegramBot.Core
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Extensions
|
namespace Kruzya.TelegramBot.Core.Extensions;
|
||||||
|
|
||||||
|
public static class BotExtension
|
||||||
{
|
{
|
||||||
public static class BotExtension
|
|
||||||
{
|
|
||||||
public static async Task<bool> CanPunishMember(this ITelegramBotClient bot, Chat chat, User user, User victim = null)
|
public static async Task<bool> CanPunishMember(this ITelegramBotClient bot, Chat chat, User user, User victim = null)
|
||||||
{
|
{
|
||||||
var canUse = await IsUserAdminAsync(bot, chat, user);
|
var canUse = await IsUserAdminAsync(bot, chat, user);
|
||||||
@@ -42,5 +42,4 @@ namespace Kruzya.TelegramBot.Core.Extensions
|
|||||||
return await bot.GetChatMemberAsync(chat.Id, user.Id) is ChatMemberOwner
|
return await bot.GetChatMemberAsync(chat.Id, user.Id) is ChatMemberOwner
|
||||||
or ChatMemberAdministrator {CanRestrictMembers: true};
|
or ChatMemberAdministrator {CanRestrictMembers: true};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,10 +3,10 @@ using System.Net.Http;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Newtonsoft.Json;
|
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);
|
||||||
@@ -18,5 +18,4 @@ namespace Kruzya.TelegramBot.Core.Extensions
|
|||||||
var response = await client.GetStringAsync(requestUri);
|
var response = await client.GetStringAsync(requestUri);
|
||||||
return JsonConvert.DeserializeObject<T>(response);
|
return JsonConvert.DeserializeObject<T>(response);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Extensions
|
namespace Kruzya.TelegramBot.Core.Extensions;
|
||||||
|
|
||||||
|
internal static class ModuleArrayExtension
|
||||||
{
|
{
|
||||||
internal static class ModuleArrayExtension
|
|
||||||
{
|
|
||||||
public static void ConfigureServices(this Module[] modules, IServiceCollection services)
|
public static void ConfigureServices(this Module[] modules, IServiceCollection services)
|
||||||
{
|
{
|
||||||
foreach (var module in modules) module.ConfigureServices(services);
|
foreach (var module in modules) module.ConfigureServices(services);
|
||||||
@@ -15,5 +15,4 @@ namespace Kruzya.TelegramBot.Core.Extensions
|
|||||||
{
|
{
|
||||||
foreach (var module in modules) module.Configure(app, env);
|
foreach (var module in modules) module.Configure(app, env);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Extensions
|
namespace Kruzya.TelegramBot.Core.Extensions;
|
||||||
|
|
||||||
|
public static partial class RepositoryExtension
|
||||||
{
|
{
|
||||||
public static partial class RepositoryExtension
|
|
||||||
{
|
|
||||||
public static TEntity Create<TEntity>(this DbSet<TEntity> repository) where TEntity : class, new()
|
public static TEntity Create<TEntity>(this DbSet<TEntity> repository) where TEntity : class, new()
|
||||||
{
|
{
|
||||||
var entity = new TEntity();
|
var entity = new TEntity();
|
||||||
@@ -11,5 +11,4 @@ namespace Kruzya.TelegramBot.Core.Extensions
|
|||||||
|
|
||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
using System.Web;
|
using System.Web;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Extensions
|
namespace Kruzya.TelegramBot.Core.Extensions;
|
||||||
|
|
||||||
|
public static class StringExtension
|
||||||
{
|
{
|
||||||
public static class StringExtension
|
|
||||||
{
|
|
||||||
public static string HtmlEncode(this string content)
|
public static string HtmlEncode(this string content)
|
||||||
{
|
{
|
||||||
return HttpUtility.HtmlEncode(content);
|
return HttpUtility.HtmlEncode(content);
|
||||||
@@ -13,5 +13,4 @@ namespace Kruzya.TelegramBot.Core.Extensions
|
|||||||
{
|
{
|
||||||
return HttpUtility.HtmlDecode(content);
|
return HttpUtility.HtmlDecode(content);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Extensions
|
namespace Kruzya.TelegramBot.Core.Extensions;
|
||||||
|
|
||||||
|
public static class UserExtension
|
||||||
{
|
{
|
||||||
public static class UserExtension
|
|
||||||
{
|
|
||||||
public static string ToHtml(this User user, bool byUsername = false)
|
public static string ToHtml(this User user, bool byUsername = false)
|
||||||
{
|
{
|
||||||
var text = new StringBuilder();
|
var text = new StringBuilder();
|
||||||
@@ -27,5 +27,4 @@ namespace Kruzya.TelegramBot.Core.Extensions
|
|||||||
|
|
||||||
return $"{name} (ID: {user.Id}, Username: {user.Username ?? "N/A"})";
|
return $"{name} (ID: {user.Id}, Username: {user.Username ?? "N/A"})";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -9,10 +9,10 @@ using Telegram.Bot;
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Handler
|
namespace Kruzya.TelegramBot.Core.Handler;
|
||||||
|
|
||||||
|
public abstract class CommonHandler : BotEventHandler
|
||||||
{
|
{
|
||||||
public abstract class CommonHandler : BotEventHandler
|
|
||||||
{
|
|
||||||
protected readonly CoreContext Db;
|
protected readonly CoreContext Db;
|
||||||
|
|
||||||
protected Message? Message => RawUpdate.Message;
|
protected Message? Message => RawUpdate.Message;
|
||||||
@@ -58,5 +58,4 @@ namespace Kruzya.TelegramBot.Core.Handler
|
|||||||
{
|
{
|
||||||
await Bot.AnswerCallbackQueryAsync(id, message);
|
await Bot.AnswerCallbackQueryAsync(id, message);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,10 +6,10 @@ using Kruzya.TelegramBot.Core.Data;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Handler
|
namespace Kruzya.TelegramBot.Core.Handler;
|
||||||
|
|
||||||
|
public class GeneralHandler : BotEventHandler
|
||||||
{
|
{
|
||||||
public class GeneralHandler : BotEventHandler
|
|
||||||
{
|
|
||||||
[AttributeUsage(AttributeTargets.Method)]
|
[AttributeUsage(AttributeTargets.Method)]
|
||||||
public sealed class HandleEverythingAttribute : HandlerAttribute
|
public sealed class HandleEverythingAttribute : HandlerAttribute
|
||||||
{
|
{
|
||||||
@@ -72,5 +72,4 @@ namespace Kruzya.TelegramBot.Core.Handler
|
|||||||
UserId = user
|
UserId = user
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+3
-4
@@ -3,10 +3,10 @@ using Microsoft.AspNetCore.Hosting;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core
|
namespace Kruzya.TelegramBot.Core;
|
||||||
|
|
||||||
|
public abstract class Module
|
||||||
{
|
{
|
||||||
public abstract class Module
|
|
||||||
{
|
|
||||||
protected readonly Core Core;
|
protected readonly Core Core;
|
||||||
protected IConfiguration Configuration => Core.Configuration;
|
protected IConfiguration Configuration => Core.Configuration;
|
||||||
|
|
||||||
@@ -32,5 +32,4 @@ namespace Kruzya.TelegramBot.Core
|
|||||||
{
|
{
|
||||||
return (T) Core.EnsureLoaded(typeof(T));
|
return (T) Core.EnsureLoaded(typeof(T));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+3
-4
@@ -2,10 +2,10 @@ using System.Globalization;
|
|||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core
|
namespace Kruzya.TelegramBot.Core;
|
||||||
|
|
||||||
|
public class Program
|
||||||
{
|
{
|
||||||
public class Program
|
|
||||||
{
|
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
CultureInfo.CurrentCulture = new CultureInfo("ru-RU");
|
CultureInfo.CurrentCulture = new CultureInfo("ru-RU");
|
||||||
@@ -16,5 +16,4 @@ namespace Kruzya.TelegramBot.Core
|
|||||||
Host.CreateDefaultBuilder(args)
|
Host.CreateDefaultBuilder(args)
|
||||||
.UseSystemd()
|
.UseSystemd()
|
||||||
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
|
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,10 @@ using BotFramework.Abstractions;
|
|||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Service
|
namespace Kruzya.TelegramBot.Core.Service;
|
||||||
|
|
||||||
|
public abstract class AbstractTimedHostedService : IHostedService, IDisposable
|
||||||
{
|
{
|
||||||
public abstract class AbstractTimedHostedService : IHostedService, IDisposable
|
|
||||||
{
|
|
||||||
private Timer _timer;
|
private Timer _timer;
|
||||||
|
|
||||||
protected readonly ILogger _logger;
|
protected readonly ILogger _logger;
|
||||||
@@ -70,5 +70,4 @@ namespace Kruzya.TelegramBot.Core.Service
|
|||||||
{
|
{
|
||||||
await Task.Delay(500);
|
await Task.Delay(500);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,14 +3,13 @@ using System.Threading.Tasks;
|
|||||||
using Kruzya.TelegramBot.Core.Data;
|
using Kruzya.TelegramBot.Core.Data;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Service
|
namespace Kruzya.TelegramBot.Core.Service;
|
||||||
|
|
||||||
|
public interface IReputation
|
||||||
{
|
{
|
||||||
public interface IReputation
|
|
||||||
{
|
|
||||||
public Task<double> GetUserReputationAsync(Chat chat, User user);
|
public Task<double> GetUserReputationAsync(Chat chat, User user);
|
||||||
public Task<double> SetUserReputationAsync(Chat chat, User user, double value);
|
public Task<double> SetUserReputationAsync(Chat chat, User user, double value);
|
||||||
public Task<double> GetReputationDiffAsync(Chat chat, User sender, User receiver);
|
public Task<double> GetReputationDiffAsync(Chat chat, User sender, User receiver);
|
||||||
public Task<double> IncrementReputationAsync(Chat chat, User user, double diff);
|
public Task<double> IncrementReputationAsync(Chat chat, User user, double diff);
|
||||||
public Task<IEnumerable<IReputationEntity>> GetChatRatingAsync(Chat chat, int limit = 10, int offset = 0);
|
public Task<IEnumerable<IReputationEntity>> GetChatRatingAsync(Chat chat, int limit = 10, int offset = 0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -11,10 +11,10 @@ using Microsoft.Extensions.Logging;
|
|||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core.Service
|
namespace Kruzya.TelegramBot.Core.Service;
|
||||||
|
|
||||||
|
public class UserService
|
||||||
{
|
{
|
||||||
public class UserService
|
|
||||||
{
|
|
||||||
private readonly List<long> _superUsers;
|
private readonly List<long> _superUsers;
|
||||||
private readonly Dictionary<long, string> _statusMap;
|
private readonly Dictionary<long, string> _statusMap;
|
||||||
private readonly ICacheStorage<long, User> _userCache;
|
private readonly ICacheStorage<long, User> _userCache;
|
||||||
@@ -87,5 +87,4 @@ namespace Kruzya.TelegramBot.Core.Service
|
|||||||
{
|
{
|
||||||
return _statusMap.ContainsKey(userId) ? _statusMap[userId] : null;
|
return _statusMap.ContainsKey(userId) ? _statusMap[userId] : null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+3
-4
@@ -14,10 +14,10 @@ using System.Collections.Concurrent;
|
|||||||
using Kruzya.TelegramBot.Core.Options;
|
using Kruzya.TelegramBot.Core.Options;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Core
|
namespace Kruzya.TelegramBot.Core;
|
||||||
|
|
||||||
|
public class Startup
|
||||||
{
|
{
|
||||||
public class Startup
|
|
||||||
{
|
|
||||||
private Core _core;
|
private Core _core;
|
||||||
|
|
||||||
public Startup(IConfiguration configuration)
|
public Startup(IConfiguration configuration)
|
||||||
@@ -66,5 +66,4 @@ namespace Kruzya.TelegramBot.Core
|
|||||||
{
|
{
|
||||||
_core.Modules.Configure(app, env);
|
_core.Modules.Configure(app, env);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,10 +6,10 @@ using Newtonsoft.Json.Converters;
|
|||||||
using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json.Serialization;
|
||||||
using West.TelegramBot.ChatQuotes.Json;
|
using West.TelegramBot.ChatQuotes.Json;
|
||||||
|
|
||||||
namespace West.TelegramBot.ChatQuotes
|
namespace West.TelegramBot.ChatQuotes;
|
||||||
|
|
||||||
|
public class ChatQuotes : Module
|
||||||
{
|
{
|
||||||
public class ChatQuotes : Module
|
|
||||||
{
|
|
||||||
public static readonly JsonSerializerSettings SerializerSettings = new()
|
public static readonly JsonSerializerSettings SerializerSettings = new()
|
||||||
{
|
{
|
||||||
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
|
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
|
||||||
@@ -28,5 +28,4 @@ namespace West.TelegramBot.ChatQuotes
|
|||||||
{
|
{
|
||||||
services.AddSingleton<QuoteGeneratorService>();
|
services.AddSingleton<QuoteGeneratorService>();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json.Serialization;
|
||||||
|
|
||||||
namespace West.TelegramBot.ChatQuotes.Json
|
namespace West.TelegramBot.ChatQuotes.Json;
|
||||||
|
|
||||||
|
class NullToEmptyObjectResolver : DefaultContractResolver
|
||||||
{
|
{
|
||||||
class NullToEmptyObjectResolver : DefaultContractResolver
|
|
||||||
{
|
|
||||||
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
|
protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
|
||||||
{
|
{
|
||||||
return type.GetProperties()
|
return type.GetProperties()
|
||||||
@@ -14,5 +14,4 @@ namespace West.TelegramBot.ChatQuotes.Json
|
|||||||
return jp;
|
return jp;
|
||||||
}).ToList();
|
}).ToList();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,10 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using West.TelegramBot.CodeWatcher.Options;
|
using West.TelegramBot.CodeWatcher.Options;
|
||||||
using West.TelegramBot.CodeWatcher.Service;
|
using West.TelegramBot.CodeWatcher.Service;
|
||||||
|
|
||||||
namespace West.TelegramBot.CodeWatcher
|
namespace West.TelegramBot.CodeWatcher;
|
||||||
|
|
||||||
|
public class CodeWatcher : Module
|
||||||
{
|
{
|
||||||
public class CodeWatcher : Module
|
|
||||||
{
|
|
||||||
public CodeWatcher(Core core) : base(core) {}
|
public CodeWatcher(Core core) : base(core) {}
|
||||||
|
|
||||||
public override void ConfigureServices(IServiceCollection services)
|
public override void ConfigureServices(IServiceCollection services)
|
||||||
@@ -19,5 +19,4 @@ namespace West.TelegramBot.CodeWatcher
|
|||||||
c.BaseAddress = new Uri(Core.Configuration["HastebinUrl"]!);
|
c.BaseAddress = new Uri(Core.Configuration["HastebinUrl"]!);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,6 @@ using BotFramework.Enums;
|
|||||||
using Kruzya.TelegramBot.CombotAntiSpam.Combot;
|
using Kruzya.TelegramBot.CombotAntiSpam.Combot;
|
||||||
using Kruzya.TelegramBot.Core.Extensions;
|
using Kruzya.TelegramBot.Core.Extensions;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.CombotAntiSpam;
|
namespace Kruzya.TelegramBot.CombotAntiSpam;
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider
|
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider;
|
||||||
|
|
||||||
|
public interface IXurPlaceProvider
|
||||||
{
|
{
|
||||||
public interface IXurPlaceProvider
|
|
||||||
{
|
|
||||||
public Task<string> GetPlaceAsync();
|
public Task<string> GetPlaceAsync();
|
||||||
public string GetPlace();
|
public string GetPlace();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,10 @@ using System.Threading.Tasks;
|
|||||||
using Fizzler.Systems.HtmlAgilityPack;
|
using Fizzler.Systems.HtmlAgilityPack;
|
||||||
using HtmlAgilityPack;
|
using HtmlAgilityPack;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider
|
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider;
|
||||||
|
|
||||||
|
public class XurWiki : IXurPlaceProvider
|
||||||
{
|
{
|
||||||
public class XurWiki : IXurPlaceProvider
|
|
||||||
{
|
|
||||||
public async Task<string> GetPlaceAsync()
|
public async Task<string> GetPlaceAsync()
|
||||||
{
|
{
|
||||||
var web = new HtmlWeb();
|
var web = new HtmlWeb();
|
||||||
@@ -24,5 +24,4 @@ namespace Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider
|
|||||||
{
|
{
|
||||||
return GetPlaceAsync().GetAwaiter().GetResult();
|
return GetPlaceAsync().GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,10 @@ using Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider;
|
|||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur
|
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur;
|
||||||
|
|
||||||
|
public class RequestHandler : BotEventHandler
|
||||||
{
|
{
|
||||||
public class RequestHandler : BotEventHandler
|
|
||||||
{
|
|
||||||
protected readonly IXurPlaceProvider _placeProvider;
|
protected readonly IXurPlaceProvider _placeProvider;
|
||||||
|
|
||||||
public RequestHandler(IXurPlaceProvider xurPlaceProvider)
|
public RequestHandler(IXurPlaceProvider xurPlaceProvider)
|
||||||
@@ -33,5 +33,4 @@ namespace Kruzya.TelegramBot.Destiny2.WhereIsXur
|
|||||||
{
|
{
|
||||||
await Bot.SendTextMessageAsync(Chat, $"<b>Xûr</b> place is <code>{place}</code>", parseMode: ParseMode.Html);
|
await Bot.SendTextMessageAsync(Chat, $"<b>Xûr</b> place is <code>{place}</code>", parseMode: ParseMode.Html);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -2,10 +2,10 @@
|
|||||||
using Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider;
|
using Kruzya.TelegramBot.Destiny2.WhereIsXur.Provider;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur
|
namespace Kruzya.TelegramBot.Destiny2.WhereIsXur;
|
||||||
|
|
||||||
|
public class WhereIsXur : Module
|
||||||
{
|
{
|
||||||
public class WhereIsXur : Module
|
|
||||||
{
|
|
||||||
public WhereIsXur(Core.Core core) : base(core)
|
public WhereIsXur(Core.Core core) : base(core)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -14,5 +14,4 @@ namespace Kruzya.TelegramBot.Destiny2.WhereIsXur
|
|||||||
{
|
{
|
||||||
services.AddSingleton<IXurPlaceProvider, XurWiki>();
|
services.AddSingleton<IXurPlaceProvider, XurWiki>();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,15 +6,14 @@ using Kruzya.TelegramBot.Core;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
|
||||||
namespace West.Entertainment
|
namespace West.Entertainment;
|
||||||
|
|
||||||
|
public class Entertainment : Module
|
||||||
{
|
{
|
||||||
public class Entertainment : Module
|
|
||||||
{
|
|
||||||
public Entertainment(Core core) : base(core) { }
|
public Entertainment(Core core) : base(core) { }
|
||||||
|
|
||||||
public override void ConfigureServices(IServiceCollection services)
|
public override void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddSingleton<IGuessCache, GuessCache>();
|
services.AddSingleton<IGuessCache, GuessCache>();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -13,10 +13,10 @@ using Microsoft.Extensions.Logging;
|
|||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace West.Entertainment.Handler
|
namespace West.Entertainment.Handler;
|
||||||
|
|
||||||
|
public class Common : BotEventHandler
|
||||||
{
|
{
|
||||||
public class Common : BotEventHandler
|
|
||||||
{
|
|
||||||
private readonly UserService _userService;
|
private readonly UserService _userService;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly CoreContext _db;
|
private readonly CoreContext _db;
|
||||||
@@ -60,5 +60,4 @@ namespace West.Entertainment.Handler
|
|||||||
|
|
||||||
await Bot.SendTextMessageAsync(Chat.Id, msg.ToString(), parseMode: ParseMode.Html);
|
await Bot.SendTextMessageAsync(Chat.Id, msg.ToString(), parseMode: ParseMode.Html);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -11,10 +11,10 @@ using Microsoft.Extensions.Logging;
|
|||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
namespace West.Entertainment.Handler.Fun
|
namespace West.Entertainment.Handler.Fun;
|
||||||
|
|
||||||
|
public abstract class AbstractAnimationReply : BotEventHandler
|
||||||
{
|
{
|
||||||
public abstract class AbstractAnimationReply : BotEventHandler
|
|
||||||
{
|
|
||||||
private readonly CoreContext _db;
|
private readonly CoreContext _db;
|
||||||
|
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
@@ -104,5 +104,4 @@ namespace West.Entertainment.Handler.Fun
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected virtual int? GetMessageIdToReply() => Message?.MessageId;
|
protected virtual int? GetMessageIdToReply() => Message?.MessageId;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -10,10 +10,10 @@ using Kruzya.TelegramBot.Core.Data;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
|
|
||||||
namespace West.Entertainment.Handler.Fun
|
namespace West.Entertainment.Handler.Fun;
|
||||||
|
|
||||||
|
public class Bayan : AbstractAnimationReply
|
||||||
{
|
{
|
||||||
public class Bayan : AbstractAnimationReply
|
|
||||||
{
|
|
||||||
protected override TimeSpan Cooldown => TimeSpan.Zero;
|
protected override TimeSpan Cooldown => TimeSpan.Zero;
|
||||||
|
|
||||||
public Bayan(CoreContext db, ILogger<Bayan> logger, ThreadSafeRandom rng) : base(db, logger, rng) { }
|
public Bayan(CoreContext db, ILogger<Bayan> logger, ThreadSafeRandom rng) : base(db, logger, rng) { }
|
||||||
@@ -47,5 +47,4 @@ namespace West.Entertainment.Handler.Fun
|
|||||||
protected override bool CanHandle()
|
protected override bool CanHandle()
|
||||||
=> Message?.ReplyToMessage != null;
|
=> Message?.ReplyToMessage != null;
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,10 +6,10 @@ using Kruzya.TelegramBot.Core;
|
|||||||
using Kruzya.TelegramBot.Core.Data;
|
using Kruzya.TelegramBot.Core.Data;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace West.Entertainment.Handler.Fun
|
namespace West.Entertainment.Handler.Fun;
|
||||||
|
|
||||||
|
public class JavaScript : AbstractAnimationReply
|
||||||
{
|
{
|
||||||
public class JavaScript : AbstractAnimationReply
|
|
||||||
{
|
|
||||||
public JavaScript(CoreContext db, ILogger<JavaScript> logger, ThreadSafeRandom rng) : base(db, logger, rng) { }
|
public JavaScript(CoreContext db, ILogger<JavaScript> logger, ThreadSafeRandom rng) : base(db, logger, rng) { }
|
||||||
|
|
||||||
protected override Regex AnimationMatch => new(
|
protected override Regex AnimationMatch => new(
|
||||||
@@ -29,5 +29,4 @@ namespace West.Entertainment.Handler.Fun
|
|||||||
{
|
{
|
||||||
await HandleAnimation();
|
await HandleAnimation();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -8,10 +8,10 @@ using Kruzya.TelegramBot.Core;
|
|||||||
using Kruzya.TelegramBot.Core.Data;
|
using Kruzya.TelegramBot.Core.Data;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace West.Entertainment.Handler.Fun
|
namespace West.Entertainment.Handler.Fun;
|
||||||
|
|
||||||
|
public class Python : AbstractAnimationReply
|
||||||
{
|
{
|
||||||
public class Python : AbstractAnimationReply
|
|
||||||
{
|
|
||||||
protected override Regex AnimationMatch =>
|
protected override Regex AnimationMatch =>
|
||||||
new("питон|пайтон|python|путхон|питухон|петухон",
|
new("питон|пайтон|python|путхон|питухон|петухон",
|
||||||
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
|
RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
|
||||||
@@ -32,5 +32,4 @@ namespace West.Entertainment.Handler.Fun
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Python(CoreContext db, ILogger<Python> logger, ThreadSafeRandom rng) : base(db, logger, rng) { }
|
public Python(CoreContext db, ILogger<Python> logger, ThreadSafeRandom rng) : base(db, logger, rng) { }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -8,13 +8,13 @@ using System.Collections.Generic;
|
|||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary.Data
|
namespace Kruzya.TelegramBot.RichSiteSummary.Data;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a feed in database.
|
||||||
|
/// </summary>
|
||||||
|
public class Feed : RepresentableEntity
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Represents a feed in database.
|
|
||||||
/// </summary>
|
|
||||||
public class Feed : RepresentableEntity
|
|
||||||
{
|
|
||||||
#region RepresentableEntity
|
#region RepresentableEntity
|
||||||
protected override string ViewableText
|
protected override string ViewableText
|
||||||
{
|
{
|
||||||
@@ -86,5 +86,4 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Data
|
|||||||
public virtual ICollection<Subscriber> Subscribers { get; set; }
|
public virtual ICollection<Subscriber> Subscribers { get; set; }
|
||||||
|
|
||||||
public override string ToString() => Title;
|
public override string ToString() => Title;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -9,13 +9,13 @@ using System.Text;
|
|||||||
using Kruzya.TelegramBot.RichSiteSummary.UrchinTrackingModule;
|
using Kruzya.TelegramBot.RichSiteSummary.UrchinTrackingModule;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary.Data
|
namespace Kruzya.TelegramBot.RichSiteSummary.Data;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a post from feed in database.
|
||||||
|
/// </summary>
|
||||||
|
public class Post : RepresentableEntity
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Represents a post from feed in database.
|
|
||||||
/// </summary>
|
|
||||||
public class Post : RepresentableEntity
|
|
||||||
{
|
|
||||||
#region RepresentableEntity
|
#region RepresentableEntity
|
||||||
protected override ParseMode DefaultRepresentation
|
protected override ParseMode DefaultRepresentation
|
||||||
{
|
{
|
||||||
@@ -103,5 +103,4 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Data
|
|||||||
return message.ToString();
|
return message.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -7,13 +7,13 @@ using System;
|
|||||||
using System.Web;
|
using System.Web;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary.Data
|
namespace Kruzya.TelegramBot.RichSiteSummary.Data;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Implements the basic logic for rendering Database Entities in messages.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class RepresentableEntity
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Implements the basic logic for rendering Database Entities in messages.
|
|
||||||
/// </summary>
|
|
||||||
public abstract class RepresentableEntity
|
|
||||||
{
|
|
||||||
protected virtual string ViewableText { get; }
|
protected virtual string ViewableText { get; }
|
||||||
protected virtual string ViewableUrl { get; }
|
protected virtual string ViewableUrl { get; }
|
||||||
protected virtual ParseMode DefaultRepresentation { get; }
|
protected virtual ParseMode DefaultRepresentation { get; }
|
||||||
@@ -57,5 +57,4 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Data
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
using Kruzya.TelegramBot.Core.EF;
|
using Kruzya.TelegramBot.Core.EF;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary.Data
|
namespace Kruzya.TelegramBot.RichSiteSummary.Data;
|
||||||
|
|
||||||
|
public class RichSiteSummaryContext : AutoSaveDbContext
|
||||||
{
|
{
|
||||||
public class RichSiteSummaryContext : AutoSaveDbContext
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Repository with all feeds in database.
|
/// Repository with all feeds in database.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -54,5 +54,4 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Data
|
|||||||
.WithMany(f => f.Subscribers)
|
.WithMany(f => f.Subscribers)
|
||||||
.HasForeignKey(s => s.FeedId);
|
.HasForeignKey(s => s.FeedId);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,13 +6,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary.Data
|
namespace Kruzya.TelegramBot.RichSiteSummary.Data;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a subscription in database.
|
||||||
|
/// </summary>
|
||||||
|
public class Subscriber
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Represents a subscription in database.
|
|
||||||
/// </summary>
|
|
||||||
public class Subscriber
|
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The unique Subscription identifier.
|
/// The unique Subscription identifier.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -52,5 +52,4 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Data
|
|||||||
{
|
{
|
||||||
Feed = feed;
|
Feed = feed;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,14 @@
|
|||||||
using BotFramework;
|
using BotFramework;
|
||||||
using Kruzya.TelegramBot.RichSiteSummary.Data;
|
using Kruzya.TelegramBot.RichSiteSummary.Data;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary.Handler
|
namespace Kruzya.TelegramBot.RichSiteSummary.Handler;
|
||||||
|
|
||||||
|
public abstract class AbstractHandler : BotEventHandler
|
||||||
{
|
{
|
||||||
public abstract class AbstractHandler : BotEventHandler
|
|
||||||
{
|
|
||||||
protected readonly RichSiteSummaryContext _dbContext;
|
protected readonly RichSiteSummaryContext _dbContext;
|
||||||
|
|
||||||
protected AbstractHandler(RichSiteSummaryContext dbContext)
|
protected AbstractHandler(RichSiteSummaryContext dbContext)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -13,10 +13,10 @@ using Telegram.Bot.Types;
|
|||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
using Telegram.Bot.Types.ReplyMarkups;
|
using Telegram.Bot.Types.ReplyMarkups;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary.Handler
|
namespace Kruzya.TelegramBot.RichSiteSummary.Handler;
|
||||||
|
|
||||||
|
public class FeedList : AbstractHandler
|
||||||
{
|
{
|
||||||
public class FeedList : AbstractHandler
|
|
||||||
{
|
|
||||||
public FeedList(RichSiteSummaryContext dbContext) : base(dbContext)
|
public FeedList(RichSiteSummaryContext dbContext) : base(dbContext)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -307,5 +307,4 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Handler
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -7,10 +7,10 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary.Handler
|
namespace Kruzya.TelegramBot.RichSiteSummary.Handler;
|
||||||
|
|
||||||
|
public class StatsHandler : AbstractHandler
|
||||||
{
|
{
|
||||||
public class StatsHandler : AbstractHandler
|
|
||||||
{
|
|
||||||
public StatsHandler(RichSiteSummaryContext dbContext) : base(dbContext)
|
public StatsHandler(RichSiteSummaryContext dbContext) : base(dbContext)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -33,5 +33,4 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Handler
|
|||||||
|
|
||||||
await Bot.SendTextMessageAsync(Chat, textMessage.ToString(), parseMode: ParseMode.Html);
|
await Bot.SendTextMessageAsync(Chat, textMessage.ToString(), parseMode: ParseMode.Html);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -7,10 +7,10 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary
|
namespace Kruzya.TelegramBot.RichSiteSummary;
|
||||||
|
|
||||||
|
public class RichSiteSummary : Module
|
||||||
{
|
{
|
||||||
public class RichSiteSummary : Module
|
|
||||||
{
|
|
||||||
public RichSiteSummary(Core.Core core) : base(core)
|
public RichSiteSummary(Core.Core core) : base(core)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -33,5 +33,4 @@ namespace Kruzya.TelegramBot.RichSiteSummary
|
|||||||
.AddHostedService<Unsubscriber>()
|
.AddHostedService<Unsubscriber>()
|
||||||
.AddHostedService<MessageSender>();
|
.AddHostedService<MessageSender>();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,10 @@ using Kruzya.TelegramBot.RichSiteSummary.Data;
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary
|
namespace Kruzya.TelegramBot.RichSiteSummary;
|
||||||
|
|
||||||
|
internal static class RichSiteSummaryRepositoryExtension
|
||||||
{
|
{
|
||||||
internal static class RichSiteSummaryRepositoryExtension
|
|
||||||
{
|
|
||||||
#region Subscriber
|
#region Subscriber
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -68,5 +68,4 @@ namespace Kruzya.TelegramBot.RichSiteSummary
|
|||||||
await repository.FirstOrDefaultAsync(post => post.Url == url && (feed == null || post.Feed == feed));
|
await repository.FirstOrDefaultAsync(post => post.Url == url && (feed == null || post.Feed == feed));
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -9,10 +9,10 @@ using Telegram.Bot;
|
|||||||
using Telegram.Bot.Exceptions;
|
using Telegram.Bot.Exceptions;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary.Service
|
namespace Kruzya.TelegramBot.RichSiteSummary.Service;
|
||||||
|
|
||||||
|
public class MessageSender : AbstractTimedHostedService
|
||||||
{
|
{
|
||||||
public class MessageSender : AbstractTimedHostedService
|
|
||||||
{
|
|
||||||
protected override TimeSpan TimerPeriod => TimeSpan.FromSeconds(1);
|
protected override TimeSpan TimerPeriod => TimeSpan.FromSeconds(1);
|
||||||
|
|
||||||
protected readonly ConcurrentQueue<UserMessage> Queue;
|
protected readonly ConcurrentQueue<UserMessage> Queue;
|
||||||
@@ -85,5 +85,4 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Service
|
|||||||
|
|
||||||
Queue.Enqueue(message);
|
Queue.Enqueue(message);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -20,16 +20,16 @@ using Feed = Kruzya.TelegramBot.RichSiteSummary.Data.Feed;
|
|||||||
|
|
||||||
using CodeHollow.FeedReader.Feeds;
|
using CodeHollow.FeedReader.Feeds;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary.Service
|
namespace Kruzya.TelegramBot.RichSiteSummary.Service;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Performs a RSS feed parsing.
|
||||||
|
/// Grabs the all feeds from database.
|
||||||
|
///
|
||||||
|
/// TODO: move entity grabbing to another service.
|
||||||
|
/// </summary>
|
||||||
|
public class RssFetch : IHostedService, IDisposable
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Performs a RSS feed parsing.
|
|
||||||
/// Grabs the all feeds from database.
|
|
||||||
///
|
|
||||||
/// TODO: move entity grabbing to another service.
|
|
||||||
/// </summary>
|
|
||||||
public class RssFetch : IHostedService, IDisposable
|
|
||||||
{
|
|
||||||
private Timer _timer;
|
private Timer _timer;
|
||||||
|
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
@@ -257,5 +257,4 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Service
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -9,10 +9,10 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary.Service
|
namespace Kruzya.TelegramBot.RichSiteSummary.Service;
|
||||||
|
|
||||||
|
public class Unsubscriber : AbstractTimedHostedService
|
||||||
{
|
{
|
||||||
public class Unsubscriber : AbstractTimedHostedService
|
|
||||||
{
|
|
||||||
protected readonly ConcurrentQueue<UserUnsubscribe> Queue;
|
protected readonly ConcurrentQueue<UserUnsubscribe> Queue;
|
||||||
protected readonly IServiceScopeFactory ScopeFactory;
|
protected readonly IServiceScopeFactory ScopeFactory;
|
||||||
|
|
||||||
@@ -45,5 +45,4 @@ namespace Kruzya.TelegramBot.RichSiteSummary.Service
|
|||||||
);
|
);
|
||||||
await dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
namespace Kruzya.TelegramBot.RichSiteSummary.UrchinTrackingModule
|
namespace Kruzya.TelegramBot.RichSiteSummary.UrchinTrackingModule;
|
||||||
|
|
||||||
|
public struct UtmParameters
|
||||||
{
|
{
|
||||||
public struct UtmParameters
|
|
||||||
{
|
|
||||||
public string Source;
|
public string Source;
|
||||||
public string Type;
|
public string Type;
|
||||||
public string Campaign;
|
public string Campaign;
|
||||||
public string Term;
|
public string Term;
|
||||||
public string Content;
|
public string Content;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,10 +3,10 @@ using System.Collections.Generic;
|
|||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary.UrchinTrackingModule
|
namespace Kruzya.TelegramBot.RichSiteSummary.UrchinTrackingModule;
|
||||||
|
|
||||||
|
public class UtmUtility
|
||||||
{
|
{
|
||||||
public class UtmUtility
|
|
||||||
{
|
|
||||||
public static string ApplyParameters(string url, UtmParameters parameters)
|
public static string ApplyParameters(string url, UtmParameters parameters)
|
||||||
=> ApplyParameters(new Uri(url), parameters);
|
=> ApplyParameters(new Uri(url), parameters);
|
||||||
|
|
||||||
@@ -47,5 +47,4 @@ namespace Kruzya.TelegramBot.RichSiteSummary.UrchinTrackingModule
|
|||||||
|
|
||||||
queryParameteters.Set(key, value);
|
queryParameteters.Set(key, value);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary
|
namespace Kruzya.TelegramBot.RichSiteSummary;
|
||||||
|
|
||||||
|
public struct UserMessage
|
||||||
{
|
{
|
||||||
public struct UserMessage
|
|
||||||
{
|
|
||||||
public ChatId ChatId;
|
public ChatId ChatId;
|
||||||
public string Text;
|
public string Text;
|
||||||
public ParseMode ParseMode;
|
public ParseMode ParseMode;
|
||||||
public bool DisableWebPagePreview;
|
public bool DisableWebPagePreview;
|
||||||
public string ImageUrl;
|
public string ImageUrl;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.RichSiteSummary
|
namespace Kruzya.TelegramBot.RichSiteSummary;
|
||||||
|
|
||||||
|
public struct UserUnsubscribe
|
||||||
{
|
{
|
||||||
public struct UserUnsubscribe
|
|
||||||
{
|
|
||||||
public ChatId ChatId;
|
public ChatId ChatId;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,10 @@ using Telegram.Bot;
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.UrlLimitations
|
namespace Kruzya.TelegramBot.UrlLimitations;
|
||||||
|
|
||||||
|
public static class MessageExtension
|
||||||
{
|
{
|
||||||
public static class MessageExtension
|
|
||||||
{
|
|
||||||
public static async Task<bool> HasUnknownMention(this Message message, ITelegramBotClient bot)
|
public static async Task<bool> HasUnknownMention(this Message message, ITelegramBotClient bot)
|
||||||
{
|
{
|
||||||
foreach (var mention in message.Entities.Where(e =>
|
foreach (var mention in message.Entities.Where(e =>
|
||||||
@@ -59,5 +59,4 @@ namespace Kruzya.TelegramBot.UrlLimitations
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -11,10 +11,10 @@ using Telegram.Bot;
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.UrlLimitations
|
namespace Kruzya.TelegramBot.UrlLimitations;
|
||||||
|
|
||||||
|
public class MessageHandler : BotEventHandler
|
||||||
{
|
{
|
||||||
public class MessageHandler : BotEventHandler
|
|
||||||
{
|
|
||||||
protected ILogger Logger;
|
protected ILogger Logger;
|
||||||
protected readonly CoreContext dbCtx;
|
protected readonly CoreContext dbCtx;
|
||||||
|
|
||||||
@@ -55,5 +55,4 @@ namespace Kruzya.TelegramBot.UrlLimitations
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
using Kruzya.TelegramBot.Core;
|
using Kruzya.TelegramBot.Core;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.UrlLimitations
|
namespace Kruzya.TelegramBot.UrlLimitations;
|
||||||
|
|
||||||
|
public class UrlLimitations : Module
|
||||||
{
|
{
|
||||||
public class UrlLimitations : Module
|
|
||||||
{
|
|
||||||
public UrlLimitations(Core.Core core) : base(core)
|
public UrlLimitations(Core.Core core) : base(core)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,10 +6,10 @@ using BotFramework.Enums;
|
|||||||
using Kruzya.TelegramBot.Core.Data;
|
using Kruzya.TelegramBot.Core.Data;
|
||||||
using Kruzya.TelegramBot.Core.Extensions;
|
using Kruzya.TelegramBot.Core.Extensions;
|
||||||
|
|
||||||
namespace Kruzya.TelegramBot.UrlLimitations
|
namespace Kruzya.TelegramBot.UrlLimitations;
|
||||||
|
|
||||||
|
public class UserJoinHandler : BotEventHandler
|
||||||
{
|
{
|
||||||
public class UserJoinHandler : BotEventHandler
|
|
||||||
{
|
|
||||||
protected readonly CoreContext dbCtx;
|
protected readonly CoreContext dbCtx;
|
||||||
|
|
||||||
public UserJoinHandler(CoreContext coreContext)
|
public UserJoinHandler(CoreContext coreContext)
|
||||||
@@ -25,5 +25,4 @@ namespace Kruzya.TelegramBot.UrlLimitations
|
|||||||
await dbCtx.UserValues.SetOptionValue<UInt16>(Chat.Id, member.Id, "urlLimitations.messagesAfterJoin",
|
await dbCtx.UserValues.SetOptionValue<UInt16>(Chat.Id, member.Id, "urlLimitations.messagesAfterJoin",
|
||||||
0);
|
0);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -14,10 +14,10 @@ using Telegram.Bot;
|
|||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
using Telegram.Bot.Types.Enums;
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace UserGroupTag
|
namespace UserGroupTag;
|
||||||
|
|
||||||
|
public class Handler : BotEventHandler
|
||||||
{
|
{
|
||||||
public class Handler : BotEventHandler
|
|
||||||
{
|
|
||||||
private readonly CoreContext _db;
|
private readonly CoreContext _db;
|
||||||
private readonly ICacheStorage<long, User> _userCache;
|
private readonly ICacheStorage<long, User> _userCache;
|
||||||
|
|
||||||
@@ -103,5 +103,4 @@ namespace UserGroupTag
|
|||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
using Kruzya.TelegramBot.Core;
|
using Kruzya.TelegramBot.Core;
|
||||||
|
|
||||||
namespace UserGroupTag
|
namespace UserGroupTag;
|
||||||
|
|
||||||
|
public class UserGroupTag : Module
|
||||||
{
|
{
|
||||||
public class UserGroupTag : Module
|
|
||||||
{
|
|
||||||
public UserGroupTag(Core core) : base(core) { }
|
public UserGroupTag(Core core) : base(core) { }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user