[Activity] Add description change command in thread
This commit is contained in:
@@ -96,7 +96,7 @@ public class ActivityFormatter
|
|||||||
// Add time if specified
|
// Add time if specified
|
||||||
if (activity.DueDateTime is { } dueDateTime)
|
if (activity.DueDateTime is { } dueDateTime)
|
||||||
{
|
{
|
||||||
descriptionBuilder.AppendLine($"**:clock2: {TimestampTag.FormatFromDateTime(dueDateTime, TimestampTagStyles.ShortTime)} ― {(activity.IsClosed ? "Fermée" : TimestampTag.FormatFromDateTime(dueDateTime, TimestampTagStyles.Relative))}**");
|
descriptionBuilder.AppendLine($"**:clock2: {TimestampTag.FormatFromDateTime(dueDateTime, TimestampTagStyles.ShortTime)} ╿ {(activity.IsClosed ? "Fermée" : TimestampTag.FormatFromDateTime(dueDateTime, TimestampTagStyles.Relative))}**");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -112,7 +112,12 @@ public class ActivityFormatter
|
|||||||
|
|
||||||
// Add thread link
|
// Add thread link
|
||||||
descriptionBuilder.AppendLine();
|
descriptionBuilder.AppendLine();
|
||||||
descriptionBuilder.Append($"**[Fil associé]({ChannelUtils.GetChannelLink(activity.GuildId, activity.ThreadId)})**");
|
descriptionBuilder.Append(
|
||||||
|
$"""
|
||||||
|
**⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯**
|
||||||
|
**[Fil associé]({ChannelUtils.GetChannelLink(activity.GuildId, activity.ThreadId)})**
|
||||||
|
**⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯**
|
||||||
|
""");
|
||||||
|
|
||||||
string bannerUrl = GetActivityBanner(activity.Name);
|
string bannerUrl = GetActivityBanner(activity.Name);
|
||||||
|
|
||||||
|
|||||||
@@ -174,6 +174,44 @@ public partial class ActivityModule
|
|||||||
await RespondAsync(pingMessageBuilder.ToString());
|
await RespondAsync(pingMessageBuilder.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SlashCommand("description", "Changer la description de l'activité")]
|
||||||
|
public async Task ThreadChangeDescription()
|
||||||
|
{
|
||||||
|
// Get activity linked to this thread
|
||||||
|
var activity = _activitiesRepository.FindActivityByThreadId(Context.Channel.Id);
|
||||||
|
|
||||||
|
if (!await CheckCommandInThread(activity, checkCreator: true) || activity is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open modal
|
||||||
|
await RespondWithModalAsync<ActivityDescriptionModal>("activity description_modal");
|
||||||
|
}
|
||||||
|
|
||||||
|
[ModalInteraction("activity description_modal", ignoreGroupNames: true)]
|
||||||
|
public async Task ActivityDescriptionSubmit(ActivityDescriptionModal descriptionModal)
|
||||||
|
{
|
||||||
|
// Get activity linked to this thread
|
||||||
|
var activity = _activitiesRepository.FindActivityByThreadId(Context.Channel.Id);
|
||||||
|
|
||||||
|
if (!await CheckCommandInThread(activity, checkCreator: true) || activity is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update description
|
||||||
|
activity.Description = descriptionModal.Description;
|
||||||
|
await _activitiesRepository.SaveChanges();
|
||||||
|
|
||||||
|
await UpdateActivityEmbed(activity, ActivityUpdateReason.Update);
|
||||||
|
|
||||||
|
await RespondAsync(
|
||||||
|
ephemeral: true,
|
||||||
|
embed: EmbedUtils.InfoEmbed("**La description** a bien été changée").Build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private async Task<bool> CheckCommandInThread(Activity? activity, bool checkCreator = false)
|
private async Task<bool> CheckCommandInThread(Activity? activity, bool checkCreator = false)
|
||||||
{
|
{
|
||||||
// Check if activity is not null (means we are in a valid thread)
|
// Check if activity is not null (means we are in a valid thread)
|
||||||
@@ -199,4 +237,13 @@ public partial class ActivityModule
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ActivityDescriptionModal : IModal
|
||||||
|
{
|
||||||
|
public string Title => "Nouvelle description";
|
||||||
|
|
||||||
|
[InputLabel("Description")]
|
||||||
|
[ModalTextInput("activity_description", TextInputStyle.Paragraph)]
|
||||||
|
public required string Description { get; set; }
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ await using(var scope = host.Services.CreateAsyncScope())
|
|||||||
var dbContext = scope.ServiceProvider.GetRequiredService<CocotteDbContext>();
|
var dbContext = scope.ServiceProvider.GetRequiredService<CocotteDbContext>();
|
||||||
if (hostEnvironment.IsDevelopment())
|
if (hostEnvironment.IsDevelopment())
|
||||||
{
|
{
|
||||||
await dbContext.Database.EnsureDeletedAsync();
|
// await dbContext.Database.EnsureDeletedAsync();
|
||||||
await dbContext.Database.EnsureCreatedAsync();
|
await dbContext.Database.EnsureCreatedAsync();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user