From 467ccd4fdee8a59390df4231add65448a7779adc Mon Sep 17 00:00:00 2001 From: Andriy <30056636+West14@users.noreply.github.com> Date: Thu, 20 Jul 2023 21:22:35 +0300 Subject: [PATCH] [core] move core handlers into subfolder --- Core/{ => Handler}/CommonHandler.cs | 10 +++++----- Core/{ => Handler}/GeneralHandler.cs | 8 +++----- modules/ChatManagement/Handler/Ban.cs | 2 +- modules/ChatManagement/Handler/BanStickerSet.cs | 4 ++-- modules/ChatManagement/Handler/Rules.cs | 2 +- modules/ChatManagement/Handler/Warn.cs | 2 +- modules/ChatManagement/Handler/WhoIs.cs | 2 +- modules/Entertainment/Handler/Guess.cs | 1 + modules/Entertainment/Handler/Roll.cs | 1 + modules/Reputation/Handler/Reputation.cs | 2 +- 10 files changed, 17 insertions(+), 17 deletions(-) rename Core/{ => Handler}/CommonHandler.cs (95%) rename Core/{ => Handler}/GeneralHandler.cs (88%) diff --git a/Core/CommonHandler.cs b/Core/Handler/CommonHandler.cs similarity index 95% rename from Core/CommonHandler.cs rename to Core/Handler/CommonHandler.cs index 142c0bc..b6758e9 100644 --- a/Core/CommonHandler.cs +++ b/Core/Handler/CommonHandler.cs @@ -9,7 +9,7 @@ using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; -namespace Kruzya.TelegramBot.Core +namespace Kruzya.TelegramBot.Core.Handler { public abstract class CommonHandler : BotEventHandler { @@ -18,7 +18,7 @@ namespace Kruzya.TelegramBot.Core protected Message? Message => RawUpdate.Message; protected User? RepliedUser => Message?.ReplyToMessage?.From; - + protected CommonHandler(CoreContext db) { Db = db; @@ -34,8 +34,8 @@ namespace Kruzya.TelegramBot.Core { return RepliedUser != null && await Bot.CanPunishMember(Chat, From, RepliedUser); } - - + + protected async Task BanMember(long userId, DateTime banEnd) { await Bot.RestrictChatMemberAsync( @@ -48,7 +48,7 @@ namespace Kruzya.TelegramBot.Core banEnd ); } - + protected async Task GetWarnOption(User user) { return await Db.UserValues.FindOrCreateOption(Chat.Id, user.Id, "warnCount"); diff --git a/Core/GeneralHandler.cs b/Core/Handler/GeneralHandler.cs similarity index 88% rename from Core/GeneralHandler.cs rename to Core/Handler/GeneralHandler.cs index 9dc2227..15a76e0 100644 --- a/Core/GeneralHandler.cs +++ b/Core/Handler/GeneralHandler.cs @@ -1,14 +1,12 @@ using System; -using System.Linq; using System.Threading.Tasks; using BotFramework; using BotFramework.Attributes; using Kruzya.TelegramBot.Core.Data; -using Kruzya.TelegramBot.Core.Extensions; using Microsoft.EntityFrameworkCore; using Telegram.Bot.Types; -namespace Kruzya.TelegramBot.Core +namespace Kruzya.TelegramBot.Core.Handler { public class GeneralHandler : BotEventHandler { @@ -22,7 +20,7 @@ namespace Kruzya.TelegramBot.Core } protected readonly CoreContext databaseContext; - + public GeneralHandler(CoreContext dbCtx) { databaseContext = dbCtx; @@ -32,7 +30,7 @@ namespace Kruzya.TelegramBot.Core [Priority(short.MaxValue - 10)] public async Task Listener() { - foreach (var message in new Message[] {RawUpdate.Message, RawUpdate.EditedMessage, RawUpdate.ChannelPost, RawUpdate.EditedChannelPost}) + foreach (var message in new Message[] { RawUpdate.Message, RawUpdate.EditedMessage, RawUpdate.ChannelPost, RawUpdate.EditedChannelPost }) { if (message == null) { diff --git a/modules/ChatManagement/Handler/Ban.cs b/modules/ChatManagement/Handler/Ban.cs index 7067b30..927ab32 100644 --- a/modules/ChatManagement/Handler/Ban.cs +++ b/modules/ChatManagement/Handler/Ban.cs @@ -4,9 +4,9 @@ using System; using System.Threading.Tasks; using BotFramework.Attributes; using BotFramework.Enums; -using Kruzya.TelegramBot.Core; using Kruzya.TelegramBot.Core.Data; using Kruzya.TelegramBot.Core.Extensions; +using Kruzya.TelegramBot.Core.Handler; using Telegram.Bot; using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; diff --git a/modules/ChatManagement/Handler/BanStickerSet.cs b/modules/ChatManagement/Handler/BanStickerSet.cs index c179c1f..ad8b00d 100644 --- a/modules/ChatManagement/Handler/BanStickerSet.cs +++ b/modules/ChatManagement/Handler/BanStickerSet.cs @@ -1,5 +1,5 @@ -using Kruzya.TelegramBot.Core; -using Kruzya.TelegramBot.Core.Data; +using Kruzya.TelegramBot.Core.Data; +using Kruzya.TelegramBot.Core.Handler; namespace West.TelegramBot.ChatManagement.Handler; diff --git a/modules/ChatManagement/Handler/Rules.cs b/modules/ChatManagement/Handler/Rules.cs index a794e2d..1c73e14 100644 --- a/modules/ChatManagement/Handler/Rules.cs +++ b/modules/ChatManagement/Handler/Rules.cs @@ -1,9 +1,9 @@ using System.Threading.Tasks; using BotFramework.Attributes; using BotFramework.Enums; -using Kruzya.TelegramBot.Core; using Kruzya.TelegramBot.Core.Data; using Kruzya.TelegramBot.Core.Extensions; +using Kruzya.TelegramBot.Core.Handler; using Telegram.Bot; using Telegram.Bot.Exceptions; using West.TelegramBot.ChatManagement.Service; diff --git a/modules/ChatManagement/Handler/Warn.cs b/modules/ChatManagement/Handler/Warn.cs index b828052..d8694ab 100644 --- a/modules/ChatManagement/Handler/Warn.cs +++ b/modules/ChatManagement/Handler/Warn.cs @@ -3,8 +3,8 @@ using System.Threading.Tasks; using BotFramework.Attributes; using BotFramework.Enums; -using Kruzya.TelegramBot.Core; using Kruzya.TelegramBot.Core.Data; +using Kruzya.TelegramBot.Core.Handler; using West.TelegramBot.ChatManagement.Service; namespace West.TelegramBot.ChatManagement.Handler; diff --git a/modules/ChatManagement/Handler/WhoIs.cs b/modules/ChatManagement/Handler/WhoIs.cs index 2b38905..4ff9ba3 100644 --- a/modules/ChatManagement/Handler/WhoIs.cs +++ b/modules/ChatManagement/Handler/WhoIs.cs @@ -3,9 +3,9 @@ using System; using System.Threading.Tasks; using BotFramework.Attributes; using BotFramework.Enums; -using Kruzya.TelegramBot.Core; using Kruzya.TelegramBot.Core.Data; using Kruzya.TelegramBot.Core.Extensions; +using Kruzya.TelegramBot.Core.Handler; using Kruzya.TelegramBot.Core.Service; using Microsoft.Extensions.DependencyInjection; using Telegram.Bot; diff --git a/modules/Entertainment/Handler/Guess.cs b/modules/Entertainment/Handler/Guess.cs index c701460..15af1ce 100644 --- a/modules/Entertainment/Handler/Guess.cs +++ b/modules/Entertainment/Handler/Guess.cs @@ -9,6 +9,7 @@ using Kruzya.TelegramBot.Core; using Kruzya.TelegramBot.Core.AutoDelete; using Kruzya.TelegramBot.Core.Data; using Kruzya.TelegramBot.Core.Extensions; +using Kruzya.TelegramBot.Core.Handler; using Kruzya.TelegramBot.Core.Service; using Telegram.Bot; using Telegram.Bot.Types; diff --git a/modules/Entertainment/Handler/Roll.cs b/modules/Entertainment/Handler/Roll.cs index 2fef7f9..8b82025 100644 --- a/modules/Entertainment/Handler/Roll.cs +++ b/modules/Entertainment/Handler/Roll.cs @@ -15,6 +15,7 @@ using System.Collections.Concurrent; using Telegram.Bot.Types.Enums; using Telegram.Bot.Types; using Microsoft.AspNetCore.Components.Forms; +using Kruzya.TelegramBot.Core.Handler; namespace West.Entertainment.Handler; diff --git a/modules/Reputation/Handler/Reputation.cs b/modules/Reputation/Handler/Reputation.cs index a64bc3a..6adb558 100644 --- a/modules/Reputation/Handler/Reputation.cs +++ b/modules/Reputation/Handler/Reputation.cs @@ -3,9 +3,9 @@ using BotFramework.Attributes; using BotFramework.Enums; using BotFramework.Utils; -using Kruzya.TelegramBot.Core; using Kruzya.TelegramBot.Core.Data; using Kruzya.TelegramBot.Core.Extensions; +using Kruzya.TelegramBot.Core.Handler; using Kruzya.TelegramBot.Core.Service; using Microsoft.Extensions.Logging; using Telegram.Bot;