[core] Massive setting system update

- Get rid of attribute crap. Now only interface is required
- Rename canUse to isAdmin in `Bot.IsUserAdminAsync` to match the actual meaning of variable
- Made `AnswerQuery` reusable by moving it from ContentStore to Core's CommonHandler
- Chat Settings edit frontend (inline keyboard)
- Rename NsfwOption to AllowNsfw and move it to ContentStore module
- Remove option backend testing commands
- Add KarmaMode option as an example of Select option type
This commit is contained in:
Andriy
2023-07-21 17:14:11 +03:00
parent 467ccd4fde
commit 27ddfd39cc
21 changed files with 307 additions and 110 deletions
-2
View File
@@ -5,7 +5,6 @@ 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
@@ -17,7 +16,6 @@ namespace West.Entertainment
public override void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IGuessCache, GuessCache>();
services.AddScoped<NsfwOption>();
}
}
}
+1 -19
View File
@@ -12,23 +12,20 @@ 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, NsfwOption nsfwOption)
public Common(CoreContext db, ILogger<Common> logger, UserService userService)
{
_db = db;
_logger = logger;
_userService = userService;
_nsfwOption = nsfwOption;
}
[Command(InChat.Public, "cooldowns", CommandParseMode.Both)]
@@ -62,20 +59,5 @@ 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)}");
}
}
}
@@ -1,11 +0,0 @@
using Kruzya.TelegramBot.Core.Options;
namespace West.Entertainment.Options;
[Option("allowNSFW", false)]
public class NsfwOption : AbstractOption<NsfwOption, bool>
{
public NsfwOption(IOptionProvider optionProvider) : base(optionProvider)
{
}
}