Skip to content

Commit

Permalink
Added value for servername
Browse files Browse the repository at this point in the history
  • Loading branch information
FeroxFoxxo committed Oct 20, 2023
1 parent 4db12a3 commit 258eae3
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 147 deletions.
5 changes: 1 addition & 4 deletions backend/Bot/Services/DiscordRest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,7 @@ public async Task SendDmMessage(ulong userId, string content)

public Dictionary<string, CacheApiResponse> GetCache() => _cache;

public void RemoveFromCache(CacheKey key)
{
_cache.Remove(key.GetValue());
}
public void RemoveFromCache(CacheKey key) => _cache.Remove(key.GetValue());

public T GetFromCache<T>(CacheKey key)
=> _cache.ContainsKey(key.GetValue()) ? _cache[key.GetValue()].GetContent<T>()
Expand Down
72 changes: 34 additions & 38 deletions backend/JoinLeave/Migrations/20231020214811_InitialCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,44 @@

#nullable disable

namespace JoinLeave.Migrations
namespace JoinLeave.Migrations;

/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
public partial class InitialCreate : Migration
protected override void Up(MigrationBuilder migrationBuilder)
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "JoinLeave");

migrationBuilder.AlterDatabase()
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.EnsureSchema(
name: "JoinLeave");

migrationBuilder.CreateTable(
name: "JoinLeaveConfig",
schema: "JoinLeave",
columns: table => new
{
GuildId = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Enabled = table.Column<bool>(type: "tinyint(1)", nullable: false),
JoinMessage = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
JoinChannelId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
LeaveMessage = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
LeaveChannelId = table.Column<ulong>(type: "bigint unsigned", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_JoinLeaveConfig", x => x.GuildId);
})
.Annotation("MySql:CharSet", "utf8mb4");
}
migrationBuilder.AlterDatabase()
.Annotation("MySql:CharSet", "utf8mb4");

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "JoinLeaveConfig",
schema: "JoinLeave");
}
migrationBuilder.CreateTable(
name: "JoinLeaveConfig",
schema: "JoinLeave",
columns: table => new
{
GuildId = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
Enabled = table.Column<bool>(type: "tinyint(1)", nullable: false),
JoinMessage = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
JoinChannelId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
LeaveMessage = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
LeaveChannelId = table.Column<ulong>(type: "bigint unsigned", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_JoinLeaveConfig", x => x.GuildId);
})
.Annotation("MySql:CharSet", "utf8mb4");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) => migrationBuilder.DropTable(
name: "JoinLeaveConfig",
schema: "JoinLeave");
}

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

34 changes: 34 additions & 0 deletions backend/JoinLeave/Migrations/20231020222543_GuildIdToUlong.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace JoinLeave.Migrations;

/// <inheritdoc />
public partial class GuildIdToUlong : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) => migrationBuilder.AlterColumn<ulong>(
name: "GuildId",
schema: "JoinLeave",
table: "JoinLeaveConfig",
type: "bigint unsigned",
nullable: false,
oldClrType: typeof(int),
oldType: "int")
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn)
.OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn);

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) => migrationBuilder.AlterColumn<int>(
name: "GuildId",
schema: "JoinLeave",
table: "JoinLeaveConfig",
type: "int",
nullable: false,
oldClrType: typeof(ulong),
oldType: "bigint unsigned")
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn)
.OldAnnotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)

modelBuilder.Entity("JoinLeave.Models.JoinLeaveConfig", b =>
{
b.Property<int>("GuildId")
b.Property<ulong>("GuildId")
.ValueGeneratedOnAdd()
.HasColumnType("int");
.HasColumnType("bigint unsigned");

b.Property<bool>("Enabled")
.HasColumnType("tinyint(1)");
Expand Down
2 changes: 1 addition & 1 deletion backend/JoinLeave/Models/JoinLeaveConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace JoinLeave.Models;

public class JoinLeaveConfig
{
[Key] public int GuildId { get; set; }
[Key] public ulong GuildId { get; set; }

public bool Enabled { get; set; }

Expand Down
2 changes: 2 additions & 0 deletions backend/JoinLeave/Services/JoinLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private async Task MemberJoined(SocketGuildUser user)
if (channel != null)
{
var message = config.JoinMessage
.Replace("{SERVERNAME}", user.Guild.Name)
.Replace("{USERNAME}", user.Username)
.Replace("{MENTION}", user.Mention);

Expand All @@ -52,6 +53,7 @@ private async Task MemberLeft(SocketGuild guild, SocketUser user)
if (channel != null)
{
var message = config.LeaveMessage
.Replace("{SERVERNAME}", guild.Name)
.Replace("{USERNAME}", user.Username)
.Replace("{MENTION}", user.Mention);

Expand Down
Loading

0 comments on commit 258eae3

Please sign in to comment.