mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
initial chat options implementation
This commit is contained in:
@@ -3,7 +3,9 @@ global using GuessCache = Kruzya.TelegramBot.Core.Cache.MemoryCache<Telegram.Bot
|
||||
|
||||
|
||||
using Kruzya.TelegramBot.Core;
|
||||
using Kruzya.TelegramBot.Core.Options;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using West.Entertainment.Options;
|
||||
|
||||
|
||||
namespace West.Entertainment
|
||||
@@ -15,6 +17,7 @@ namespace West.Entertainment
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IGuessCache, GuessCache>();
|
||||
services.AddScoped<NsfwOption>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,20 +12,23 @@ using Kruzya.TelegramBot.Core.Service;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
using West.Entertainment.Options;
|
||||
|
||||
namespace West.Entertainment.Handler
|
||||
{
|
||||
public class Common : BotEventHandler
|
||||
{
|
||||
private readonly UserService _userService;
|
||||
private readonly NsfwOption _nsfwOption;
|
||||
private readonly ILogger _logger;
|
||||
private readonly CoreContext _db;
|
||||
|
||||
public Common(CoreContext db, ILogger<Common> logger, UserService userService)
|
||||
public Common(CoreContext db, ILogger<Common> logger, UserService userService, NsfwOption nsfwOption)
|
||||
{
|
||||
_db = db;
|
||||
_logger = logger;
|
||||
_userService = userService;
|
||||
_nsfwOption = nsfwOption;
|
||||
}
|
||||
|
||||
[Command(InChat.Public, "cooldowns", CommandParseMode.Both)]
|
||||
@@ -59,5 +62,20 @@ namespace West.Entertainment.Handler
|
||||
|
||||
await Bot.SendTextMessageAsync(Chat.Id, msg.ToString(), parseMode: ParseMode.Html);
|
||||
}
|
||||
|
||||
[Command("test_option_get")]
|
||||
public async Task HandleTestOptionGet()
|
||||
{
|
||||
await Bot.SendTextMessageAsync(Chat.Id, $"nsfw option is: {await _nsfwOption.GetValueAsync(Chat.Id)}");
|
||||
}
|
||||
|
||||
[Command("test_option_set")]
|
||||
public async Task HandleTestOptionSet()
|
||||
{
|
||||
var value = await _nsfwOption.GetValueAsync(Chat.Id);
|
||||
await _nsfwOption.SetValueAsync(Chat.Id, !value);
|
||||
|
||||
await Bot.SendTextMessageAsync(Chat.Id, $"nsfw option is: {await _nsfwOption.GetValueAsync(Chat.Id)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using Kruzya.TelegramBot.Core.Options;
|
||||
|
||||
namespace West.Entertainment.Options;
|
||||
|
||||
[Option("allowNSFW", false)]
|
||||
public class NsfwOption : AbstractOption<NsfwOption, bool>
|
||||
{
|
||||
public NsfwOption(IOptionProvider optionProvider) : base(optionProvider)
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user