Skip to content

Commit

Permalink
Updated lavalink
Browse files Browse the repository at this point in the history
  • Loading branch information
FeroxFoxxo committed Apr 9, 2024
1 parent 309fc89 commit 54c4871
Show file tree
Hide file tree
Showing 57 changed files with 701 additions and 715 deletions.
2 changes: 1 addition & 1 deletion backend/AutoMods/Controllers/AutoModEventController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class AutoModEventController(IdentityManager identityManager, AutoModEven

[HttpGet]
public async Task<IActionResult> GetAllItems([FromRoute] ulong guildId,
[FromQuery] [Range(0, int.MaxValue)] int startPage = 0)
[FromQuery][Range(0, int.MaxValue)] int startPage = 0)
{
var identity = await SetupAuthentication();

Expand Down
14 changes: 6 additions & 8 deletions backend/AutoMods/Extensions/SearchContains.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ namespace AutoMods.Extensions;
public static class SearchContains
{
public static bool Search(this string search, AutoModEventExpanded obj) =>
obj == null
? false
: search.Search(obj.AutoModEvent) ||
search.Search(obj.Suspect);
obj != null
&& (search.Search(obj.AutoModEvent) ||
search.Search(obj.Suspect));

public static bool Search(this string search, AutoModEvent obj) =>
obj == null
? false
: search.Search(obj.AutoModAction.ToString()) ||
obj != null
&& (search.Search(obj.AutoModAction.ToString()) ||
search.Search(obj.AutoModType.ToString()) ||
search.Search(obj.CreatedAt) ||
search.Search(obj.Username) ||
search.Search(obj.Nickname) ||
search.Search(obj.UserId) ||
search.Search(obj.MessageContent) ||
search.Search(obj.MessageId);
search.Search(obj.MessageId));
}
2 changes: 1 addition & 1 deletion backend/AutoMods/MessageChecks/EmbedCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace AutoMods.MessageChecks;

public static class EmbedCheck
{
public static bool Check(IMessage message, AutoModConfig config, DiscordSocketClient _) => config.Limit == null ? false : message.Embeds == null ? false : message.Embeds.Count > config.Limit;
public static bool Check(IMessage message, AutoModConfig config, DiscordSocketClient _) => config.Limit != null && message.Embeds != null && message.Embeds.Count > config.Limit;
}
2 changes: 1 addition & 1 deletion backend/AutoMods/MessageChecks/MentionCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ namespace AutoMods.MessageChecks;

public static class MentionCheck
{
public static bool Check(IMessage message, AutoModConfig config, DiscordSocketClient _) => config.Limit == null ? false : message.MentionedUserIds == null ? false : message.MentionedUserIds.Count > config.Limit;
public static bool Check(IMessage message, AutoModConfig config, DiscordSocketClient _) => config.Limit != null && message.MentionedUserIds != null && message.MentionedUserIds.Count > config.Limit;
}
130 changes: 65 additions & 65 deletions backend/AutoMods/Migrations/20220225095748_InitialCreate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,74 +7,74 @@ namespace AutoMods.Migrations;

public partial class InitialCreate : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "AutoMods");
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "AutoMods");

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

migrationBuilder.CreateTable(
name: "AutoModConfigs",
schema: "AutoMods",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
GuildId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
AutoModType = table.Column<int>(type: "int", nullable: false),
AutoModAction = table.Column<int>(type: "int", nullable: false),
PunishmentType = table.Column<int>(type: "int", nullable: true),
PunishmentDurationMinutes = table.Column<int>(type: "int", nullable: true),
IgnoreChannels = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
IgnoreRoles = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
TimeLimitMinutes = table.Column<int>(type: "int", nullable: true),
Limit = table.Column<int>(type: "int", nullable: true),
CustomWordFilter = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
ChannelNotificationBehavior = table.Column<int>(type: "int", nullable: false)
},
constraints: table => table.PrimaryKey("PK_AutoModConfigs", x => x.Id))
.Annotation("MySql:CharSet", "utf8mb4");
migrationBuilder.CreateTable(
name: "AutoModConfigs",
schema: "AutoMods",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
GuildId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
AutoModType = table.Column<int>(type: "int", nullable: false),
AutoModAction = table.Column<int>(type: "int", nullable: false),
PunishmentType = table.Column<int>(type: "int", nullable: true),
PunishmentDurationMinutes = table.Column<int>(type: "int", nullable: true),
IgnoreChannels = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
IgnoreRoles = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
TimeLimitMinutes = table.Column<int>(type: "int", nullable: true),
Limit = table.Column<int>(type: "int", nullable: true),
CustomWordFilter = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
ChannelNotificationBehavior = table.Column<int>(type: "int", nullable: false)
},
constraints: table => table.PrimaryKey("PK_AutoModConfigs", x => x.Id))
.Annotation("MySql:CharSet", "utf8mb4");

migrationBuilder.CreateTable(
name: "AutoModEvents",
schema: "AutoMods",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
GuildId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
AutoModType = table.Column<int>(type: "int", nullable: false),
AutoModAction = table.Column<int>(type: "int", nullable: false),
UserId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
Username = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Nickname = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Discriminator = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
MessageId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
MessageContent = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
AssociatedCaseId = table.Column<int>(type: "int", nullable: true)
},
constraints: table => table.PrimaryKey("PK_AutoModEvents", x => x.Id))
.Annotation("MySql:CharSet", "utf8mb4");
}
migrationBuilder.CreateTable(
name: "AutoModEvents",
schema: "AutoMods",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
GuildId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
AutoModType = table.Column<int>(type: "int", nullable: false),
AutoModAction = table.Column<int>(type: "int", nullable: false),
UserId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
Username = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Nickname = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
Discriminator = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
MessageId = table.Column<ulong>(type: "bigint unsigned", nullable: false),
MessageContent = table.Column<string>(type: "longtext", nullable: true)
.Annotation("MySql:CharSet", "utf8mb4"),
CreatedAt = table.Column<DateTime>(type: "datetime(6)", nullable: false),
AssociatedCaseId = table.Column<int>(type: "int", nullable: true)
},
constraints: table => table.PrimaryKey("PK_AutoModEvents", x => x.Id))
.Annotation("MySql:CharSet", "utf8mb4");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AutoModConfigs",
schema: "AutoMods");
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AutoModConfigs",
schema: "AutoMods");

migrationBuilder.DropTable(
name: "AutoModEvents",
schema: "AutoMods");
}
migrationBuilder.DropTable(
name: "AutoModEvents",
schema: "AutoMods");
}
}
2 changes: 1 addition & 1 deletion backend/AutoMods/Services/AutoModChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private async Task<bool> FinaliseAutoMod(AutoModConfig autoModConfig, IMessage m

if (modType != AutoModType.TooManyAutomods)
await CheckAutoMod(AutoModType.TooManyAutomods, message, CheckMultipleEvents, scope);

return true;
}

Expand Down
18 changes: 9 additions & 9 deletions backend/Bot/Abstractions/DataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
FloatArrayComparer floatArrayComparer = new();

foreach (var entityType in modelBuilder.Model.GetEntityTypes())
foreach (var property in entityType.GetProperties())
{
if (property.ClrType == typeof(ulong[]))
property.SetValueComparer(ulongArrayComparer);
else if (property.ClrType == typeof(string[]))
property.SetValueComparer(stringArrayComparer);
else if (property.ClrType == typeof(float[]))
property.SetValueComparer(floatArrayComparer);
}
foreach (var property in entityType.GetProperties())
{
if (property.ClrType == typeof(ulong[]))
property.SetValueComparer(ulongArrayComparer);
else if (property.ClrType == typeof(string[]))
property.SetValueComparer(stringArrayComparer);
else if (property.ClrType == typeof(float[]))
property.SetValueComparer(floatArrayComparer);
}

OverrideModelCreating(modelBuilder);
}
Expand Down
2 changes: 1 addition & 1 deletion backend/Bot/Abstractions/DataConverters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Bot.Abstractions;

public class JsonDataConverter<T> : ValueConverter<T, string>
public class JsonDataConverter<T> : ValueConverter<T, string>
{
public JsonDataConverter() : base(
v => JsonConvert.SerializeObject(v),
Expand Down
1 change: 0 additions & 1 deletion backend/Bot/Bot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.14.1" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Lavalink4NET.Integrations.Lavasrc" Version="4.0.17" />

<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.3" />
Expand Down
2 changes: 1 addition & 1 deletion backend/Bot/BotModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public override void PostWebBuild(WebApplication app, AppSettings settings)
options.RoutePrefix = string.Empty;
});
}

app.UseMiddleware<HeaderMiddleware>();
app.UseMiddleware<RequestLoggingMiddleware>();
app.UseMiddleware<ApiExceptionHandlingMiddleware>();
Expand Down
2 changes: 1 addition & 1 deletion backend/Bot/Controllers/BotEnumControllers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public async Task<IActionResult> ApiError([FromQuery] Language? language = null)
await TranslateEnum<ApiError>(language);

[HttpGet("editstatus")]
public async Task<IActionResult> ViewEditStatus([FromQuery] Language? language = null) =>
public async Task<IActionResult> ViewEditStatus([FromQuery] Language? language = null) =>
await TranslateEnum<EditStatus>(language);

[HttpGet("language")]
Expand Down
6 changes: 3 additions & 3 deletions backend/Bot/Controllers/StatusController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public async Task<IActionResult> Status()
{
var config = await _settingsRepository.GetAppSettings();

if (!HttpContext.Request.Headers.TryGetValue("Accept", out var value)) return Ok("OK");

return value.ToString().Search("application/json")
return !HttpContext.Request.Headers.TryGetValue("Accept", out var value)
? Ok("OK")
: value.ToString().Search("application/json")
? Ok(new
{
status = "OK",
Expand Down
2 changes: 1 addition & 1 deletion backend/Bot/Controllers/UserNetworkController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class UserNetworkController(GuildConfigRepository guildConfigRepository,
private readonly IServiceProvider _serviceProvider = serviceProvider;

[HttpGet("user")]
public async Task<IActionResult> GetUserNetwork([FromQuery] [Required] ulong userId)
public async Task<IActionResult> GetUserNetwork([FromQuery][Required] ulong userId)
{
var identity = await SetupAuthentication();

Expand Down
17 changes: 7 additions & 10 deletions backend/Bot/Identities/DiscordCommandIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ public override async Task<bool> HasAdminRoleOnGuild(ulong guildId)

var guildUser = GetGuildMembership(guildId);

return guildUser is null
? false
: guildUser.Guild.OwnerId == guildUser.Id ||
guildUser.RoleIds.Any(x => guildConfig.AdminRoles.Contains(x));
return guildUser is not null
&& (guildUser.Guild.OwnerId == guildUser.Id ||
guildUser.RoleIds.Any(x => guildConfig.AdminRoles.Contains(x)));
}
catch (ResourceNotFoundException)
{
Expand All @@ -75,12 +74,10 @@ public override async Task<bool> HasModRoleOrHigherOnGuild(ulong guildId)

var guildUser = GetGuildMembership(guildId);

return guildUser is null
? false
: guildUser.Guild.OwnerId == guildUser.Id
? true
: guildUser.RoleIds.Any(x => guildConfig.AdminRoles.Contains(x) ||
guildConfig.ModRoles.Contains(x));
return guildUser is not null
&& (guildUser.Guild.OwnerId == guildUser.Id
|| guildUser.RoleIds.Any(x => guildConfig.AdminRoles.Contains(x) ||
guildConfig.ModRoles.Contains(x)));
}
catch (ResourceNotFoundException)
{
Expand Down
17 changes: 7 additions & 10 deletions backend/Bot/Identities/DiscordOAuthIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ public override async Task<bool> HasAdminRoleOnGuild(ulong guildId)

var guildUser = GetGuildMembership(guildId);

return guildUser is null
? false
: guildUser.Guild.OwnerId == guildUser.Id ||
guildUser.RoleIds.Any(x => guildConfig.AdminRoles.Contains(x));
return guildUser is not null
&& (guildUser.Guild.OwnerId == guildUser.Id ||
guildUser.RoleIds.Any(x => guildConfig.AdminRoles.Contains(x)));
}
catch (ResourceNotFoundException)
{
Expand All @@ -107,12 +106,10 @@ public override async Task<bool> HasModRoleOrHigherOnGuild(ulong guildId)

var guildUser = GetGuildMembership(guildId);

return guildUser is null
? false
: guildUser.Guild.OwnerId == guildUser.Id
? true
: guildUser.RoleIds.Any(x => guildConfig.AdminRoles.Contains(x) ||
guildConfig.ModRoles.Contains(x));
return guildUser is not null
&& (guildUser.Guild.OwnerId == guildUser.Id
|| guildUser.RoleIds.Any(x => guildConfig.AdminRoles.Contains(x) ||
guildConfig.ModRoles.Contains(x)));
}
catch (ResourceNotFoundException)
{
Expand Down
Loading

0 comments on commit 54c4871

Please sign in to comment.