mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-19 16:33:36 +03:00
resolve all requested changes finally
This commit is contained in:
parent
a8c7d1d965
commit
9c3144a42e
2 changed files with 24 additions and 13 deletions
|
@ -30,18 +30,18 @@ public class RemindCommandGroup : CommandGroup
|
|||
private readonly IFeedbackService _feedback;
|
||||
private readonly GuildDataService _guildData;
|
||||
private readonly IDiscordRestUserAPI _userApi;
|
||||
|
||||
// ReSharper disable once NotAccessedField.Local
|
||||
private readonly IInteractionCommandContext _interactionContext;
|
||||
private readonly IDiscordRestInteractionAPI _interactionApi;
|
||||
|
||||
public RemindCommandGroup(
|
||||
ICommandContext context, GuildDataService guildData, IFeedbackService feedback,
|
||||
IDiscordRestUserAPI userApi, IDiscordRestInteractionAPI interactionApi)
|
||||
IDiscordRestUserAPI userApi, IInteractionCommandContext interactionContext, IDiscordRestInteractionAPI interactionApi)
|
||||
{
|
||||
_context = context;
|
||||
_guildData = guildData;
|
||||
_feedback = feedback;
|
||||
_userApi = userApi;
|
||||
_interactionContext = interactionContext;
|
||||
_interactionApi = interactionApi;
|
||||
}
|
||||
|
||||
|
@ -138,15 +138,17 @@ public class RemindCommandGroup : CommandGroup
|
|||
return Result.FromError(executorResult);
|
||||
}
|
||||
|
||||
var interactionToken = _interactionContext.Interaction.Token;
|
||||
var applicationId = _interactionContext.Interaction.ApplicationID;
|
||||
|
||||
var data = await _guildData.GetData(guildId, CancellationToken);
|
||||
Messages.Culture = GuildSettings.Language.Get(data.Settings);
|
||||
|
||||
return await AddReminderAsync(@in, text, data, channelId, executor, CancellationToken);
|
||||
return await AddReminderAsync(@in, text, data, channelId, executor, interactionToken, applicationId, CancellationToken);
|
||||
}
|
||||
|
||||
private async Task<Result> AddReminderAsync(
|
||||
TimeSpan @in, string text, GuildData data,
|
||||
Snowflake channelId, IUser executor, CancellationToken ct = default)
|
||||
private async Task<Result> AddReminderAsync(TimeSpan @in, string text, GuildData data,
|
||||
Snowflake channelId, IUser executor, string interactionToken, Snowflake applicationId, CancellationToken ct = default)
|
||||
{
|
||||
var remindAt = DateTimeOffset.UtcNow.Add(@in);
|
||||
var memberData = data.GetOrCreateMemberData(executor.ID);
|
||||
|
@ -162,20 +164,25 @@ public class RemindCommandGroup : CommandGroup
|
|||
.WithFooter(string.Format(Messages.ReminderPosition, memberData.Reminders.Count + 1))
|
||||
.Build();
|
||||
var messageResult = await _feedback.SendContextualEmbedAsync(embed.Entity, ct: ct);
|
||||
if (!messageResult.IsDefined(out var message))
|
||||
if (!messageResult.IsDefined(out _))
|
||||
{
|
||||
return (Result)messageResult;
|
||||
}
|
||||
|
||||
// var a = await _interactionApi.GetOriginalInteractionResponseAsync(message.Application.Value.ID.Value, "", ct);
|
||||
//TODO
|
||||
var a = await _interactionApi.GetOriginalInteractionResponseAsync(applicationId, interactionToken, ct);
|
||||
if (!a.IsDefined(out var interaction))
|
||||
{
|
||||
return (Result)a;
|
||||
}
|
||||
|
||||
var interactionValue = interaction.Interaction.Value.ID;
|
||||
memberData.Reminders.Add(
|
||||
new Reminder
|
||||
{
|
||||
At = remindAt,
|
||||
ChannelId = channelId.Value,
|
||||
Text = text,
|
||||
MessageId = message.ID.Value
|
||||
MessageId = interactionValue.Value
|
||||
});
|
||||
|
||||
return (Result)messageResult;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
@ -225,10 +226,13 @@ public sealed partial class MemberUpdateService : BackgroundService
|
|||
return Result.FromSuccess();
|
||||
}
|
||||
|
||||
var builder = new StringBuilder()
|
||||
.AppendBulletPointLine(string.Format(Messages.DescriptionReminder, Markdown.InlineCode(reminder.Text)))
|
||||
.AppendBulletPointLine(string.Format(Messages.DescriptionActionJumpToMessage, $"https://discord.com/channels/{guildId.Value}/{reminder.ChannelId}/{reminder.MessageId}"));
|
||||
|
||||
var embed = new EmbedBuilder().WithSmallTitle(
|
||||
string.Format(Messages.Reminder, user.GetTag()), user)
|
||||
.WithDescription(string.Format(Messages.DescriptionReminder, Markdown.InlineCode(reminder.Text)) +
|
||||
$" (https://discord.com/channels/{guildId.Value}/{reminder.ChannelId}/{reminder.MessageId})")
|
||||
.WithDescription(string.Format(builder.ToString()))
|
||||
.WithColour(ColorsList.Magenta)
|
||||
.Build();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue