mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Scratch for running next callbacks in queue
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Data
|
||||
@@ -11,6 +12,18 @@ namespace Kruzya.TelegramBot.Core.Data
|
||||
|
||||
public DbSet<BotUserValue> UserValues { get; set; }
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
SaveChanges();
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public override ValueTask DisposeAsync()
|
||||
{
|
||||
SaveChanges();
|
||||
return base.DisposeAsync();
|
||||
}
|
||||
|
||||
public CoreContext(DbContextOptions<CoreContext> ctx) : base(ctx)
|
||||
{
|
||||
Database.Migrate();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Threading.Tasks;
|
||||
using Kruzya.TelegramBot.Core.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Extensions
|
||||
{
|
||||
@@ -48,6 +49,23 @@ namespace Kruzya.TelegramBot.Core.Extensions
|
||||
|
||||
#region Core-context repository extensions
|
||||
|
||||
#region BotUser
|
||||
|
||||
public static async Task<BotUser> FindOrCreate(this DbSet<BotUser> repository, long chatId, int userId)
|
||||
{
|
||||
var user = await repository.SingleOrDefaultAsync(e => e.ChatId == chatId && e.UserId == userId);
|
||||
if (user == null)
|
||||
{
|
||||
user = repository.Create();
|
||||
user.ChatId = chatId;
|
||||
user.UserId = userId;
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region BotUserValue
|
||||
|
||||
#region FindOption
|
||||
@@ -79,6 +97,7 @@ namespace Kruzya.TelegramBot.Core.Extensions
|
||||
if (opt == null)
|
||||
{
|
||||
opt = repository.Create();
|
||||
opt.BotUser = await repository.GetService<CoreContext>().Users.FindOrCreate(chatId, userId);
|
||||
}
|
||||
|
||||
return opt;
|
||||
|
||||
@@ -39,6 +39,8 @@ namespace Kruzya.TelegramBot.Core
|
||||
|
||||
await VerifyChatPair(message);
|
||||
}
|
||||
|
||||
throw new ArgumentException();
|
||||
}
|
||||
|
||||
public async Task VerifyChatPair(Message message)
|
||||
|
||||
Reference in New Issue
Block a user