mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
|
|
#nullable enable
|
||
|
|
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using BotFramework.Attributes;
|
||
|
|
using BotFramework.Enums;
|
||
|
|
using Castle.Core.Internal;
|
||
|
|
using Kruzya.TelegramBot.Core.Data;
|
||
|
|
using Kruzya.TelegramBot.Core.Extensions;
|
||
|
|
using Telegram.Bot;
|
||
|
|
|
||
|
|
namespace West.TelegramBot.ChatManagement.Handler.Fun
|
||
|
|
{
|
||
|
|
public class Python : ManagementHandler
|
||
|
|
{
|
||
|
|
[Command(InChat.Public, "setpython", CommandParseMode.Both)]
|
||
|
|
public async Task HandleSetpython()
|
||
|
|
{
|
||
|
|
var animation = Message?.ReplyToMessage?.Animation;
|
||
|
|
if (await CanPunish() || animation == null) return;
|
||
|
|
|
||
|
|
var pythonFile = await GetPythonFileOption();
|
||
|
|
pythonFile.SetValue(animation.FileId);
|
||
|
|
Db.MarkAsModified(pythonFile);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Message(InChat.Public, "(?i)питон|пайтон|python|путхон", MessageFlag.HasText, true)]
|
||
|
|
public async Task HandlePython()
|
||
|
|
{
|
||
|
|
var pythonFileId = (await GetPythonFileOption()).GetValue(string.Empty);
|
||
|
|
if (pythonFileId.IsNullOrEmpty()) return;
|
||
|
|
|
||
|
|
await Bot.SendAnimationAsync(Chat.Id, pythonFileId, replyToMessageId: Message?.MessageId);
|
||
|
|
}
|
||
|
|
|
||
|
|
private async Task<BotUserValue> GetPythonFileOption()
|
||
|
|
{
|
||
|
|
return await Db.UserValues.FindOrCreateOption(Chat.Id, "pythonFile");
|
||
|
|
}
|
||
|
|
|
||
|
|
public Python(CoreContext db) : base(db) { }
|
||
|
|
}
|
||
|
|
}
|