mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[cm] greet new members & refactor rules
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#nullable enable
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Kruzya.TelegramBot.Core.Data;
|
||||
using Kruzya.TelegramBot.Core.Extensions;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace West.TelegramBot.ChatManagement.Service;
|
||||
|
||||
public class RulesService
|
||||
{
|
||||
private readonly CoreContext _db;
|
||||
|
||||
public RulesService(CoreContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public async Task<BotUserValue?> GetRulesOptionAsync(Chat chat)
|
||||
{
|
||||
return await _db.UserValues.FindOption(chat.Id, "rulesMsgId");
|
||||
}
|
||||
|
||||
public async Task<int?> GetRulesMessageIdAsync(Chat chat)
|
||||
{
|
||||
return (await GetRulesOptionAsync(chat))?.GetValue<int>();
|
||||
}
|
||||
|
||||
public async Task<bool> HasRulesAsync(Chat chat)
|
||||
{
|
||||
return await GetRulesMessageIdAsync(chat) != null;
|
||||
}
|
||||
|
||||
public async Task SetRulesAsync(Chat chat, int messageId)
|
||||
{
|
||||
var option = await GetRulesOptionAsync(chat) ?? _db.UserValues.Create();
|
||||
option.SetValue(messageId);
|
||||
_db.AddOrUpdate(option);
|
||||
}
|
||||
|
||||
public async Task RemoveChatRulesAsync(Chat chat)
|
||||
{
|
||||
var option = await GetRulesOptionAsync(chat);
|
||||
if (option == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_db.Remove(option);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user