Compare commits
2 Commits
e3df53738f
...
094f07ea3c
| Author | SHA1 | Date | |
|---|---|---|---|
| 094f07ea3c | |||
| d47442b984 |
@@ -8,7 +8,19 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Discord.Net" Version="3.8.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
|
||||
<PackageReference Include="Discord.Net" Version="3.9.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="cocotte.db" />
|
||||
<Content Include="cocotte.db">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
122
Cocotte/Migrations/20230320145030_InitialCreate.Designer.cs
generated
Normal file
122
Cocotte/Migrations/20230320145030_InitialCreate.Designer.cs
generated
Normal file
@@ -0,0 +1,122 @@
|
||||
// <auto-generated />
|
||||
using Cocotte.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Cocotte.Migrations
|
||||
{
|
||||
[DbContext(typeof(CocotteContext))]
|
||||
[Migration("20230320145030_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "7.0.4");
|
||||
|
||||
modelBuilder.Entity("Cocotte.Modules.Activity.Models.Activity", b =>
|
||||
{
|
||||
b.Property<ulong>("ActivityId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ActivityName")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ActivityType")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<ulong>("CreatorId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Discriminator")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<uint>("MaxPlayers")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("ActivityId");
|
||||
|
||||
b.ToTable("Activities");
|
||||
|
||||
b.HasDiscriminator<string>("Discriminator").HasValue("Activity");
|
||||
|
||||
b.UseTphMappingStrategy();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cocotte.Modules.Activity.Models.ActivityPlayer", b =>
|
||||
{
|
||||
b.Property<ulong>("UserId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<ulong>("ActivityId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Discriminator")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("PlayerName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("UserId");
|
||||
|
||||
b.HasIndex("ActivityId");
|
||||
|
||||
b.ToTable("ActivityPlayers");
|
||||
|
||||
b.HasDiscriminator<string>("Discriminator").HasValue("ActivityPlayer");
|
||||
|
||||
b.UseTphMappingStrategy();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cocotte.Modules.Activity.Models.StagedActivity", b =>
|
||||
{
|
||||
b.HasBaseType("Cocotte.Modules.Activity.Models.Activity");
|
||||
|
||||
b.Property<uint>("Stage")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasDiscriminator().HasValue("StagedActivity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cocotte.Modules.Activity.Models.ActivityRolePlayer", b =>
|
||||
{
|
||||
b.HasBaseType("Cocotte.Modules.Activity.Models.ActivityPlayer");
|
||||
|
||||
b.Property<byte>("Roles")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasDiscriminator().HasValue("ActivityRolePlayer");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cocotte.Modules.Activity.Models.ActivityPlayer", b =>
|
||||
{
|
||||
b.HasOne("Cocotte.Modules.Activity.Models.Activity", "Activity")
|
||||
.WithMany("ActivityPlayers")
|
||||
.HasForeignKey("ActivityId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Activity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cocotte.Modules.Activity.Models.Activity", b =>
|
||||
{
|
||||
b.Navigation("ActivityPlayers");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
70
Cocotte/Migrations/20230320145030_InitialCreate.cs
Normal file
70
Cocotte/Migrations/20230320145030_InitialCreate.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Cocotte.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Activities",
|
||||
columns: table => new
|
||||
{
|
||||
ActivityId = table.Column<ulong>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
CreatorId = table.Column<ulong>(type: "INTEGER", nullable: false),
|
||||
Description = table.Column<string>(type: "TEXT", nullable: true),
|
||||
ActivityType = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
ActivityName = table.Column<int>(type: "INTEGER", nullable: false),
|
||||
MaxPlayers = table.Column<uint>(type: "INTEGER", nullable: false),
|
||||
Discriminator = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Stage = table.Column<uint>(type: "INTEGER", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Activities", x => x.ActivityId);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ActivityPlayers",
|
||||
columns: table => new
|
||||
{
|
||||
UserId = table.Column<ulong>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
PlayerName = table.Column<string>(type: "TEXT", nullable: false),
|
||||
ActivityId = table.Column<ulong>(type: "INTEGER", nullable: false),
|
||||
Discriminator = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Roles = table.Column<byte>(type: "INTEGER", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ActivityPlayers", x => x.UserId);
|
||||
table.ForeignKey(
|
||||
name: "FK_ActivityPlayers_Activities_ActivityId",
|
||||
column: x => x.ActivityId,
|
||||
principalTable: "Activities",
|
||||
principalColumn: "ActivityId",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ActivityPlayers_ActivityId",
|
||||
table: "ActivityPlayers",
|
||||
column: "ActivityId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "ActivityPlayers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Activities");
|
||||
}
|
||||
}
|
||||
}
|
||||
119
Cocotte/Migrations/CocotteContextModelSnapshot.cs
Normal file
119
Cocotte/Migrations/CocotteContextModelSnapshot.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
// <auto-generated />
|
||||
using Cocotte.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Cocotte.Migrations
|
||||
{
|
||||
[DbContext(typeof(CocotteContext))]
|
||||
partial class CocotteContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "7.0.4");
|
||||
|
||||
modelBuilder.Entity("Cocotte.Modules.Activity.Models.Activity", b =>
|
||||
{
|
||||
b.Property<ulong>("ActivityId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ActivityName")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("ActivityType")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<ulong>("CreatorId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Discriminator")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<uint>("MaxPlayers")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("ActivityId");
|
||||
|
||||
b.ToTable("Activities");
|
||||
|
||||
b.HasDiscriminator<string>("Discriminator").HasValue("Activity");
|
||||
|
||||
b.UseTphMappingStrategy();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cocotte.Modules.Activity.Models.ActivityPlayer", b =>
|
||||
{
|
||||
b.Property<ulong>("UserId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<ulong>("ActivityId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("Discriminator")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("PlayerName")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("UserId");
|
||||
|
||||
b.HasIndex("ActivityId");
|
||||
|
||||
b.ToTable("ActivityPlayers");
|
||||
|
||||
b.HasDiscriminator<string>("Discriminator").HasValue("ActivityPlayer");
|
||||
|
||||
b.UseTphMappingStrategy();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cocotte.Modules.Activity.Models.StagedActivity", b =>
|
||||
{
|
||||
b.HasBaseType("Cocotte.Modules.Activity.Models.Activity");
|
||||
|
||||
b.Property<uint>("Stage")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasDiscriminator().HasValue("StagedActivity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cocotte.Modules.Activity.Models.ActivityRolePlayer", b =>
|
||||
{
|
||||
b.HasBaseType("Cocotte.Modules.Activity.Models.ActivityPlayer");
|
||||
|
||||
b.Property<byte>("Roles")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasDiscriminator().HasValue("ActivityRolePlayer");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cocotte.Modules.Activity.Models.ActivityPlayer", b =>
|
||||
{
|
||||
b.HasOne("Cocotte.Modules.Activity.Models.Activity", "Activity")
|
||||
.WithMany("ActivityPlayers")
|
||||
.HasForeignKey("ActivityId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Activity");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Cocotte.Modules.Activity.Models.Activity", b =>
|
||||
{
|
||||
b.Navigation("ActivityPlayers");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
24
Cocotte/Modules/Activity/ActivityFormatter.cs
Normal file
24
Cocotte/Modules/Activity/ActivityFormatter.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace Cocotte.Modules.Activity;
|
||||
|
||||
public class ActivityFormatter
|
||||
{
|
||||
public static string ActivityName(ActivityName activityName)
|
||||
{
|
||||
return activityName switch
|
||||
{
|
||||
Modules.Activity.ActivityName.Abyss => "Abîme du Néant",
|
||||
Modules.Activity.ActivityName.Raids => "Raids",
|
||||
Modules.Activity.ActivityName.FrontierClash => "Clash Frontalier",
|
||||
Modules.Activity.ActivityName.VoidRift => "Failles du Néant",
|
||||
Modules.Activity.ActivityName.OriginsOfWar => "Origines de la Guerre",
|
||||
Modules.Activity.ActivityName.JointOperation => "Opération Conjointe",
|
||||
Modules.Activity.ActivityName.InterstellarExploration => "Exploration Interstellaire",
|
||||
Modules.Activity.ActivityName.BreakFromDestiny => "Échapper au Destin (3v3)",
|
||||
Modules.Activity.ActivityName.CriticalAbyss => "Abîme Critique (8v8)",
|
||||
Modules.Activity.ActivityName.Event => "Event",
|
||||
Modules.Activity.ActivityName.Fishing => "Pêche",
|
||||
Modules.Activity.ActivityName.MirroriaRace => "Course Mirroria",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(activityName), activityName, null)
|
||||
};
|
||||
}
|
||||
}
|
||||
82
Cocotte/Modules/Activity/ActivityHelper.cs
Normal file
82
Cocotte/Modules/Activity/ActivityHelper.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using Cocotte.Options;
|
||||
using Discord.WebSocket;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Cocotte.Modules.Activity;
|
||||
|
||||
public class ActivityHelper
|
||||
{
|
||||
private const uint UnlimitedPlayers = uint.MaxValue;
|
||||
|
||||
private readonly ActivityOptions _options;
|
||||
|
||||
public ActivityHelper(IOptions<ActivityOptions> options)
|
||||
{
|
||||
_options = options.Value;
|
||||
}
|
||||
|
||||
public ActivityRoles GetPlayerRoles(IReadOnlyCollection<SocketRole> userRoles)
|
||||
{
|
||||
var roles = ActivityRoles.None;
|
||||
|
||||
foreach (var socketRole in userRoles)
|
||||
{
|
||||
if (socketRole.Id == _options.HelperRoleId)
|
||||
{
|
||||
roles |= ActivityRoles.Helper;
|
||||
}
|
||||
else if (socketRole.Id == _options.DpsRoleId)
|
||||
{
|
||||
roles |= ActivityRoles.Dps;
|
||||
}
|
||||
else if (socketRole.Id == _options.TankRoleId)
|
||||
{
|
||||
roles |= ActivityRoles.Tank;
|
||||
}
|
||||
else if (socketRole.Id == _options.SupportRoleId)
|
||||
{
|
||||
roles |= ActivityRoles.Support;
|
||||
}
|
||||
}
|
||||
|
||||
return roles;
|
||||
}
|
||||
|
||||
public static ActivityType ActivityNameToType(ActivityName activityName) => activityName switch
|
||||
{
|
||||
ActivityName.Abyss or
|
||||
ActivityName.FrontierClash or
|
||||
ActivityName.InterstellarExploration or
|
||||
ActivityName.JointOperation or
|
||||
ActivityName.VoidRift or
|
||||
ActivityName.OriginsOfWar => ActivityType.Pve4Players,
|
||||
|
||||
ActivityName.Raids => ActivityType.Pve8Players,
|
||||
|
||||
ActivityName.CriticalAbyss => ActivityType.Pvp8Players,
|
||||
|
||||
ActivityName.BreakFromDestiny => ActivityType.Pvp3Players,
|
||||
|
||||
ActivityName.Event or
|
||||
ActivityName.Fishing => ActivityType.Event8Players,
|
||||
|
||||
ActivityName.MirroriaRace => ActivityType.Event4Players,
|
||||
|
||||
_ => ActivityType.Other
|
||||
};
|
||||
|
||||
public static uint ActivityTypeToMaxPlayers(ActivityType activityType) => activityType switch
|
||||
{
|
||||
ActivityType.Pve4Players or
|
||||
ActivityType.Event4Players => 4,
|
||||
|
||||
ActivityType.Pve8Players or
|
||||
ActivityType.Event8Players => 8,
|
||||
|
||||
ActivityType.Pvp3Players => 3,
|
||||
|
||||
ActivityType.Other => UnlimitedPlayers,
|
||||
|
||||
_ => 0
|
||||
};
|
||||
}
|
||||
194
Cocotte/Modules/Activity/ActivityModule.cs
Normal file
194
Cocotte/Modules/Activity/ActivityModule.cs
Normal file
@@ -0,0 +1,194 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Cocotte.Modules.Activity.Models;
|
||||
using Cocotte.Options;
|
||||
using Cocotte.Utils;
|
||||
using Discord;
|
||||
using Discord.Interactions;
|
||||
using Discord.WebSocket;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Cocotte.Modules.Activity;
|
||||
|
||||
/// <summary>
|
||||
/// Module to ask and propose groups for different activities: Abyss, OOW, FC, ...
|
||||
/// </summary>
|
||||
[Group("activite", "Organise des activités")]
|
||||
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
||||
public class ActivityModule : InteractionModuleBase<SocketInteractionContext>
|
||||
{
|
||||
private readonly ILogger<ActivityModule> _logger;
|
||||
private readonly ActivityOptions _options;
|
||||
private readonly ActivityHelper _activityHelper;
|
||||
private readonly ActivitiesRepository _activitiesRepository;
|
||||
|
||||
public ActivityModule(ILogger<ActivityModule> logger, IOptions<ActivityOptions> options, ActivityHelper activityHelper, ActivitiesRepository activitiesRepository)
|
||||
{
|
||||
_logger = logger;
|
||||
_activityHelper = activityHelper;
|
||||
_activitiesRepository = activitiesRepository;
|
||||
_options = options.Value;
|
||||
}
|
||||
|
||||
[RequireOwner]
|
||||
[SlashCommand("setup-info", "Display activity setup info")]
|
||||
public async Task SetupInfo()
|
||||
{
|
||||
await RespondAsync($"""
|
||||
- Helper: {MentionUtils.MentionRole(_options.HelperRoleId)} {_options.HelperEmote.ToEmote()}
|
||||
- Dps: {MentionUtils.MentionRole(_options.DpsRoleId)} {_options.DpsEmote.ToEmote()}
|
||||
- Tank: {MentionUtils.MentionRole(_options.TankRoleId)} {_options.TankEmote.ToEmote()}
|
||||
- Healer: {MentionUtils.MentionRole(_options.SupportRoleId)} {_options.SupportEmote.ToEmote()}
|
||||
""");
|
||||
}
|
||||
|
||||
[SlashCommand("abyss", "Créer un groupe pour l'Abîme du Néant")]
|
||||
public async Task ActivityAbyss([Summary("étage", "A quel étage êtes vous")] uint stage, [Summary("description", "Message accompagnant la demande de groupe")] string description = "")
|
||||
{
|
||||
const ActivityName activityName = ActivityName.Abyss;
|
||||
var activityType = ActivityHelper.ActivityNameToType(activityName);
|
||||
var maxPlayers = ActivityHelper.ActivityTypeToMaxPlayers(activityType);
|
||||
|
||||
var activity = new StagedActivity
|
||||
{
|
||||
ActivityId = 0,
|
||||
CreatorId = Context.User.Id,
|
||||
Description = description,
|
||||
ActivityType = activityType,
|
||||
ActivityName = activityName,
|
||||
MaxPlayers = maxPlayers,
|
||||
Stage = stage,
|
||||
ActivityPlayers = new()
|
||||
};
|
||||
|
||||
await CreateRoleActivity(activity);
|
||||
}
|
||||
|
||||
private async Task CreateRoleActivity(Models.Activity activity)
|
||||
{
|
||||
_logger.LogTrace("Creating activity {Activity}", activity);
|
||||
|
||||
// Activities are identified using their original message id
|
||||
await RespondAsync("`Création de l'activité en cours...`");
|
||||
|
||||
var response = await GetOriginalResponseAsync();
|
||||
activity.ActivityId = response.Id;
|
||||
|
||||
// Add activity to db
|
||||
await _activitiesRepository.AddActivity(activity);
|
||||
|
||||
// Add components
|
||||
var components = ActivityRoleComponent(activity.ActivityId);
|
||||
|
||||
await ModifyOriginalResponseAsync(m =>
|
||||
{
|
||||
m.Content = "";
|
||||
m.Components = components.Build();
|
||||
// m.Embed = embed.Build();
|
||||
});
|
||||
}
|
||||
|
||||
[ComponentInteraction("activity join_role:*", ignoreGroupNames: true)]
|
||||
private async Task JoinActivityRole(ulong activityId)
|
||||
{
|
||||
var user = (SocketGuildUser)Context.User;
|
||||
|
||||
// Check if activity exists
|
||||
if (await _activitiesRepository.FindActivity(activityId) is not { } activity)
|
||||
{
|
||||
await RespondAsync(
|
||||
ephemeral: true,
|
||||
embed: EmbedUtils.ErrorEmbed("Cette activité n'existe plus").Build()
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If player is already registered
|
||||
if (await _activitiesRepository.FindActivityRolePlayer(activityId, user.Id) is not null)
|
||||
{
|
||||
await RespondAsync(
|
||||
ephemeral: true,
|
||||
embed: EmbedUtils.ErrorEmbed("Vous êtes déjà inscrit à cette activité").Build()
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogTrace("Player {Player} joined activity {Id}", user.DisplayName, activityId);
|
||||
|
||||
var roles = _activityHelper.GetPlayerRoles(user.Roles);
|
||||
var activityRolePlayer = new ActivityRolePlayer { UserId = user.Id, PlayerName = user.DisplayName, Roles = roles, ActivityId = activityId, Activity = activity };
|
||||
|
||||
// Add player to activity
|
||||
activity.ActivityPlayers.Add(activityRolePlayer);
|
||||
await _activitiesRepository.SaveChanges();
|
||||
|
||||
await RespondAsync(
|
||||
ephemeral: true,
|
||||
embed: EmbedUtils.SuccessEmbed("Vous avez bien été inscrit pour cette activité").Build()
|
||||
);
|
||||
}
|
||||
|
||||
[ComponentInteraction("activity leave_role:*", ignoreGroupNames: true)]
|
||||
private async Task LeaveActivityRole(ulong activityId)
|
||||
{
|
||||
var user = (IGuildUser)Context.User;
|
||||
|
||||
// Check if activity exists
|
||||
if (await _activitiesRepository.FindActivity(activityId) is not { } activity)
|
||||
{
|
||||
await RespondAsync(
|
||||
ephemeral: true,
|
||||
embed: EmbedUtils.ErrorEmbed("Cette activité n'existe plus").Build()
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if player is in activity
|
||||
if (await _activitiesRepository.FindActivityPlayer(activityId, user.Id) is not { } activityPlayer)
|
||||
{
|
||||
await RespondAsync(
|
||||
ephemeral: true,
|
||||
embed: EmbedUtils.ErrorEmbed("Vous n'êtes pas inscrit à cette activité").Build()
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogTrace("Player {Player} left activity {Id}", user.DisplayName, activityId);
|
||||
|
||||
activity.ActivityPlayers.Remove(activityPlayer);
|
||||
await _activitiesRepository.SaveChanges();
|
||||
|
||||
await RespondAsync(
|
||||
ephemeral: true,
|
||||
embed: EmbedUtils.SuccessEmbed("Vous avez bien été désinscrit pour cette activité").Build()
|
||||
);
|
||||
}
|
||||
|
||||
[ComponentInteraction("activity event_join:*", ignoreGroupNames: true)]
|
||||
private async Task JoinEventActivity(ulong activityId)
|
||||
{
|
||||
_logger.LogTrace("Player {Player} joined activity {Id}", ((IGuildUser)Context.User).DisplayName, activityId);
|
||||
|
||||
await RespondAsync(activityId.ToString());
|
||||
}
|
||||
|
||||
private static ComponentBuilder ActivityRoleComponent(ulong activityId)
|
||||
{
|
||||
return new ComponentBuilder()
|
||||
.AddRow(new ActionRowBuilder()
|
||||
.WithButton(new ButtonBuilder()
|
||||
.WithLabel("Rejoindre l'activité")
|
||||
.WithCustomId($"activity join_role:{activityId}")
|
||||
.WithStyle(ButtonStyle.Primary)
|
||||
)
|
||||
.WithButton(new ButtonBuilder()
|
||||
.WithLabel("Se désinscrire de l'activité")
|
||||
.WithCustomId($"activity leave_role:{activityId}")
|
||||
.WithStyle(ButtonStyle.Danger)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
17
Cocotte/Modules/Activity/ActivityName.cs
Normal file
17
Cocotte/Modules/Activity/ActivityName.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
namespace Cocotte.Modules.Activity;
|
||||
|
||||
public enum ActivityName
|
||||
{
|
||||
Abyss,
|
||||
OriginsOfWar,
|
||||
Raids,
|
||||
FrontierClash,
|
||||
VoidRift,
|
||||
JointOperation,
|
||||
InterstellarExploration,
|
||||
BreakFromDestiny,
|
||||
CriticalAbyss,
|
||||
Fishing,
|
||||
Event,
|
||||
MirroriaRace
|
||||
}
|
||||
11
Cocotte/Modules/Activity/ActivityRoles.cs
Normal file
11
Cocotte/Modules/Activity/ActivityRoles.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Cocotte.Modules.Activity;
|
||||
|
||||
[Flags]
|
||||
public enum ActivityRoles : byte
|
||||
{
|
||||
None = 0b0000,
|
||||
Helper = 0b0001,
|
||||
Dps = 0b0010,
|
||||
Tank = 0b0100,
|
||||
Support = 0b1000
|
||||
}
|
||||
12
Cocotte/Modules/Activity/ActivityType.cs
Normal file
12
Cocotte/Modules/Activity/ActivityType.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace Cocotte.Modules.Activity;
|
||||
|
||||
public enum ActivityType
|
||||
{
|
||||
Pve4Players,
|
||||
Pve8Players,
|
||||
Pvp8Players,
|
||||
Pvp3Players,
|
||||
Event8Players,
|
||||
Event4Players,
|
||||
Other
|
||||
}
|
||||
45
Cocotte/Modules/Activity/Models/ActivitiesRepository.cs
Normal file
45
Cocotte/Modules/Activity/Models/ActivitiesRepository.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Cocotte.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Cocotte.Modules.Activity.Models;
|
||||
|
||||
public class ActivitiesRepository
|
||||
{
|
||||
private readonly CocotteContext _cocotteContext;
|
||||
|
||||
public ActivitiesRepository(CocotteContext cocotteContext)
|
||||
{
|
||||
_cocotteContext = cocotteContext;
|
||||
}
|
||||
|
||||
public async Task<Activity?> FindActivity(ulong activityId)
|
||||
{
|
||||
return await _cocotteContext.Activities.FindAsync(activityId);
|
||||
}
|
||||
|
||||
public async Task<StagedActivity?> FindStagedActivity(ulong activityId)
|
||||
{
|
||||
return await _cocotteContext.StagedActivities.FindAsync(activityId);
|
||||
}
|
||||
|
||||
public async Task<ActivityPlayer?> FindActivityPlayer(ulong activityId, ulong playerId)
|
||||
{
|
||||
return await _cocotteContext.ActivityPlayers.FindAsync(activityId, playerId);
|
||||
}
|
||||
|
||||
public async Task<ActivityRolePlayer?> FindActivityRolePlayer(ulong activityId, ulong playerId)
|
||||
{
|
||||
return await _cocotteContext.ActivityRolePlayers.FindAsync(activityId, playerId);
|
||||
}
|
||||
|
||||
public async Task AddActivity(Activity activity)
|
||||
{
|
||||
await _cocotteContext.AddAsync(activity);
|
||||
await _cocotteContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task SaveChanges()
|
||||
{
|
||||
await _cocotteContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
23
Cocotte/Modules/Activity/Models/Activity.cs
Normal file
23
Cocotte/Modules/Activity/Models/Activity.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Cocotte.Modules.Activity.Models;
|
||||
|
||||
public abstract class Activity
|
||||
{
|
||||
[Key]
|
||||
public ulong ActivityId { get; set; }
|
||||
|
||||
public ulong CreatorId { get; init; }
|
||||
public string? Description { get; init; }
|
||||
public ActivityType ActivityType { get; init; }
|
||||
public ActivityName ActivityName { get; init; }
|
||||
public uint MaxPlayers { get; set; }
|
||||
|
||||
public List<ActivityPlayer> ActivityPlayers { get; init; } = new();
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{nameof(ActivityId)}: {ActivityId}, {nameof(CreatorId)}: {CreatorId}, {nameof(Description)}: {Description}, {nameof(ActivityType)}: {ActivityType}, {nameof(ActivityName)}: {ActivityName}, {nameof(MaxPlayers)}: {MaxPlayers}";
|
||||
}
|
||||
}
|
||||
20
Cocotte/Modules/Activity/Models/ActivityPlayer.cs
Normal file
20
Cocotte/Modules/Activity/Models/ActivityPlayer.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Cocotte.Modules.Activity.Models;
|
||||
|
||||
[PrimaryKey(nameof(ActivityId), nameof(UserId))]
|
||||
public class ActivityPlayer
|
||||
{
|
||||
public ulong UserId { get; init; }
|
||||
|
||||
public required string PlayerName { get; init; }
|
||||
|
||||
public ulong ActivityId { get; init; }
|
||||
public required Activity Activity { get; init; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{nameof(UserId)}: {UserId}, {nameof(PlayerName)}: {PlayerName}";
|
||||
}
|
||||
}
|
||||
6
Cocotte/Modules/Activity/Models/ActivityRolePlayer.cs
Normal file
6
Cocotte/Modules/Activity/Models/ActivityRolePlayer.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Cocotte.Modules.Activity.Models;
|
||||
|
||||
public class ActivityRolePlayer : ActivityPlayer
|
||||
{
|
||||
public required ActivityRoles Roles { get; init; }
|
||||
}
|
||||
11
Cocotte/Modules/Activity/Models/StagedActivity.cs
Normal file
11
Cocotte/Modules/Activity/Models/StagedActivity.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Cocotte.Modules.Activity.Models;
|
||||
|
||||
public class StagedActivity : Activity
|
||||
{
|
||||
public uint Stage { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{base.ToString()}, {nameof(Stage)}: {Stage}";
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
using Cocotte.Options;
|
||||
using Cocotte.Utils;
|
||||
using Discord;
|
||||
using Discord.Interactions;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Cocotte.Modules.Groups;
|
||||
|
||||
/// <summary>
|
||||
/// Module to ask and propose groups for different activities: Abyss, OOW, FC, ...
|
||||
/// </summary>
|
||||
[Group("group", "Group related commands")]
|
||||
public class GroupModule : InteractionModuleBase<SocketInteractionContext>
|
||||
{
|
||||
private readonly ILogger<GroupModule> _logger;
|
||||
private readonly GroupsOptions _options;
|
||||
|
||||
public GroupModule(ILogger<GroupModule> logger, IOptions<GroupsOptions> options)
|
||||
{
|
||||
_logger = logger;
|
||||
_options = options.Value;
|
||||
}
|
||||
|
||||
[RequireOwner]
|
||||
[SlashCommand("test", "Test group module")]
|
||||
public async Task Test()
|
||||
{
|
||||
await RespondAsync("Module is active!!");
|
||||
}
|
||||
|
||||
[RequireOwner]
|
||||
[SlashCommand("setup-info", "Display group setup info")]
|
||||
public async Task SetupInfo()
|
||||
{
|
||||
await RespondAsync($"""
|
||||
- Helper: {MentionUtils.MentionRole(_options.HelperRoleId)} {_options.HelperEmote.ToEmote()}
|
||||
- Dps: {MentionUtils.MentionRole(_options.DpsRoleId)} {_options.DpsEmote.ToEmote()}
|
||||
- Tank: {MentionUtils.MentionRole(_options.TankRoleId)} {_options.TankEmote.ToEmote()}
|
||||
- Healer: {MentionUtils.MentionRole(_options.HealerRoleId)} {_options.HealerEmote.ToEmote()}
|
||||
""");
|
||||
}
|
||||
}
|
||||
18
Cocotte/Options/ActivityOptions.cs
Normal file
18
Cocotte/Options/ActivityOptions.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace Cocotte.Options;
|
||||
|
||||
public class ActivityOptions
|
||||
{
|
||||
public const string SectionName = "ActivityOptions";
|
||||
|
||||
public ulong HelperRoleId { get; init; }
|
||||
public required string HelperEmote { get; init; }
|
||||
|
||||
public ulong DpsRoleId { get; init; }
|
||||
public required string DpsEmote { get; init; }
|
||||
|
||||
public ulong TankRoleId { get; init; }
|
||||
public required string TankEmote { get; init; }
|
||||
|
||||
public ulong SupportRoleId { get; init; }
|
||||
public required string SupportEmote { get; init; }
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
namespace Cocotte.Options;
|
||||
|
||||
public class GroupsOptions
|
||||
{
|
||||
public const string SectionName = "GroupsOptions";
|
||||
|
||||
public ulong HelperRoleId { get; init; }
|
||||
public string HelperEmote { get; init; }
|
||||
|
||||
public ulong DpsRoleId { get; init; }
|
||||
public string DpsEmote { get; init; }
|
||||
|
||||
public ulong TankRoleId { get; init; }
|
||||
public string TankEmote { get; init; }
|
||||
|
||||
public ulong HealerRoleId { get; init; }
|
||||
public string HealerEmote { get; init; }
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
using Cocotte.Modules.Activity;
|
||||
using Cocotte.Modules.Activity.Models;
|
||||
using Cocotte.Modules.Raids;
|
||||
using Cocotte.Options;
|
||||
using Cocotte.Services;
|
||||
@@ -5,25 +7,31 @@ using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.Interactions;
|
||||
using Discord.WebSocket;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
DiscordSocketConfig discordSocketConfig = new()
|
||||
{
|
||||
LogLevel = LogSeverity.Debug,
|
||||
MessageCacheSize = 200,
|
||||
GatewayIntents = GatewayIntents.None
|
||||
GatewayIntents = GatewayIntents.AllUnprivileged
|
||||
};
|
||||
|
||||
IHost host = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureAppConfiguration((_, configuration) =>
|
||||
{
|
||||
configuration.AddJsonFile("discord.json", false, false);
|
||||
configuration.AddJsonFile("groups.json", false, false);
|
||||
configuration.AddJsonFile("activity.json", false, false);
|
||||
})
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
// Options
|
||||
services.Configure<DiscordOptions>(context.Configuration.GetSection(DiscordOptions.SectionName));
|
||||
services.Configure<GroupsOptions>(context.Configuration.GetSection(GroupsOptions.SectionName));
|
||||
services.Configure<ActivityOptions>(context.Configuration.GetSection(ActivityOptions.SectionName));
|
||||
|
||||
// Database
|
||||
services.AddDbContext<CocotteContext>(options =>
|
||||
options.UseSqlite(context.Configuration.GetConnectionString("CocotteContext")), ServiceLifetime.Transient, ServiceLifetime.Transient);
|
||||
services.AddTransient<ActivitiesRepository>();
|
||||
|
||||
// Discord.Net
|
||||
services.AddHostedService<DiscordLoggingService>();
|
||||
@@ -41,6 +49,8 @@ IHost host = Host.CreateDefaultBuilder(args)
|
||||
services.AddSingleton<RolesOptions>();
|
||||
|
||||
// Groups
|
||||
services.AddTransient<ActivityFormatter>();
|
||||
services.AddSingleton<ActivityHelper>();
|
||||
|
||||
// Raids
|
||||
services.AddTransient<RaidFormatter>();
|
||||
|
||||
18
Cocotte/Services/CocotteContext.cs
Normal file
18
Cocotte/Services/CocotteContext.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Cocotte.Modules.Activity.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Cocotte.Services;
|
||||
|
||||
public class CocotteContext : DbContext
|
||||
{
|
||||
public DbSet<Activity> Activities => Set<Activity>();
|
||||
public DbSet<StagedActivity> StagedActivities => Set<StagedActivity>();
|
||||
|
||||
public DbSet<ActivityPlayer> ActivityPlayers => Set<ActivityPlayer>();
|
||||
public DbSet<ActivityRolePlayer> ActivityRolePlayers => Set<ActivityRolePlayer>();
|
||||
|
||||
public CocotteContext(DbContextOptions<CocotteContext> options) : base(options)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,20 +15,20 @@ public class CocotteService : BackgroundService
|
||||
private readonly IHostApplicationLifetime _hostApplicationLifetime;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly DiscordOptions _options;
|
||||
private readonly GroupsOptions _groupOptions;
|
||||
private readonly ActivityOptions _activityOptions;
|
||||
private readonly InteractionService _interactionService;
|
||||
|
||||
public CocotteService(ILogger<CocotteService> logger, IServiceProvider serviceProvider,
|
||||
IHostEnvironment hostEnvironment,
|
||||
IHostApplicationLifetime hostApplicationLifetime, DiscordSocketClient client,
|
||||
IOptions<DiscordOptions> options, IOptions<GroupsOptions> groupOptions, InteractionService interactionService)
|
||||
IOptions<DiscordOptions> options, IOptions<ActivityOptions> groupOptions, InteractionService interactionService)
|
||||
{
|
||||
_logger = logger;
|
||||
_serviceProvider = serviceProvider;
|
||||
_hostApplicationLifetime = hostApplicationLifetime;
|
||||
_client = client;
|
||||
_options = options.Value;
|
||||
_groupOptions = groupOptions.Value;
|
||||
_activityOptions = groupOptions.Value;
|
||||
_interactionService = interactionService;
|
||||
_hostEnvironment = hostEnvironment;
|
||||
}
|
||||
@@ -66,10 +66,10 @@ public class CocotteService : BackgroundService
|
||||
private bool ValidateOptions()
|
||||
{
|
||||
// Validate group options
|
||||
if ((_groupOptions.HelperRoleId
|
||||
| _groupOptions.DpsRoleId
|
||||
| _groupOptions.TankRoleId
|
||||
| _groupOptions.HealerRoleId) == 0)
|
||||
if ((_activityOptions.HelperRoleId
|
||||
| _activityOptions.DpsRoleId
|
||||
| _activityOptions.TankRoleId
|
||||
| _activityOptions.SupportRoleId) == 0)
|
||||
{
|
||||
_logger.LogError("One of the group options id is invalid, it cannot be 0");
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"GroupsOptions": {
|
||||
"ActivityOptions": {
|
||||
"HelperRoleId": 0,
|
||||
"HelperEmote": "",
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"TankRoleId": 0,
|
||||
"TankEmote": "",
|
||||
|
||||
"HealerRoleId": 0,
|
||||
"HealerEmote": ""
|
||||
"SupportRoleId": 0,
|
||||
"SupportEmote": ""
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,8 @@
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"CocotteContext": "Data Source=cocotte.db"
|
||||
}
|
||||
}
|
||||
|
||||
BIN
Cocotte/cocotte.db
Normal file
BIN
Cocotte/cocotte.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user