Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ProgramowanieBot/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class InteractionHandlerConfiguration
{
public string AlreadyMentionedResponse { get; set; }
public string ApproveButtonLabel { get; set; }
public string ApprovedPostResolvingMessage { get; set; }
public string IHelpedMyselfButtonLabel { get; set; }
public string NotHelpChannelResponse { get; set; }
public string NotOwnMessageResponse { get; set; }
Expand All @@ -87,8 +88,8 @@ public class InteractionHandlerConfiguration
public string ShowProfileOnBotResponse { get; set; }
public StealEmojiConfiguration StealEmoji { get; set; }
public string SyncingPostsResponse { get; set; }
public string WaitingForApprovalResponse { get; set; }
public string WaitingForApprovalWith2HelpersResponse { get; set; }
public string WaitingForApprovalMessage { get; set; }
public string WaitingForApprovalWith2HelpersMessage { get; set; }

public class ReactionCommandsConfiguration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,29 @@ public async Task<InteractionCallback> ResolveAsync(
if (await context.Posts.AnyAsync(p => p.PostId == channelId && p.IsResolved))
throw new(configuration.Interaction.PostAlreadyResolvedResponse);

await Context.Client.Rest.SendMessageAsync(configuration.Interaction.PostResolvedNotificationChannelId, $"**{string.Format(configuration.Interaction.PostResolvedNotificationMessage, channel)}**");

var isHelper2 = helper2 != null && helper != helper2;
var user = Context.User;
return InteractionCallback.Message(new()

var closingMessage = await Context.Channel.SendMessageAsync(new()
{
Content = $"**{configuration.Emojis.Success} {(isHelper2 ? string.Format(configuration.Interaction.WaitingForApprovalWith2HelpersResponse, helper, helper2) : string.Format(configuration.Interaction.WaitingForApprovalResponse, helper))}**",
Content = $"**{configuration.Emojis.Success} {(isHelper2 ? string.Format(configuration.Interaction.WaitingForApprovalWith2HelpersMessage, helper, helper2) : string.Format(configuration.Interaction.WaitingForApprovalMessage, helper))}**",
AllowedMentions = AllowedMentionsProperties.None,
});


await Context.Client.Rest.SendMessageAsync(configuration.Interaction.PostResolvedNotificationChannelId, new()
{
Content = $"**{string.Format(configuration.Interaction.PostResolvedNotificationMessage, channel)}**",
Components =
[
new ActionRowProperties(
[
new ActionButtonProperties($"approve:{helper.Id}:{helper != user}:{(isHelper2 ? helper2!.Id : null)}:{(isHelper2 ? helper2 != user : null)}", configuration.Interaction.ApproveButtonLabel, ButtonStyle.Success),
new ActionButtonProperties($"approve:{Context.Channel.Id}:{closingMessage.Id}:{helper.Id}:{helper != user}:{(isHelper2 ? helper2!.Id : null)}:{(isHelper2 ? helper2 != user : null)}", configuration.Interaction.ApproveButtonLabel, ButtonStyle.Success),
]),
],
AllowedMentions = AllowedMentionsProperties.None,
});

return InteractionCallback.DeferredModifyMessage;
}

public class NameTranslationsProvider : ITranslationsProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Extensions.Options;

using NetCord;
using NetCord.Gateway;
using NetCord.Rest;
using NetCord.Services;
using NetCord.Services.Interactions;
Expand All @@ -16,12 +17,10 @@ public class ApproveInteraction(IServiceProvider serviceProvider, IOptions<Confi
{
[RequireUserPermissions<ButtonInteractionContext>(Permissions.Administrator)]
[Interaction("approve")]
public async Task ApproveAsync(ulong helper, bool giveReputation, ulong? helper2 = null, bool? giveReputation2 = null)
public async Task ApproveAsync(ulong channelId, ulong closingMessageId, ulong helper, bool giveReputation, ulong? helper2 = null, bool? giveReputation2 = null)
{
var configuration = options.Value;

var channel = (GuildThread)Context.Channel;
var channelId = channel.Id;
await using (var context = serviceProvider.GetRequiredService<DataContext>())
{
await using var transaction = await context.Database.BeginTransactionAsync();
Expand All @@ -38,13 +37,21 @@ public async Task ApproveAsync(ulong helper, bool giveReputation, ulong? helper2
await transaction.CommitAsync();
}

GuildThread channel = (GuildThread)Context.Client.Rest.GetChannelAsync(channelId).Result;

await RespondAsync(InteractionCallback.ModifyMessage(m =>
{
m.Content = $"**{configuration.Emojis.Success} {configuration.Interaction.PostResolvedResponse}**";
m.Content = $"**{configuration.Emojis.Success} {string.Format(configuration.Interaction.ApprovedPostResolvingMessage, channel)}**";
m.Components = [];
}));

var user = Context.User;

await channel.ModifyMessageAsync(closingMessageId, m =>
{
m.Content = $"**{configuration.Emojis.Success} {configuration.Interaction.PostResolvedResponse}**";
m.Components = [];
});
await channel.ModifyAsync(t =>
{
t.Archived = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,24 @@ public async Task<InteractionCallback> ResolveAsync(ulong helper)
if (await context.Posts.AnyAsync(p => p.PostId == channelId && p.IsResolved))
throw new(configuration.Interaction.PostAlreadyResolvedResponse);

await Context.Client.Rest.SendMessageAsync(configuration.Interaction.PostResolvedNotificationChannelId, $"**{string.Format(configuration.Interaction.PostResolvedNotificationMessage, channel)}**");
var closingMessage = await Context.Channel.SendMessageAsync(new()
{
Content = $"**{configuration.Emojis.Success} {string.Format(configuration.Interaction.WaitingForApprovalMessage, $"<@{helper}>")}**",
AllowedMentions = AllowedMentionsProperties.None,
});

return InteractionCallback.Message(new()
await Context.Client.Rest.SendMessageAsync(configuration.Interaction.PostResolvedNotificationChannelId, new()
{
Content = $"**{configuration.Emojis.Success} {string.Format(configuration.Interaction.WaitingForApprovalResponse, $"<@{helper}>")}**",
Content = $"**{configuration.Emojis.Success} {string.Format(configuration.Interaction.PostResolvedNotificationMessage, channel)}**",
Components =
[
new ActionRowProperties(
[
new ActionButtonProperties($"approve:{helper}:{helper != Context.User.Id}::", configuration.Interaction.ApproveButtonLabel, ButtonStyle.Success),
new ActionButtonProperties($"approve:{Context.Channel.Id}:{closingMessage.Id}:{helper}:{helper != Context.User.Id}::", configuration.Interaction.ApproveButtonLabel, ButtonStyle.Success),
]),
],
AllowedMentions = AllowedMentionsProperties.None,
});

return InteractionCallback.DeferredModifyMessage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,27 @@ public async Task<InteractionCallback> ResolveAsync()
else
helper2 = null;

await Context.Client.Rest.SendMessageAsync(configuration.Interaction.PostResolvedNotificationChannelId, $"**{string.Format(configuration.Interaction.PostResolvedNotificationMessage, channel)}**");

var user = Context.User;
return InteractionCallback.Message(new()

var closingMessage = await Context.Channel.SendMessageAsync(new()
{
Content = $"**{configuration.Emojis.Success} {(isHelper2 ? string.Format(configuration.Interaction.WaitingForApprovalWith2HelpersResponse, helper, helper2) : string.Format(configuration.Interaction.WaitingForApprovalResponse, helper))}**",
Content = $"**{configuration.Emojis.Success} {(isHelper2 ? string.Format(configuration.Interaction.WaitingForApprovalWith2HelpersMessage, helper, helper2) : string.Format(configuration.Interaction.WaitingForApprovalMessage, helper))}**",
AllowedMentions = AllowedMentionsProperties.None,
});


await Context.Client.Rest.SendMessageAsync(configuration.Interaction.PostResolvedNotificationChannelId, new()
{
Content = $"**{string.Format(configuration.Interaction.PostResolvedNotificationMessage, channel)}**",
Components =
[
new ActionRowProperties(
[
new ActionButtonProperties($"approve:{helper.Id}:{helper != user}:{(isHelper2 ? helper2!.Id : null)}:{(isHelper2 ? helper2 != user : null)}", configuration.Interaction.ApproveButtonLabel, ButtonStyle.Success),
new ActionButtonProperties($"approve:{Context.Channel.Id}:{closingMessage.Id}:{helper.Id}:{helper != user}:{(isHelper2 ? helper2!.Id : null)}:{(isHelper2 ? helper2 != user : null)}", configuration.Interaction.ApproveButtonLabel, ButtonStyle.Success),
]),
],
AllowedMentions = AllowedMentionsProperties.None,
});

return InteractionCallback.DeferredModifyMessage;
}
}
5 changes: 3 additions & 2 deletions ProgramowanieBot/appsettings - sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"Interaction": {
"AlreadyMentionedResponse": "Już spingowano!",
"ApproveButtonLabel": "Zatwierdź",
"ApprovedPostResolvingMessage": "Post {0} został rozwiązany. Zatwierdzono przez administrację.",
"IHelpedMyselfButtonLabel": "Sam sobie pomogłem",
"NotHelpChannelResponse": "Nie możesz używać tej komendy tutaj!",
"NotOwnMessageResponse": "Możesz użyć tej komendy tylko na własnych wiadomościach!",
Expand Down Expand Up @@ -97,8 +98,8 @@
"StealEmojisMenuPlaceholder": "Wybierz emoji do dodania"
},
"SyncingPostsResponse": "Synchronizowanie postów! Ta operacja może zająć długi czas.",
"WaitingForApprovalResponse": "{0} został wskazany jako pomocnik! Oczekiwanie na zatwierdzenie przez administrację!",
"WaitingForApprovalWith2HelpersResponse": "{0} oraz {1} zostali wskazani jako pomocnicy! Oczekiwanie na zatwierdzenie przez administrację!"
"WaitingForApprovalMessage": "{0} został wskazany jako pomocnik! Oczekiwanie na zatwierdzenie przez administrację!",
"WaitingForApprovalWith2HelpersMessage": "{0} oraz {1} zostali wskazani jako pomocnicy! Oczekiwanie na zatwierdzenie przez administrację!"
},
"Discord": {
"Token": ""
Expand Down