mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Move fun commands to separate module.
This commit is contained in:
@@ -1,42 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Castle.Core.Internal;
|
||||
using Kruzya.TelegramBot.Core.Data;
|
||||
using Kruzya.TelegramBot.Core.Extensions;
|
||||
using Telegram.Bot;
|
||||
|
||||
namespace West.TelegramBot.ChatManagement.Handler.Fun
|
||||
{
|
||||
public abstract class AbstractAnimationReply : ManagementHandler
|
||||
{
|
||||
protected abstract string GetAnimationName();
|
||||
|
||||
protected async Task HandleSetAnimation()
|
||||
{
|
||||
var animation = Message?.ReplyToMessage?.Animation;
|
||||
if (await CanPunish() || animation == null) return;
|
||||
|
||||
var animationFileOption = await GetAnimationFileOption();
|
||||
animationFileOption.SetValue(animation.FileId);
|
||||
Db.MarkAsModified(animationFileOption);
|
||||
}
|
||||
|
||||
protected async Task<bool> HandleAnimation(int? replyToMessageId = null)
|
||||
{
|
||||
var anumationFileId = (await GetAnimationFileOption()).GetValue(string.Empty);
|
||||
if (anumationFileId.IsNullOrEmpty()) return false;
|
||||
|
||||
await Bot.SendAnimationAsync(Chat.Id, anumationFileId,
|
||||
replyToMessageId: replyToMessageId ?? Message?.MessageId);
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task<BotUserValue> GetAnimationFileOption()
|
||||
{
|
||||
return await Db.UserValues.FindOrCreateOption(Chat.Id, $"{GetAnimationName()}File");
|
||||
}
|
||||
|
||||
protected AbstractAnimationReply(CoreContext db) : base(db) {}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using BotFramework.Attributes;
|
||||
using BotFramework.Enums;
|
||||
using Kruzya.TelegramBot.Core.Data;
|
||||
using Telegram.Bot;
|
||||
|
||||
namespace West.TelegramBot.ChatManagement.Handler.Fun
|
||||
{
|
||||
public class Bayan : AbstractAnimationReply
|
||||
{
|
||||
public Bayan(CoreContext db) : base(db) { }
|
||||
|
||||
protected override string GetAnimationName()
|
||||
{
|
||||
return "bayan";
|
||||
}
|
||||
|
||||
[Command(InChat.Public, "setbayan", CommandParseMode.Both)]
|
||||
public async Task HandleSetBayan()
|
||||
{
|
||||
await HandleSetAnimation();
|
||||
}
|
||||
|
||||
[Message(InChat.Public, "(?i)баян|боян", MessageFlag.HasText | MessageFlag.IsReply, true)]
|
||||
public async Task HandleBayan()
|
||||
{
|
||||
var msg = Message;
|
||||
var replyMsg = msg?.ReplyToMessage!;
|
||||
if (msg == null || !await HandleAnimation(replyMsg.MessageId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await Bot.DeleteMessageAsync(Chat.Id, msg.MessageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using BotFramework.Attributes;
|
||||
using BotFramework.Enums;
|
||||
using Kruzya.TelegramBot.Core.Data;
|
||||
using Kruzya.TelegramBot.Core.Extensions;
|
||||
|
||||
namespace West.TelegramBot.ChatManagement.Handler.Fun
|
||||
{
|
||||
public class Python : AbstractAnimationReply
|
||||
{
|
||||
protected override string GetAnimationName()
|
||||
{
|
||||
return "python";
|
||||
}
|
||||
|
||||
[Command(InChat.Public, "setpython", CommandParseMode.Both)]
|
||||
public async Task HandleSetPython()
|
||||
{
|
||||
await HandleSetAnimation();
|
||||
}
|
||||
|
||||
[Message(InChat.Public, "(?i)питон|пайтон|python|путхон", MessageFlag.HasText, true)]
|
||||
public async Task HandlePython()
|
||||
{
|
||||
// var cmdEntity = Message?.Entities?.Find(e => e.Type == MessageEntityType.BotCommand);
|
||||
// if (cmdEntity is { Length: > 0 })
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (Message!.Text!.Contains("/setpython"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
await HandleAnimation();
|
||||
}
|
||||
|
||||
private async Task<BotUserValue> GetPythonFileOption()
|
||||
{
|
||||
return await Db.UserValues.FindOrCreateOption(Chat.Id, "pythonFile");
|
||||
}
|
||||
|
||||
public Python(CoreContext db) : base(db) { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user