mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[store] refactor, add new purchasables
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
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;
|
||||
}
|
||||
|
||||
[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")}");
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ using Kruzya.TelegramBot.Core.Service;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
using Telegram.Bot.Types.InputFiles;
|
||||
using Telegram.Bot.Types.ReplyMarkups;
|
||||
using West.TelegramBot.ContentStore.Service;
|
||||
|
||||
@@ -47,11 +46,14 @@ public class Store : BotEventHandler
|
||||
await Bot.SendTextMessageAsync(Chat.Id, $"<b>{user.ToHtml()} ({reputation})</b>, чего пожелаете?", ParseMode.Html,
|
||||
replyMarkup: new InlineKeyboardMarkup(
|
||||
_provider.GetServices<IRandomMediaService>()
|
||||
.OrderBy(x => x.StoreItem.Order)
|
||||
.Select(x => x.StoreItem.ToButton(From.Id))
|
||||
.Chunk(2)
|
||||
.ToList()
|
||||
)
|
||||
.ToAsyncEnumerable()
|
||||
.WhereAwait(async x => await x.CanView(Chat, user))
|
||||
.OrderBy(x => x.StoreItem.Order)
|
||||
.Select(x => x.StoreItem.ToButton(From.Id))
|
||||
.ToEnumerable()
|
||||
.Chunk(2)
|
||||
.ToList()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -110,14 +112,14 @@ public class Store : BotEventHandler
|
||||
ParseMode.Html);
|
||||
|
||||
var randomMedia = await mediaService!.GetRandomMediaAsync();
|
||||
var file = new InputOnlineFile(randomMedia.Url);
|
||||
var file = randomMedia.File;
|
||||
switch (randomMedia.Type)
|
||||
{
|
||||
case InputMediaType.Photo:
|
||||
await Bot.SendPhotoAsync(Chat.Id, file, randomMedia.Caption, replyToMessageId: messageId);
|
||||
await Bot.SendPhotoAsync(Chat.Id, file, randomMedia.Caption, replyToMessageId: messageId, parseMode: ParseMode.Html);
|
||||
break;
|
||||
case InputMediaType.Video:
|
||||
await Bot.SendVideoAsync(Chat.Id, file, caption: randomMedia.Caption, replyToMessageId: messageId);
|
||||
await Bot.SendVideoAsync(Chat.Id, file, caption: randomMedia.Caption, replyToMessageId: messageId, parseMode: ParseMode.Html);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user