-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1039 from discord-csharp/start-moderation-refactor
V3: Start moderation refactor, add scoped session concept
- Loading branch information
Showing
34 changed files
with
973 additions
and
1,021 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Discord.Commands; | ||
using Discord.WebSocket; | ||
using Modix.Data.Models.Core; | ||
using Modix.Services; | ||
|
||
namespace Modix.Bot; | ||
|
||
public class DiscordBotSession(DiscordSocketClient discordSocketClient, | ||
AuthorizationClaimService authorizationClaimService) : IScopedSession | ||
{ | ||
public ulong SelfUserId { get; } = discordSocketClient.CurrentUser.Id; | ||
|
||
private ulong _executingUserId; | ||
|
||
public ulong ExecutingUserId => | ||
_executingUserId == default | ||
? SelfUserId | ||
: _executingUserId; | ||
|
||
private IReadOnlyCollection<AuthorizationClaim> _authorizationClaims; | ||
|
||
public void ApplyCommandContext(ICommandContext context) | ||
{ | ||
_executingUserId = context.User.Id; | ||
} | ||
|
||
private async Task<IReadOnlyCollection<AuthorizationClaim>> GetClaims() | ||
{ | ||
return _authorizationClaims ??= await authorizationClaimService.GetClaimsForUser(ExecutingUserId); | ||
} | ||
|
||
public async Task<bool> HasClaim(params AuthorizationClaim[] claims) | ||
{ | ||
var ownedClaims = await GetClaims(); | ||
return claims.All(claim => ownedClaims.Contains(claim)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/Modix.Bot/Notifications/AuditLogCreatedNotificationV3.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Discord.WebSocket; | ||
using MediatR; | ||
|
||
namespace Modix.Bot.Notifications; | ||
|
||
public class AuditLogCreatedNotificationV3(SocketAuditLogEntry entry, SocketGuild guild) : INotification | ||
{ | ||
public SocketAuditLogEntry Entry { get; } = entry; | ||
public SocketGuild Guild { get; } = guild; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Discord.WebSocket; | ||
using MediatR; | ||
|
||
namespace Modix.Bot.Notifications; | ||
|
||
public class ChannelCreatedNotificationV3(SocketChannel channel) : INotification | ||
{ | ||
public SocketChannel Channel { get; } = channel; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Modix.Bot/Notifications/ChannelUpdatedNotificationV3.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using Discord.WebSocket; | ||
using MediatR; | ||
|
||
namespace Modix.Bot.Notifications; | ||
|
||
public class ChannelUpdatedNotificationV3(SocketChannel oldChannel, SocketChannel newChannel) : INotification | ||
{ | ||
public SocketChannel OldChannel { get; } = oldChannel; | ||
public SocketChannel NewChannel { get; } = newChannel; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Discord.WebSocket; | ||
using MediatR; | ||
|
||
namespace Modix.Bot.Notifications; | ||
|
||
public class GuildAvailableNotificationV3(SocketGuild guild) : INotification | ||
{ | ||
public SocketGuild Guild { get; } = guild; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Discord.WebSocket; | ||
using MediatR; | ||
|
||
namespace Modix.Bot.Notifications; | ||
|
||
public class JoinedGuildNotificationV3(SocketGuild guild) : INotification | ||
{ | ||
public SocketGuild Guild { get; } = guild; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using Discord.WebSocket; | ||
using MediatR; | ||
|
||
namespace Modix.Bot.Notifications; | ||
|
||
public class UserJoinedNotificationV3(SocketGuildUser guildUser) : INotification | ||
{ | ||
public SocketGuildUser GuildUser { get; } = guildUser; | ||
} |
Oops, something went wrong.