2022-11-14 00:23:36 +02:00
|
|
|
using BotFramework;
|
|
|
|
|
using BotFramework.Attributes;
|
|
|
|
|
using BotFramework.Enums;
|
|
|
|
|
using Kruzya.TelegramBot.Core.Data;
|
|
|
|
|
using Kruzya.TelegramBot.Core.Extensions;
|
|
|
|
|
using Telegram.Bot;
|
|
|
|
|
using Telegram.Bot.Types;
|
|
|
|
|
|
|
|
|
|
namespace West.TelegramBot.ContentStore.Handler;
|
|
|
|
|
|
|
|
|
|
public class NSFW : BotEventHandler
|
|
|
|
|
{
|
|
|
|
|
private readonly CoreContext _db;
|
|
|
|
|
|
|
|
|
|
public NSFW(CoreContext db)
|
|
|
|
|
{
|
|
|
|
|
_db = db;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-29 01:50:28 +03:00
|
|
|
[InChat(InChat.Public)]
|
2022-11-14 00:23:36 +02:00
|
|
|
[Command("nsfw", CommandParseMode.Both)]
|
|
|
|
|
public async Task HandleNSFW()
|
|
|
|
|
{
|
|
|
|
|
var canUse = await Bot.GetChatMemberAsync(Chat.Id, From.Id) is ChatMemberAdministrator { CanDeleteMessages: true }
|
|
|
|
|
or ChatMemberOwner;
|
|
|
|
|
if (!canUse)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var option = await _db.UserValues.FindOrCreateOption(Chat.Id, "AllowNSFW");
|
|
|
|
|
var newValue = !option.GetValue<bool>();
|
|
|
|
|
option.SetValue(newValue);
|
|
|
|
|
await _db.SaveChangesAsync();
|
|
|
|
|
|
|
|
|
|
await Bot.SendTextMessageAsync(Chat.Id,$"NSFW {(newValue ? "enabled" : "disabled")}");
|
|
|
|
|
}
|
|
|
|
|
}
|