mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
fixed build errors
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Discord.Net" Version="3.202.0" />
|
<PackageReference Include="Discord.Net" Version="3.203.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@@ -8,54 +8,6 @@ namespace NadekoBot.Db;
|
|||||||
|
|
||||||
public static class DiscordUserExtensions
|
public static class DiscordUserExtensions
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Adds the specified <paramref name="users"/> to the database. If a database user with placeholder name
|
|
||||||
/// and discriminator is present in <paramref name="users"/>, their name and discriminator get updated accordingly.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="ctx">This database context.</param>
|
|
||||||
/// <param name="users">The users to add or update in the database.</param>
|
|
||||||
/// <returns>A tuple with the amount of new users added and old users updated.</returns>
|
|
||||||
public static async Task<(long UsersAdded, long UsersUpdated)> RefreshUsersAsync(this NadekoContext ctx, List<IUser> users)
|
|
||||||
{
|
|
||||||
var presentDbUsers = await ctx.DiscordUser
|
|
||||||
.Select(x => new { x.UserId, x.Username, x.Discriminator })
|
|
||||||
.Where(x => users.Select(y => y.Id).Contains(x.UserId))
|
|
||||||
.ToArrayAsyncEF();
|
|
||||||
|
|
||||||
var usersToAdd = users
|
|
||||||
.Where(x => !presentDbUsers.Select(x => x.UserId).Contains(x.Id))
|
|
||||||
.Select(x => new DiscordUser()
|
|
||||||
{
|
|
||||||
UserId = x.Id,
|
|
||||||
AvatarId = x.AvatarId,
|
|
||||||
Username = x.Username,
|
|
||||||
Discriminator = x.Discriminator
|
|
||||||
});
|
|
||||||
|
|
||||||
var added = (await ctx.BulkCopyAsync(usersToAdd)).RowsCopied;
|
|
||||||
var toUpdateUserIds = presentDbUsers
|
|
||||||
.Where(x => x.Username == "Unknown" && x.Discriminator == "????")
|
|
||||||
.Select(x => x.UserId)
|
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
foreach (var user in users.Where(x => toUpdateUserIds.Contains(x.Id)))
|
|
||||||
{
|
|
||||||
await ctx.DiscordUser
|
|
||||||
.Where(x => x.UserId == user.Id)
|
|
||||||
.UpdateAsync(x => new DiscordUser()
|
|
||||||
{
|
|
||||||
Username = user.Username,
|
|
||||||
Discriminator = user.Discriminator,
|
|
||||||
|
|
||||||
// .award tends to set AvatarId and DateAdded to NULL, so account for that.
|
|
||||||
AvatarId = user.AvatarId,
|
|
||||||
DateAdded = x.DateAdded ?? DateTime.UtcNow
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return (added, toUpdateUserIds.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Task<DiscordUser> GetByUserIdAsync(
|
public static Task<DiscordUser> GetByUserIdAsync(
|
||||||
this IQueryable<DiscordUser> set,
|
this IQueryable<DiscordUser> set,
|
||||||
ulong userId)
|
ulong userId)
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Discord.Net" Version="3.202.0" />
|
<PackageReference Include="Discord.Net" Version="3.203.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@@ -60,7 +60,7 @@ public partial class Administration
|
|||||||
.Cast<IUser>()
|
.Cast<IUser>()
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var (added, updated) = await dbContext.RefreshUsersAsync(users);
|
var (added, updated) = await _service.RefreshUsersAsync(users);
|
||||||
|
|
||||||
await message.ModifyAsync(x =>
|
await message.ModifyAsync(x =>
|
||||||
x.Embed = _eb.Create()
|
x.Embed = _eb.Create()
|
||||||
|
@@ -3,6 +3,9 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using NadekoBot.Common.ModuleBehaviors;
|
using NadekoBot.Common.ModuleBehaviors;
|
||||||
using Nadeko.Bot.Db.Models;
|
using Nadeko.Bot.Db.Models;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
using LinqToDB;
|
||||||
|
using LinqToDB.EntityFrameworkCore;
|
||||||
|
using NadekoBot.Db.Models;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Administration.Services;
|
namespace NadekoBot.Modules.Administration.Services;
|
||||||
|
|
||||||
@@ -396,4 +399,54 @@ public sealed class SelfService : IExecNoCommand, IReadyExecutor, INService
|
|||||||
public string Link { get; init; }
|
public string Link { get; init; }
|
||||||
public ActivityType Type { get; init; }
|
public ActivityType Type { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the specified <paramref name="users"/> to the database. If a database user with placeholder name
|
||||||
|
/// and discriminator is present in <paramref name="users"/>, their name and discriminator get updated accordingly.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ctx">This database context.</param>
|
||||||
|
/// <param name="users">The users to add or update in the database.</param>
|
||||||
|
/// <returns>A tuple with the amount of new users added and old users updated.</returns>
|
||||||
|
public async Task<(long UsersAdded, long UsersUpdated)> RefreshUsersAsync(List<IUser> users)
|
||||||
|
{
|
||||||
|
await using var ctx = _db.GetDbContext();
|
||||||
|
var presentDbUsers = await ctx.GetTable<DiscordUser>()
|
||||||
|
.Select(x => new { x.UserId, x.Username, x.Discriminator })
|
||||||
|
.Where(x => users.Select(y => y.Id).Contains(x.UserId))
|
||||||
|
.ToArrayAsyncEF();
|
||||||
|
|
||||||
|
var usersToAdd = users
|
||||||
|
.Where(x => !presentDbUsers.Select(x => x.UserId).Contains(x.Id))
|
||||||
|
.Select(x => new DiscordUser()
|
||||||
|
{
|
||||||
|
UserId = x.Id,
|
||||||
|
AvatarId = x.AvatarId,
|
||||||
|
Username = x.Username,
|
||||||
|
Discriminator = x.Discriminator
|
||||||
|
});
|
||||||
|
|
||||||
|
var added = (await ctx.BulkCopyAsync(usersToAdd)).RowsCopied;
|
||||||
|
var toUpdateUserIds = presentDbUsers
|
||||||
|
.Where(x => x.Username == "Unknown" && x.Discriminator == "????")
|
||||||
|
.Select(x => x.UserId)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
foreach (var user in users.Where(x => toUpdateUserIds.Contains(x.Id)))
|
||||||
|
{
|
||||||
|
await ctx.GetTable<DiscordUser>()
|
||||||
|
.Where(x => x.UserId == user.Id)
|
||||||
|
.UpdateAsync(x => new DiscordUser()
|
||||||
|
{
|
||||||
|
Username = user.Username,
|
||||||
|
Discriminator = user.Discriminator,
|
||||||
|
|
||||||
|
// .award tends to set AvatarId and DateAdded to NULL, so account for that.
|
||||||
|
AvatarId = user.AvatarId,
|
||||||
|
DateAdded = x.DateAdded ?? DateTime.UtcNow
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return (added, toUpdateUserIds.Length);
|
||||||
|
}
|
||||||
}
|
}
|
@@ -14,7 +14,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Discord.Net" Version="3.202.0" />
|
<PackageReference Include="Discord.Net" Version="3.203.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Discord.Net.Core" Version="3.202.0" />
|
<PackageReference Include="Discord.Net.Core" Version="3.203.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Discord.Net.Core" Version="3.202.0" />
|
<PackageReference Include="Discord.Net.Core" Version="3.203.0" />
|
||||||
<PackageReference Include="Serilog" Version="2.12.0" />
|
<PackageReference Include="Serilog" Version="2.12.0" />
|
||||||
<PackageReference Include="YamlDotNet" Version="13.0.2" />
|
<PackageReference Include="YamlDotNet" Version="13.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
Reference in New Issue
Block a user