Compare commits

...

3 Commits

7 changed files with 78 additions and 25 deletions

View File

@@ -9,7 +9,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="AppAny.Quartz.EntityFrameworkCore.Migrations.SQLite" Version="0.4.0" /> <PackageReference Include="AppAny.Quartz.EntityFrameworkCore.Migrations.SQLite" Version="0.4.0" />
<PackageReference Include="Discord.Net" Version="3.9.0" /> <PackageReference Include="Discord.Net" Version="3.10.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

View File

@@ -31,7 +31,7 @@ public class ActivityFormatter
ActivityName.InterstellarExploration => "Porte interstellaire", ActivityName.InterstellarExploration => "Porte interstellaire",
ActivityName.BreakFromDestiny => "Échapper au destin (3v3)", ActivityName.BreakFromDestiny => "Échapper au destin (3v3)",
ActivityName.CriticalAbyss => "Abîme critique (8v8)", ActivityName.CriticalAbyss => "Abîme critique (8v8)",
ActivityName.Event => "Évènement", ActivityName.Minigame => "Évènement",
ActivityName.Fishing => "Pêche", ActivityName.Fishing => "Pêche",
ActivityName.MirroriaRace => "Course Mirroria", ActivityName.MirroriaRace => "Course Mirroria",
_ => throw new ArgumentOutOfRangeException(nameof(activityName), activityName, null) _ => throw new ArgumentOutOfRangeException(nameof(activityName), activityName, null)
@@ -77,16 +77,19 @@ public class ActivityFormatter
fields.Add(playersField); fields.Add(playersField);
string countTitlePart = activity.MaxPlayers == ActivityHelper.UnlimitedPlayers
? ""
: $"({participants.Length}/{activity.MaxPlayers})";
var title = activity switch var title = activity switch
{ {
StagedActivity stagedActivity => StagedActivity stagedActivity =>
$"{FormatActivityName(activity.Name)} ({participants.Length}/{activity.MaxPlayers}) - Étage {stagedActivity.Stage}", $"{FormatActivityName(activity.Name)} {countTitlePart} - Étage {stagedActivity.Stage}",
InterstellarActivity interstellar => InterstellarActivity interstellar =>
$"{FormatActivityName(activity.Name)} {_interstellarFormatter.FormatInterstellarColor(interstellar.Color)} ({players.Count}/{activity.MaxPlayers})", $"{FormatActivityName(activity.Name)} {_interstellarFormatter.FormatInterstellarColor(interstellar.Color)} {countTitlePart}",
OrganizedActivity => OrganizedActivity =>
$"{(ActivityHelper.IsEventActivity(activity.Type) ? "Organisation d'évènement" : $"Proposition d'aide - {FormatActivityName(activity.Name)}")} ({participants.Length}/{activity.MaxPlayers})", $"{(ActivityHelper.IsEventActivity(activity.Type) ? "Organisation d'évènement" : $"Proposition d'aide - {FormatActivityName(activity.Name)}")} {countTitlePart}",
_ => _ =>
$"{FormatActivityName(activity.Name)} ({participants.Length}/{activity.MaxPlayers})" $"{FormatActivityName(activity.Name)} {countTitlePart}"
}; };
// Build description // Build description
@@ -156,7 +159,7 @@ public class ActivityFormatter
ActivityName.BreakFromDestiny => "BR", ActivityName.BreakFromDestiny => "BR",
ActivityName.CriticalAbyss => "CA", ActivityName.CriticalAbyss => "CA",
ActivityName.Fishing => "FI", ActivityName.Fishing => "FI",
ActivityName.Event => "EV", ActivityName.Minigame => "EV",
ActivityName.MirroriaRace => "MR", ActivityName.MirroriaRace => "MR",
_ => "NA" _ => "NA"
}; };

View File

@@ -9,7 +9,7 @@ namespace Cocotte.Modules.Activities;
public class ActivityHelper public class ActivityHelper
{ {
private const uint UnlimitedPlayers = uint.MaxValue; public const uint UnlimitedPlayers = uint.MaxValue;
private readonly ActivityOptions _options; private readonly ActivityOptions _options;
private readonly ActivitiesRepository _activitiesRepository; private readonly ActivitiesRepository _activitiesRepository;
@@ -57,32 +57,31 @@ public class ActivityHelper
ActivityName.BreakFromDestiny => ActivityType.Pvp3Players, ActivityName.BreakFromDestiny => ActivityType.Pvp3Players,
ActivityName.Event or ActivityName.Minigame => ActivityType.Other8Players,
ActivityName.Fishing => ActivityType.Event8Players,
ActivityName.MirroriaRace => ActivityType.Event4Players, ActivityName.MirroriaRace => ActivityType.Other4Players,
_ => ActivityType.Other _ => ActivityType.OtherUnlimitedPlayers
}; };
public static uint ActivityTypeToMaxPlayers(ActivityType activityType) => activityType switch public static uint ActivityTypeToMaxPlayers(ActivityType activityType) => activityType switch
{ {
ActivityType.Pve4Players or ActivityType.Pve4Players or
ActivityType.Event4Players => 4, ActivityType.Other4Players => 4,
ActivityType.Pve8Players or ActivityType.Pve8Players or
ActivityType.Pvp8Players or ActivityType.Pvp8Players or
ActivityType.Event8Players => 8, ActivityType.Other8Players => 8,
ActivityType.Pvp3Players => 3, ActivityType.Pvp3Players => 3,
ActivityType.Other => UnlimitedPlayers, ActivityType.OtherUnlimitedPlayers => UnlimitedPlayers,
_ => 0 _ => 0
}; };
public static bool IsEventActivity(ActivityType activityType) => public static bool IsEventActivity(ActivityType activityType) =>
activityType is ActivityType.Event8Players or ActivityType.Event4Players or ActivityType.Other; activityType is ActivityType.Other8Players or ActivityType.Other4Players or ActivityType.OtherUnlimitedPlayers;
public bool IsOrganizer(OrganizedActivity organizedActivity, SocketGuildUser user) public bool IsOrganizer(OrganizedActivity organizedActivity, SocketGuildUser user)
{ {

View File

@@ -142,12 +142,12 @@ public partial class ActivityModule : InteractionModuleBase<SocketInteractionCon
[SlashCommand("evenement", "Créer un groupe pour les évènements")] [SlashCommand("evenement", "Créer un groupe pour les évènements")]
[Alias("event")] [Alias("event")]
public async Task ActivityEvent( public async Task ActivityMinigame(
[Summary("joueurs", "Nombre de joueurs maximum pour cette activité")] [MinValue(2), MaxValue(16)] [Summary("joueurs", "Nombre de joueurs maximum pour cette activité")] [MinValue(2), MaxValue(16)]
uint maxPlayers = 8, [Summary("heure", "Heure à laquelle l'activité est prévue")] string? timeInput = null, uint maxPlayers = 8, [Summary("heure", "Heure à laquelle l'activité est prévue")] string? timeInput = null,
[Summary("description", "Message accompagnant la demande de groupe")] string description = "") [Summary("description", "Message accompagnant la demande de groupe")] string description = "")
{ {
await CreateActivity(ActivityName.Event, timeInput, description, areRolesEnabled: false, await CreateActivity(ActivityName.Minigame, timeInput, description, areRolesEnabled: false,
maxPlayers: maxPlayers); maxPlayers: maxPlayers);
} }
@@ -499,7 +499,7 @@ public partial class ActivityModule : InteractionModuleBase<SocketInteractionCon
} }
// Check if user has permission to delete this activity // Check if user has permission to delete this activity
if (User.Id != activity.CreatorUserId && !User.GetPermissions((IGuildChannel) Context.Channel).ManageMessages) if (User.Id != activity.CreatorUserId && Context.User.Id != (await Context.Client.GetApplicationInfoAsync()).Owner.Id)
{ {
await RespondAsync( await RespondAsync(
ephemeral: true, ephemeral: true,

View File

@@ -189,6 +189,56 @@ public partial class ActivityModule
await RespondWithModalAsync<ActivityDescriptionModal>("activity description_modal"); await RespondWithModalAsync<ActivityDescriptionModal>("activity description_modal");
} }
[SlashCommand("etage", "Changer l'étage de l'activité pour l'abîme du néant et l'origine de la guerre")]
public async Task ThreadChangeStage([Summary("étage", "Nouvel étage, de 1 à 6 en abîme du néant, et de 1 à 25 en origine de la guerre")] [MinValue(1), MaxValue(25)] uint stage)
{
// Get activity linked to this thread
var activity = _activitiesRepository.FindActivityByThreadId(Context.Channel.Id);
if (!await CheckCommandInThread(activity, checkCreator: true) || activity is null)
{
return;
}
if (activity is not StagedActivity stagedActivity)
{
await RespondAsync(
ephemeral: true,
embed: EmbedUtils.ErrorEmbed("Cette commande n'est utilisable que pour l'abîme du néant et l'origine de la guerre").Build()
);
return;
}
// Check if stage is valid
var stageValid = (activity.Name, stage) switch
{
(ActivityName.Abyss, >= 1 and <= 6) => true,
(ActivityName.OriginsOfWar, >= 1 and <= 25) => true,
_ => false
};
if (!stageValid)
{
await RespondAsync(
ephemeral: true,
embed: EmbedUtils.ErrorEmbed("Etage invalide").Build()
);
return;
}
stagedActivity.Stage = stage;
await _activitiesRepository.SaveChanges();
await UpdateActivityEmbed(activity, ActivityUpdateReason.Update);
await RespondAsync(
ephemeral: true,
embed: EmbedUtils.InfoEmbed($"L'activité est maintenant bien définie à **l'étage {stage}**").Build()
);
}
[ModalInteraction("activity description_modal", ignoreGroupNames: true)] [ModalInteraction("activity description_modal", ignoreGroupNames: true)]
public async Task ActivityDescriptionSubmit(ActivityDescriptionModal descriptionModal) public async Task ActivityDescriptionSubmit(ActivityDescriptionModal descriptionModal)
{ {
@@ -246,4 +296,4 @@ public class ActivityDescriptionModal : IModal
[InputLabel("Description")] [InputLabel("Description")]
[ModalTextInput("activity_description", TextInputStyle.Paragraph)] [ModalTextInput("activity_description", TextInputStyle.Paragraph)]
public required string Description { get; set; } public required string Description { get; set; }
} }

View File

@@ -12,6 +12,7 @@ public enum ActivityName
BreakFromDestiny, BreakFromDestiny,
CriticalAbyss, CriticalAbyss,
Fishing, Fishing,
Event, Minigame,
MirroriaRace MirroriaRace,
Event
} }

View File

@@ -6,7 +6,7 @@ public enum ActivityType
Pve8Players, Pve8Players,
Pvp8Players, Pvp8Players,
Pvp3Players, Pvp3Players,
Event8Players, Other8Players,
Event4Players, Other4Players,
Other OtherUnlimitedPlayers
} }