Skip to content

Commit

Permalink
Fix aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
minisbett committed Dec 31, 2023
1 parent 6dc23be commit 24fb5d2
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 135 deletions.
10 changes: 5 additions & 5 deletions huisbot/Embeds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public static Embed LinkSuccessful(OsuUser user) => BaseEmbed
/// </summary>
/// <param name="aliases">The beatmap aliases.</param>
/// <returns>An embed for displaying the beatmap aliases.</returns>
public static Embed BeatmapAliases(IDAlias[] aliases)
public static Embed BeatmapAliases(BeatmapAlias[] aliases)
{
// Sort the aliases by alphabetical order.
aliases = aliases.OrderBy(x => x.Alias).ToArray();
Expand All @@ -226,7 +226,7 @@ public static Embed BeatmapAliases(IDAlias[] aliases)
if (aliases.Length > 0)
{
aliasesStr = "";
foreach (IGrouping<int, IDAlias> group in aliases.GroupBy(x => x.Id))
foreach (IGrouping<long, BeatmapAlias> group in aliases.GroupBy(x => x.BeatmapId))
aliasesStr += $"[{group.First().DisplayName}](https://osu.ppy.sh/b/{group.Key})\n{string.Join(", ", group.Select(j => $"`{j.Alias}`"))}\n\n";
}

Expand All @@ -241,17 +241,17 @@ public static Embed BeatmapAliases(IDAlias[] aliases)
/// </summary>
/// <param name="aliases">The score aliases.</param>
/// <returns>An embed for displaying the score aliases.</returns>
public static Embed ScoreAliases(IDAlias[] aliases)
public static Embed ScoreAliases(ScoreAlias[] aliases)
{
// Sort the aliases by alphabetical order.
aliases = aliases.OrderBy(x => x.Alias).ToArray();

// Build the alias string.
string aliasesStr = "*There are no score aliases. You can add some via `/alias score add`.*";
if (aliases.Length > 0)
if (aliases.Length > 0)
{
aliasesStr = "";
foreach (IGrouping<long, IDAlias> group in aliases.GroupBy(x => x.Id))
foreach (IGrouping<long, ScoreAlias> group in aliases.GroupBy(x => x.ScoreId))
aliasesStr += $"[{group.First().DisplayName}](https://osu.ppy.sh/scores/osu/{group.Key})\n{string.Join(", ", group.Select(j => $"`{j.Alias}`"))}\n\n";
}

Expand Down
50 changes: 0 additions & 50 deletions huisbot/Migrations/20231122013527_AddScoreAliases.cs

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions huisbot/Migrations/20231231232112_AddScoreAliases.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace huisbot.Migrations
{
/// <inheritdoc />
public partial class AddScoreAliases : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "id",
table: "beatmap_aliases",
newName: "beatmap_id");

migrationBuilder.CreateTable(
name: "score_aliases",
columns: table => new
{
alias = table.Column<string>(type: "TEXT", nullable: false),
score_id = table.Column<long>(type: "INTEGER", nullable: false),
display_name = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_score_aliases", x => x.alias);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "score_aliases");

migrationBuilder.RenameColumn(
name: "beatmap_id",
table: "beatmap_aliases",
newName: "id");
}
}
}
35 changes: 28 additions & 7 deletions huisbot/Migrations/DatabaseModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ protected override void BuildModel(ModelBuilder modelBuilder)
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.13");

modelBuilder.Entity("huisbot.Models.Utility.IDAlias", b =>
modelBuilder.Entity("huisbot.Models.Utility.BeatmapAlias", b =>
{
b.Property<string>("Alias")
.HasColumnType("TEXT")
.HasColumnName("alias");
b.Property<long>("BeatmapId")
.HasColumnType("INTEGER")
.HasColumnName("beatmap_id");
b.Property<string>("DisplayName")
.IsRequired()
.HasColumnType("TEXT")
.HasColumnName("display_name");
b.Property<long>("Id")
.HasColumnType("INTEGER")
.HasColumnName("id");
b.HasKey("Alias")
.HasName("pk_id_alias");
.HasName("pk_beatmap_aliases");
b.ToTable("id_alias", (string)null);
b.ToTable("beatmap_aliases", (string)null);
});

modelBuilder.Entity("huisbot.Models.Utility.OsuDiscordLink", b =>
Expand All @@ -53,6 +53,27 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("osu_discord_links", (string)null);
});

modelBuilder.Entity("huisbot.Models.Utility.ScoreAlias", b =>
{
b.Property<string>("Alias")
.HasColumnType("TEXT")
.HasColumnName("alias");
b.Property<string>("DisplayName")
.IsRequired()
.HasColumnType("TEXT")
.HasColumnName("display_name");
b.Property<long>("ScoreId")
.HasColumnType("INTEGER")
.HasColumnName("score_id");
b.HasKey("Alias")
.HasName("pk_score_aliases");
b.ToTable("score_aliases", (string)null);
});
#pragma warning restore 612, 618
}
}
Expand Down
38 changes: 38 additions & 0 deletions huisbot/Models/Utility/BeatmapAlias.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.ComponentModel.DataAnnotations;

namespace huisbot.Models.Utility;

/// <summary>
/// Represents an alias to be used instead of a beatmap ID in order to provide easier access.
/// </summary>
public class BeatmapAlias
{
/// <summary>
/// The unique alias.
/// </summary>
[Key]
public string Alias { get; set; }

/// <summary>
/// The beatmap ID the alias represents.
/// </summary>
public long BeatmapId { get; set; }

/// <summary>
/// The display name of the object associated with the beatmap ID, used for display purposes.
/// </summary>
public string DisplayName { get; set; }

/// <summary>
/// Creates a new <see cref="BeatmapAlias"/> object with the specified beatmap ID, alias for it and display name.
/// </summary>
/// <param name="alias">The alias.</param>
/// <param name="beatmapId">The beatmap ID the alias represents.</param>
/// <param name="displayName">The display name of the beatmap.</param>
public BeatmapAlias(string alias, long beatmapId, string displayName)
{
Alias = alias;
BeatmapId = beatmapId;
DisplayName = displayName;
}
}
38 changes: 0 additions & 38 deletions huisbot/Models/Utility/IDAlias.cs

This file was deleted.

38 changes: 38 additions & 0 deletions huisbot/Models/Utility/ScoreAlias.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.ComponentModel.DataAnnotations;

namespace huisbot.Models.Utility;

/// <summary>
/// Represents an alias to be used instead of a score ID in order to provide easier access.
/// </summary>
public class ScoreAlias
{
/// <summary>
/// The unique alias.
/// </summary>
[Key]
public string Alias { get; set; }

/// <summary>
/// The score ID the alias represents.
/// </summary>
public long ScoreId { get; set; }

/// <summary>
/// The display name of the object associated with the score ID, used for display purposes.
/// </summary>
public string DisplayName { get; set; }

/// <summary>
/// Creates a new <see cref="ScoreAlias"/> object with the specified score ID, alias for it and display name.
/// </summary>
/// <param name="alias">The alias.</param>
/// <param name="scoreId">The score ID the alias represents.</param>
/// <param name="displayName">The display name of the score.</param>
public ScoreAlias(string alias, long scoreId, string displayName)
{
Alias = alias;
ScoreId = scoreId;
DisplayName = displayName;
}
}
Loading

0 comments on commit 24fb5d2

Please sign in to comment.