Updated editorconfig to (mostly?) require braces around if/else statements, and applied the new formatting rules

This commit is contained in:
Kwoth
2022-02-02 01:44:45 +01:00
parent b22cd5a81e
commit ffa2c3f119
202 changed files with 2108 additions and 920 deletions

View File

@@ -26,8 +26,16 @@ public static class DiscordUserExtensions
TotalXp = 0,
CurrencyAmount = 0
},
old => new() { Username = username, Discriminator = discrim, AvatarId = avatarId },
() => new() { UserId = userId });
old => new()
{
Username = username,
Discriminator = discrim,
AvatarId = avatarId
},
() => new()
{
UserId = userId
});
//temp is only used in updatecurrencystate, so that i don't overwrite real usernames/discrims with Unknown
public static DiscordUser GetOrCreateUser(
@@ -72,7 +80,8 @@ public static class DiscordUserExtensions
public static void RemoveFromMany(this DbSet<DiscordUser> users, IEnumerable<ulong> ids)
{
var items = users.AsQueryable().Where(x => ids.Contains(x.UserId));
foreach (var item in items) item.CurrencyAmount = 0;
foreach (var item in items)
item.CurrencyAmount = 0;
}
public static bool TryUpdateCurrencyState(

View File

@@ -11,8 +11,16 @@ public static class GuildConfigExtensions
private static List<WarningPunishment> DefaultWarnPunishments
=> new()
{
new() { Count = 3, Punishment = PunishmentAction.Kick },
new() { Count = 5, Punishment = PunishmentAction.Ban }
new()
{
Count = 3,
Punishment = PunishmentAction.Kick
},
new()
{
Count = 5,
Punishment = PunishmentAction.Ban
}
};
/// <summary>
@@ -105,7 +113,10 @@ public static class GuildConfigExtensions
if (logSetting is null)
{
ctx.LogSettings.Add(logSetting = new() { GuildId = guildId });
ctx.LogSettings.Add(logSetting = new()
{
GuildId = guildId
});
ctx.SaveChanges();
}
@@ -128,7 +139,11 @@ public static class GuildConfigExtensions
if (config is null) // if there is no guildconfig, create new one
{
ctx.GuildConfigs.Add(config = new() { GuildId = guildId, Permissions = Permissionv2.GetDefaultPermlist });
ctx.GuildConfigs.Add(config = new()
{
GuildId = guildId,
Permissions = Permissionv2.GetDefaultPermlist
});
ctx.SaveChanges();
}
else if (config.Permissions is null || !config.Permissions.Any()) // if no perms, add default ones
@@ -181,7 +196,11 @@ public static class GuildConfigExtensions
.Include(x => x.GenerateCurrencyChannelIds)
.Where(x => x.GenerateCurrencyChannelIds.Any())
.SelectMany(x => x.GenerateCurrencyChannelIds)
.Select(x => new GeneratingChannel { ChannelId = x.ChannelId, GuildId = x.GuildConfig.GuildId })
.Select(x => new GeneratingChannel
{
ChannelId = x.ChannelId,
GuildId = x.GuildConfig.GuildId
})
.ToArray();
public class GeneratingChannel

View File

@@ -12,7 +12,11 @@ public static class MusicPlayerSettingsExtensions
if (toReturn is null)
{
var newSettings = new MusicPlayerSettings { GuildId = guildId, PlayerRepeat = PlayerRepeatType.Queue };
var newSettings = new MusicPlayerSettings
{
GuildId = guildId,
PlayerRepeat = PlayerRepeatType.Queue
};
await settings.AddAsync(newSettings);
return newSettings;

View File

@@ -13,6 +13,9 @@ public static class NadekoExpressionExtensions
public static IEnumerable<NadekoExpression> ForId(this DbSet<NadekoExpression> exprs, ulong id)
=> exprs.AsNoTracking().AsQueryable().Where(x => x.GuildId == id).ToList();
public static NadekoExpression GetByGuildIdAndInput(this DbSet<NadekoExpression> exprs, ulong? guildId, string input)
public static NadekoExpression GetByGuildIdAndInput(
this DbSet<NadekoExpression> exprs,
ulong? guildId,
string input)
=> exprs.FirstOrDefault(x => x.GuildId == guildId && x.Trigger.ToUpper() == input);
}

View File

@@ -15,7 +15,10 @@ public static class UserXpExtensions
if (usr is null)
ctx.Add(usr = new()
{
Xp = 0, UserId = userId, NotifyOnLevelUp = XpNotificationLocation.None, GuildId = guildId
Xp = 0,
UserId = userId,
NotifyOnLevelUp = XpNotificationLocation.None,
GuildId = guildId
});
return usr;

View File

@@ -38,7 +38,10 @@ public class Permissionv2 : DbEntity, IIndexed
};
public static List<Permissionv2> GetDefaultPermlist
=> new() { AllowAllPerm };
=> new()
{
AllowAllPerm
};
}
public enum PrimaryPermissionType

View File

@@ -32,7 +32,8 @@ public class ShopEntryItem : DbEntity
public override bool Equals(object obj)
{
if (obj is null || GetType() != obj.GetType()) return false;
if (obj is null || GetType() != obj.GetType())
return false;
return ((ShopEntryItem)obj).Text == Text;
}

View File

@@ -8,7 +8,8 @@ public class SlowmodeIgnoredRole : DbEntity
// override object.Equals
public override bool Equals(object obj)
{
if (obj is null || GetType() != obj.GetType()) return false;
if (obj is null || GetType() != obj.GetType())
return false;
return ((SlowmodeIgnoredRole)obj).RoleId == RoleId;
}

View File

@@ -8,7 +8,8 @@ public class SlowmodeIgnoredUser : DbEntity
// override object.Equals
public override bool Equals(object obj)
{
if (obj is null || GetType() != obj.GetType()) return false;
if (obj is null || GetType() != obj.GetType())
return false;
return ((SlowmodeIgnoredUser)obj).UserId == UserId;
}

View File

@@ -25,7 +25,8 @@ public class WaifuInfo : DbEntity
var waifuUsername = Waifu.Username.TrimTo(20);
var claimerUsername = Claimer?.Username.TrimTo(20);
if (ClaimerId is not null) claimer = $"{claimerUsername}#{Claimer.Discriminator}";
if (ClaimerId is not null)
claimer = $"{claimerUsername}#{Claimer.Discriminator}";
if (AffinityId is null)
status = $"... but {waifuUsername}'s heart is empty";
else if (AffinityId == ClaimerId)
@@ -58,7 +59,8 @@ public class WaifuLbResult
var waifuUsername = Username.TrimTo(20);
var claimerUsername = Claimer?.TrimTo(20);
if (Claimer is not null) claimer = $"{claimerUsername}#{ClaimerDiscrim}";
if (Claimer is not null)
claimer = $"{claimerUsername}#{ClaimerDiscrim}";
if (Affinity is null)
status = $"... but {waifuUsername}'s heart is empty";
else if (Affinity + AffinityDiscrim == Claimer + ClaimerDiscrim)

View File

@@ -62,7 +62,7 @@ public class NadekoContext : DbContext
public DbSet<NsfwBlacklistedTag> NsfwBlacklistedTags { get; set; }
public DbSet<AutoTranslateChannel> AutoTranslateChannels { get; set; }
public DbSet<AutoTranslateUser> AutoTranslateUsers { get; set; }
public DbSet<Permissionv2> Permissions { get; set; }
public NadekoContext(DbContextOptions<NadekoContext> options)
@@ -95,7 +95,12 @@ public class NadekoContext : DbContext
.HasForeignKey<AntiAltSetting>(x => x.GuildConfigId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<FeedSub>().HasAlternateKey(x => new { x.GuildConfigId, x.Url });
modelBuilder.Entity<FeedSub>()
.HasAlternateKey(x => new
{
x.GuildConfigId,
x.Url
});
modelBuilder.Entity<PlantedCurrency>().HasIndex(x => x.MessageId).IsUnique();
@@ -115,7 +120,12 @@ public class NadekoContext : DbContext
var selfassignableRolesEntity = modelBuilder.Entity<SelfAssignedRole>();
selfassignableRolesEntity.HasIndex(s => new { s.GuildId, s.RoleId }).IsUnique();
selfassignableRolesEntity.HasIndex(s => new
{
s.GuildId,
s.RoleId
})
.IsUnique();
selfassignableRolesEntity.Property(x => x.Group).HasDefaultValue(0);
@@ -160,7 +170,7 @@ public class NadekoContext : DbContext
du.Property(x => x.TotalXp)
.HasDefaultValue(0);
du.Property(x => x.CurrencyAmount)
.HasDefaultValue(0);
@@ -196,7 +206,12 @@ public class NadekoContext : DbContext
#region XpStats
var xps = modelBuilder.Entity<UserXpStats>();
xps.HasIndex(x => new { x.UserId, x.GuildId }).IsUnique();
xps.HasIndex(x => new
{
x.UserId,
x.GuildId
})
.IsUnique();
xps.Property(x => x.LastLevelUp)
.HasDefaultValue(new DateTime(2017, 9, 21, 20, 53, 13, 307, DateTimeKind.Local));
@@ -216,7 +231,13 @@ public class NadekoContext : DbContext
#region XpRoleReward
modelBuilder.Entity<XpRoleReward>().HasIndex(x => new { x.XpSettingsId, x.Level }).IsUnique();
modelBuilder.Entity<XpRoleReward>()
.HasIndex(x => new
{
x.XpSettingsId,
x.Level
})
.IsUnique();
#endregion
@@ -226,19 +247,33 @@ public class NadekoContext : DbContext
ci.HasOne(x => x.Owner).WithOne().HasForeignKey<ClubInfo>(x => x.OwnerId);
ci.HasAlternateKey(x => new { x.Name, x.Discrim });
ci.HasAlternateKey(x => new
{
x.Name,
x.Discrim
});
#endregion
#region ClubManytoMany
modelBuilder.Entity<ClubApplicants>().HasKey(t => new { t.ClubId, t.UserId });
modelBuilder.Entity<ClubApplicants>()
.HasKey(t => new
{
t.ClubId,
t.UserId
});
modelBuilder.Entity<ClubApplicants>().HasOne(pt => pt.User).WithMany();
modelBuilder.Entity<ClubApplicants>().HasOne(pt => pt.Club).WithMany(x => x.Applicants);
modelBuilder.Entity<ClubBans>().HasKey(t => new { t.ClubId, t.UserId });
modelBuilder.Entity<ClubBans>()
.HasKey(t => new
{
t.ClubId,
t.UserId
});
modelBuilder.Entity<ClubBans>().HasOne(pt => pt.User).WithMany();
@@ -264,12 +299,10 @@ public class NadekoContext : DbContext
e.Property(x => x.Type)
.IsRequired();
e.Property(x => x.Extra)
.IsRequired();
});
#endregion
@@ -281,7 +314,13 @@ public class NadekoContext : DbContext
#region GroupName
modelBuilder.Entity<GroupName>().HasIndex(x => new { x.GuildConfigId, x.Number }).IsUnique();
modelBuilder.Entity<GroupName>()
.HasIndex(x => new
{
x.GuildConfigId,
x.Number
})
.IsUnique();
modelBuilder.Entity<GroupName>()
.HasOne(x => x.GuildConfig)
@@ -298,7 +337,13 @@ public class NadekoContext : DbContext
#region Perm Override
modelBuilder.Entity<DiscordPermOverride>().HasIndex(x => new { x.GuildId, x.Command }).IsUnique();
modelBuilder.Entity<DiscordPermOverride>()
.HasIndex(x => new
{
x.GuildId,
x.Command
})
.IsUnique();
#endregion
@@ -329,7 +374,12 @@ public class NadekoContext : DbContext
.OnDelete(DeleteBehavior.Cascade));
modelBuilder.Entity<IgnoredLogItem>(ili => ili
.HasIndex(x => new { x.LogSettingId, x.LogItemId, x.ItemType })
.HasIndex(x => new
{
x.LogSettingId,
x.LogItemId,
x.ItemType
})
.IsUnique());
#endregion
@@ -345,8 +395,11 @@ public class NadekoContext : DbContext
atch.HasMany(x => x.Users).WithOne(x => x.Channel).OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<AutoTranslateUser>(atu => atu.HasAlternateKey(x => new { x.ChannelId, x.UserId }));
modelBuilder.Entity<AutoTranslateUser>(atu => atu.HasAlternateKey(x => new
{
x.ChannelId,
x.UserId
}));
}
#if DEBUG