diff --git a/Core/Core.csproj b/Core/Core.csproj
index c0c40b9..11d7178 100644
--- a/Core/Core.csproj
+++ b/Core/Core.csproj
@@ -8,7 +8,7 @@
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/modules/ChatManagement/Extensions/BotExtension.cs b/Core/Extensions/BotExtension.cs
similarity index 94%
rename from modules/ChatManagement/Extensions/BotExtension.cs
rename to Core/Extensions/BotExtension.cs
index 3203be8..a36761f 100644
--- a/modules/ChatManagement/Extensions/BotExtension.cs
+++ b/Core/Extensions/BotExtension.cs
@@ -2,7 +2,7 @@
using Telegram.Bot;
using Telegram.Bot.Types;
-namespace West.TelegramBot.ChatManagement.Extensions
+namespace Kruzya.TelegramBot.Core.Extensions
{
public static class BotExtension
{
diff --git a/modules/ChatManagement/Handler/ManagementHandler.cs b/modules/ChatManagement/Handler/ManagementHandler.cs
index dc39147..1fb3be6 100644
--- a/modules/ChatManagement/Handler/ManagementHandler.cs
+++ b/modules/ChatManagement/Handler/ManagementHandler.cs
@@ -8,7 +8,6 @@ using Kruzya.TelegramBot.Core.Extensions;
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
-using West.TelegramBot.ChatManagement.Extensions;
namespace West.TelegramBot.ChatManagement.Handler
{
diff --git a/modules/Entertainment/Entertainment.cs b/modules/Entertainment/Entertainment.cs
index 3da7aad..a0134a1 100644
--- a/modules/Entertainment/Entertainment.cs
+++ b/modules/Entertainment/Entertainment.cs
@@ -1,13 +1,9 @@
using Kruzya.TelegramBot.Core;
-using West.TelegramBot.ChatManagement;
namespace West.Entertainment
{
public class Entertainment : Module
{
- public Entertainment(Core core) : base(core)
- {
- // core.EnsureLoaded();
- }
+ public Entertainment(Core core) : base(core) { }
}
}
\ No newline at end of file
diff --git a/modules/Entertainment/Entertainment.csproj b/modules/Entertainment/Entertainment.csproj
index 18890b1..b24581b 100644
--- a/modules/Entertainment/Entertainment.csproj
+++ b/modules/Entertainment/Entertainment.csproj
@@ -8,7 +8,6 @@
-
diff --git a/modules/Entertainment/Handler/Fun/AbstractAnimationReply.cs b/modules/Entertainment/Handler/Fun/AbstractAnimationReply.cs
index 45edef0..8faf151 100644
--- a/modules/Entertainment/Handler/Fun/AbstractAnimationReply.cs
+++ b/modules/Entertainment/Handler/Fun/AbstractAnimationReply.cs
@@ -2,23 +2,33 @@
using System.Text.RegularExpressions;
using System.Threading.Tasks;
-using BotFramework.Attributes;
-using BotFramework.Enums;
+using BotFramework;
using Castle.Core.Internal;
using Kruzya.TelegramBot.Core.Data;
using Kruzya.TelegramBot.Core.Extensions;
using Telegram.Bot;
-using West.TelegramBot.ChatManagement.Handler;
+using Telegram.Bot.Types;
namespace West.Entertainment.Handler.Fun
{
- public abstract class AbstractAnimationReply : ManagementHandler
+ public abstract class AbstractAnimationReply : BotEventHandler
{
+ private readonly CoreContext _db;
+
+ protected Message? Message => RawUpdate.Message;
+
+ private User? RepliedUser => Message?.ReplyToMessage?.From;
+
protected abstract Regex AnimationMatch
{
get;
}
+ protected AbstractAnimationReply(CoreContext db)
+ {
+ _db = db;
+ }
+
protected abstract string GetAnimationName();
protected virtual bool CanHandle() => true;
@@ -30,26 +40,31 @@ namespace West.Entertainment.Handler.Fun
var animationFileOption = await GetAnimationFileOption();
animationFileOption.SetValue(animation.FileId);
- Db.MarkAsModified(animationFileOption);
+ _db.MarkAsModified(animationFileOption);
}
- [Message(InChat.Public, MessageFlag.HasText)]
- protected virtual async Task HandleAnimation(int? replyToMessageId = null)
+ // ReSharper disable once MemberCanBeProtected.Global
+ public virtual async Task HandleAnimation()
{
var animationFileId = (await GetAnimationFileOption()).GetValue(string.Empty);
if (animationFileId.IsNullOrEmpty() || !AnimationMatch.IsMatch(Message!.Text!) || !CanHandle()) return false;
await Bot.SendAnimationAsync(Chat.Id, animationFileId,
- replyToMessageId: replyToMessageId ?? Message?.MessageId);
+ replyToMessageId: GetMessageIdToReply() ?? Message?.MessageId);
return true;
}
private async Task GetAnimationFileOption()
{
- return await Db.UserValues.FindOrCreateOption(Chat.Id, $"{GetAnimationName()}File");
+ return await _db.UserValues.FindOrCreateOption(Chat.Id, $"{GetAnimationName()}File");
}
- protected AbstractAnimationReply(CoreContext db) : base(db) {}
+ private async Task CanPunish()
+ {
+ return RepliedUser != null && await Bot.CanPunishMember(Chat, From, RepliedUser);
+ }
+
+ protected virtual int? GetMessageIdToReply() => Message?.MessageId;
}
}
\ No newline at end of file
diff --git a/modules/Entertainment/Handler/Fun/Bayan.cs b/modules/Entertainment/Handler/Fun/Bayan.cs
index 8635329..b39d3eb 100644
--- a/modules/Entertainment/Handler/Fun/Bayan.cs
+++ b/modules/Entertainment/Handler/Fun/Bayan.cs
@@ -13,25 +13,34 @@ namespace West.Entertainment.Handler.Fun
{
public Bayan(CoreContext db) : base(db) { }
- protected override Regex AnimationMatch => new("^баян$", RegexOptions.IgnoreCase);
+ protected override Regex AnimationMatch
+ => new("^баян$", RegexOptions.IgnoreCase);
- protected override string GetAnimationName() => "bayan";
-
+ protected override string GetAnimationName()
+ => "bayan";
[Command(InChat.Public, "setbayan", CommandParseMode.Both)]
- public async Task HandleSetBayan() => await HandleSetAnimation();
+ public async Task HandleSetBayan()
+ => await HandleSetAnimation();
- protected override async Task HandleAnimation(int? replyToMessageId = null)
+ [Message(InChat.Public, MessageFlag.HasText)]
+ public override async Task HandleAnimation()
{
- if (await base.HandleAnimation(replyToMessageId))
+ if (await base.HandleAnimation())
{
await Bot.DeleteMessageAsync(Chat.Id, Message!.MessageId);
}
-
+
return true;
}
- protected override bool CanHandle() => Message?.ReplyToMessage != null;
+ protected override int? GetMessageIdToReply()
+ {
+ return Message!.ReplyToMessage!.MessageId;
+ }
+
+ protected override bool CanHandle()
+ => Message?.ReplyToMessage != null;
}
}
\ No newline at end of file
diff --git a/modules/Entertainment/Handler/Fun/Python.cs b/modules/Entertainment/Handler/Fun/Python.cs
index 73e7aa0..831d111 100644
--- a/modules/Entertainment/Handler/Fun/Python.cs
+++ b/modules/Entertainment/Handler/Fun/Python.cs
@@ -13,13 +13,21 @@ namespace West.Entertainment.Handler.Fun
protected override Regex AnimationMatch =>
new("питон|пайтон|python|путхон|питухон|петухон", RegexOptions.IgnoreCase);
- protected override string GetAnimationName() => "python";
+ protected override string GetAnimationName()
+ => "python";
- protected override bool CanHandle() => !Message!.Text!.Contains("/setpython");
+ protected override bool CanHandle()
+ => !Message!.Text!.Contains("/setpython");
[Command(InChat.Public, "setpython", CommandParseMode.Both)]
- public async Task HandleSetPython() => await HandleSetAnimation();
-
+ public async Task HandleSetPython()
+ => await HandleSetAnimation();
+
+ [Message(InChat.Public, MessageFlag.HasText)]
+ public override async Task HandleAnimation()
+ => await base.HandleAnimation();
+
+
public Python(CoreContext db) : base(db) { }
}
}
\ No newline at end of file