Skip to content

Commit

Permalink
messaging changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sphexator committed Jan 3, 2025
1 parent a561d78 commit 6e5c711
Show file tree
Hide file tree
Showing 26 changed files with 74 additions and 69 deletions.
2 changes: 1 addition & 1 deletion Hanekawa.Application/Contracts/Discord/Common/Ban.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Hanekawa.Application.Contracts.Discord.Common;

public record Ban : ISqs
public record Ban : IMessageSqs
{
public ulong GuildId { get; init; }
public ulong UserId { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion Hanekawa.Application/Contracts/Discord/Common/Kick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Hanekawa.Application.Contracts.Discord.Common;

public class Kick : ISqs
public class Kick : IMessageSqs
{
public ulong GuildId { get; init; }
public ulong UserId { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion Hanekawa.Application/Contracts/Discord/Common/Mute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Hanekawa.Application.Contracts.Discord.Common;

public class Mute : ISqs
public class Mute : IMessageSqs
{
public ulong GuildId { get; init; }
public ulong UserId { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion Hanekawa.Application/Contracts/Discord/Common/Prune.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Hanekawa.Application.Contracts.Discord.Common;

public class Prune : ISqs
public class Prune : IMessageSqs
{
public ulong GuildId { get; init; }
public ulong UserId { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion Hanekawa.Application/Contracts/Discord/Common/Unban.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Hanekawa.Application.Contracts.Discord.Common;

public class Unban : ISqs
public class Unban : IMessageSqs
{
public ulong GuildId { get; init; }
public ulong UserId { get; init; }
Expand Down
2 changes: 1 addition & 1 deletion Hanekawa.Application/Contracts/Discord/Common/Unmute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Hanekawa.Application.Contracts.Discord.Common;

public class Unmute : ISqs
public class Unmute : IMessageSqs
{
public ulong GuildId { get; init; }
public ulong UserId { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Hanekawa.Application.Contracts.Discord.Services;

public record BotLeave(ulong GuildId) : ISqs<bool>;
public record BotLeave(ulong GuildId) : INotificationSqs;
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
namespace Hanekawa.Application.Contracts.Discord.Services;

public record MessageDeleted
(ulong GuildId, ulong ChannelId, ulong AuthorId, ulong MessageId, string MessageContent) : ISqs<bool>;
(ulong GuildId, ulong ChannelId, ulong AuthorId, ulong MessageId, string MessageContent) : INotificationSqs;
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

namespace Hanekawa.Application.Contracts.Discord.Services;

public record MessageReceived(ulong GuildId, ulong ChannelId, DiscordMember Member,
ulong MessageId, string? Message, DateTimeOffset CreatedAt) : ISqs<bool>;
public record MessageReceived(ulong GuildId, ulong ChannelId, DiscordMember Member,
ulong MessageId, string? Message, DateTimeOffset CreatedAt) : INotificationSqs;
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

namespace Hanekawa.Application.Contracts.Discord.Services;

public record MessagesDeleted(ulong GuildId, ulong ChannelId, ulong[] AuthorId,
ulong[] MessageIds, string[] MessageContents) : ISqs<bool>;
public record MessagesDeleted(ulong GuildId, ulong ChannelId, ulong[] AuthorId,
ulong[] MessageIds, string[] MessageContents) : INotificationSqs;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Hanekawa.Application.Contracts.Discord.Services;

public record ReactionAdd(ulong GuildId, ulong ChannelId, ulong MessageId, ulong UserId, string? Emoji) : ISqs<bool>;
public record ReactionAdd(ulong GuildId, ulong ChannelId, ulong MessageId, ulong UserId, string? Emoji) : INotificationSqs;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Hanekawa.Application.Contracts.Discord.Services;

public record ReactionCleared(ulong GuildId, ulong ChannelId, ulong MessageId) : ISqs<bool>;
public record ReactionCleared(ulong GuildId, ulong ChannelId, ulong MessageId) : INotificationSqs;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Hanekawa.Application.Contracts.Discord.Services;

public record ReactionRemove(ulong GuildId, ulong ChannelId, ulong MessageId, ulong UserId, string? Emoji) : ISqs<bool>;
public record ReactionRemove(ulong GuildId, ulong ChannelId, ulong MessageId, ulong UserId, string? Emoji) : INotificationSqs;
9 changes: 6 additions & 3 deletions Hanekawa.Application/Contracts/Discord/Services/UserBanned.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Hanekawa.Entities.Discord;
using MediatR;
using Hanekawa.Application.Interfaces;
using Hanekawa.Entities.Discord;

namespace Hanekawa.Application.Contracts.Discord.Services;

public record UserBanned(DiscordMember Member) : IRequest<bool>, IRequest;
public record UserBanned(DiscordMember Member) : INotificationSqs
{
public ulong GuildId { get; init; }
}
4 changes: 2 additions & 2 deletions Hanekawa.Application/Contracts/Discord/Services/UserJoin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

namespace Hanekawa.Application.Contracts.Discord.Services;

public record UserJoin(ulong GuildId, ulong UserId, string Username,
string AvatarUrl, DateTimeOffset CreatedAt) : ISqs<bool>;
public record UserJoin(ulong GuildId, ulong UserId, string Username,
string AvatarUrl, DateTimeOffset CreatedAt) : INotificationSqs;
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Hanekawa.Application.Contracts.Discord.Services;

public record UserLeave(ulong GuildId, ulong UserId) : ISqs<bool>;
public record UserLeave(ulong GuildId, ulong UserId) : INotificationSqs;
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Hanekawa.Entities.Discord;
using MediatR;
using Hanekawa.Application.Interfaces;
using Hanekawa.Entities.Discord;

namespace Hanekawa.Application.Contracts.Discord.Services;

public record UserUnbanned(DiscordMember Member) : IRequest<bool>;
public record UserUnbanned(DiscordMember Member) : INotificationSqs
{
public ulong GuildId { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace Hanekawa.Application.Contracts.Discord.Services;

public record VoiceStateUpdate(ulong GuildId, ulong UserId, ulong? ChannelId, string? SessionId) : ISqs<bool>;
public record VoiceStateUpdate(ulong GuildId, ulong UserId, ulong? ChannelId, string? SessionId) : IMessageSqs<bool>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@

namespace Hanekawa.Application.Handlers.Services.Levels;

public class MessageReceivedExperienceHandler: IRequestHandler<MessageReceived, bool>
public class MessageReceivedExperienceHandler: INotificationHandler<MessageReceived>
{
private readonly IConfiguration _configuration;
private readonly ILevelService _levelService;

public MessageReceivedExperienceHandler(ILevelService levelService, IConfiguration configuration)
{
_levelService = levelService;
_configuration = configuration;
}
public async Task<bool> Handle(MessageReceived request, CancellationToken cancellationToken)

public async Task Handle(MessageReceived request, CancellationToken cancellationToken)
{
await _levelService.AddExperienceAsync(request.Member,
Random.Shared.Next(Convert.ToInt32(_configuration["expLower"]),
Convert.ToInt32(_configuration["expUpper"])));
return true;
}
}
14 changes: 7 additions & 7 deletions Hanekawa.Application/Handlers/Services/Logs/UserBannedHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Hanekawa.Application.Handlers.Services.Logs;

public class UserBannedHandler : IRequestHandler<UserBanned, bool>
public class UserBannedHandler : INotificationHandler<UserBanned>
{
private readonly IBot _bot;
private readonly IDbContext _db;
Expand All @@ -19,19 +19,19 @@ public UserBannedHandler(IBot bot, IDbContext db)
_db = db;
}

public async Task<bool> Handle(UserBanned request, CancellationToken cancellationToken)
public async Task Handle(UserBanned request, CancellationToken cancellationToken)
{
var cfg = await _db.GuildConfigs.Include(x => x.LogConfig)
.FirstOrDefaultAsync(x => x.GuildId == request.Member.Guild.GuildId, cancellationToken: cancellationToken);
if (cfg is { LogConfig.ModLogChannelId: null }) return false;
if (cfg is { LogConfig.ModLogChannelId: null }) return;
var channel = _bot.GetChannel(request.Member.Guild.GuildId, cfg!.LogConfig.ModLogChannelId.Value);
if (channel is null)
{
cfg.LogConfig.ModLogChannelId = null;
await _db.SaveChangesAsync();
return false;
await _db.SaveChangesAsync(cancellationToken);
return;
}

await _bot.SendMessageAsync(channel.Value, new Embed
{
Title = $"User Banned | Case ID: {request.Member.Id} | ${request.Member.Guild.GuildId}",
Expand All @@ -43,6 +43,6 @@ public async Task<bool> Handle(UserBanned request, CancellationToken cancellatio
new EmbedField("Reason", "No reason provided", false)
]
});
return true;
return;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Hanekawa.Application.Handlers.Services.Logs;

public class UserJoinedHandler : IRequestHandler<UserJoin, bool>
public class UserJoinedHandler : INotificationHandler<UserJoin>
{
public Task<bool> Handle(UserJoin request, CancellationToken cancellationToken)
public Task Handle(UserJoin request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Hanekawa.Application.Handlers.Services.Logs;

public class UserLeftHandler : IRequestHandler<UserLeave, bool>
public class UserLeftHandler : INotificationHandler<UserLeave>
{
public Task<bool> Handle(UserLeave request, CancellationToken cancellationToken)
public Task Handle(UserLeave request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Hanekawa.Application.Handlers.Services.Logs;

public class UserUnbannedHandler : IRequestHandler<UserUnbanned, bool>
public class UserUnbannedHandler : INotificationHandler<UserUnbanned>
{
private readonly IBot _bot;
private readonly IDbContext _db;
Expand All @@ -18,20 +18,20 @@ public UserUnbannedHandler(IBot bot, IDbContext db)
_bot = bot;
_db = db;
}
public async Task<bool> Handle(UserUnbanned request, CancellationToken cancellationToken)

public async Task Handle(UserUnbanned request, CancellationToken cancellationToken)
{
var cfg = await _db.GuildConfigs.Include(x => x.LogConfig)
.FirstOrDefaultAsync(x => x.GuildId == request.Member.Guild.GuildId, cancellationToken: cancellationToken);
if (cfg is { LogConfig.ModLogChannelId: null }) return false;
if (cfg is { LogConfig.ModLogChannelId: null }) return;
var channel = _bot.GetChannel(request.Member.Guild.GuildId, cfg.LogConfig.ModLogChannelId.Value);
if (channel is null)
{
cfg.LogConfig.ModLogChannelId = null;
await _db.SaveChangesAsync();
return false;
await _db.SaveChangesAsync(cancellationToken);
return;
}

await _bot.SendMessageAsync(channel.Value, new Embed
{
Title = $"User Banned | Case ID: {request.Member.Id} | ${request.Member.Guild.GuildId}",
Expand All @@ -43,6 +43,6 @@ public async Task<bool> Handle(UserUnbanned request, CancellationToken cancellat
new EmbedField("Reason", "No reason provided", false)
]
});
return true;
return;
}
}
9 changes: 9 additions & 0 deletions Hanekawa.Application/Interfaces/INotificationSqs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using MediatR;

namespace Hanekawa.Application.Interfaces;

public interface IMetric { ulong GuildId { get; init; } }
public interface INotificationSqs : IMetric, INotification;

public interface IMessageSqs : IMetric, IRequest;
public interface IMessageSqs<out T> : IMetric, IRequest<T>;
9 changes: 0 additions & 9 deletions Hanekawa.Application/Interfaces/ISqs.cs

This file was deleted.

Loading

0 comments on commit 6e5c711

Please sign in to comment.