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

@@ -337,7 +337,8 @@ public partial class Xp
var embed = _eb.Create().WithTitle(GetText(strs.club_leaderboard(page + 1))).WithOkColor();
var i = page * 9;
foreach (var club in clubs) embed.AddField($"#{++i} " + club, club.Xp + " xp");
foreach (var club in clubs)
embed.AddField($"#{++i} " + club, club.Xp + " xp");
return ctx.Channel.EmbedAsync(embed);
}

View File

@@ -28,7 +28,12 @@ public class ClubService : INService
if (xp.Level >= 5 && du.Club is null)
{
du.IsClubAdmin = true;
du.Club = new() { Name = clubName, Discrim = uow.Clubs.GetNextDiscrim(clubName), Owner = du };
du.Club = new()
{
Name = clubName,
Discrim = uow.Clubs.GetNextDiscrim(clubName),
Owner = du
};
uow.Clubs.Add(du.Club);
uow.SaveChanges();
}
@@ -142,7 +147,11 @@ public class ClubService : INService
// or doesn't min minumum level requirement, can't apply
return false;
var app = new ClubApplicants { ClubId = club.Id, UserId = du.Id };
var app = new ClubApplicants
{
ClubId = club.Id,
UserId = du.Id
};
uow.Set<ClubApplicants>().Add(app);
@@ -254,7 +263,11 @@ public class ClubService : INService
|| (usr.IsClubAdmin && club.Owner.UserId != bannerId)) // can't ban the owner kek, whew
return false;
club.Bans.Add(new() { Club = club, User = usr });
club.Bans.Add(new()
{
Club = club,
User = usr
});
club.Users.Remove(usr);
var app = club.Applicants.FirstOrDefault(x => x.UserId == usr.Id);

View File

@@ -164,9 +164,11 @@ public partial class Xp : NadekoModule<XpService>
private string GetNotifLocationString(XpNotificationLocation loc)
{
if (loc == XpNotificationLocation.Channel) return GetText(strs.xpn_notif_channel);
if (loc == XpNotificationLocation.Channel)
return GetText(strs.xpn_notif_channel);
if (loc == XpNotificationLocation.Dm) return GetText(strs.xpn_notif_dm);
if (loc == XpNotificationLocation.Dm)
return GetText(strs.xpn_notif_dm);
return GetText(strs.xpn_notif_disabled);
}
@@ -323,7 +325,8 @@ public partial class Xp : NadekoModule<XpService>
else
users = _service.GetUserXps(ctx.Guild.Id, curPage);
if (!users.Any()) return embed.WithDescription("-");
if (!users.Any())
return embed.WithDescription("-");
for (var i = 0; i < users.Count; i++)
{

View File

@@ -7,6 +7,7 @@ public sealed class XpConfigService : ConfigServiceBase<XpConfig>
{
private const string FILE_PATH = "data/xp.yml";
private static readonly TypedKey<XpConfig> _changeKey = new("config.xp.updated");
public override string Name
=> "xp";

View File

@@ -116,7 +116,8 @@ public class XpService : INService
// Scan guilds on startup.
_client.GuildAvailable += Client_OnGuildAvailable;
foreach (var guild in _client.Guilds) Client_OnGuildAvailable(guild);
foreach (var guild in _client.Guilds)
Client_OnGuildAvailable(guild);
#endif
_updateXpTask = Task.Run(UpdateLoop);
}
@@ -135,10 +136,12 @@ public class XpService : INService
var curRewards = new Dictionary<ulong, List<XpCurrencyReward>>();
var toAddTo = new List<UserCacheItem>();
while (_addMessageXp.TryDequeue(out var usr)) toAddTo.Add(usr);
while (_addMessageXp.TryDequeue(out var usr))
toAddTo.Add(usr);
var group = toAddTo.GroupBy(x => (GuildId: x.Guild.Id, x.User));
if (toAddTo.Count == 0) continue;
if (toAddTo.Count == 0)
continue;
await using (var uow = _db.GetDbContext())
{
@@ -156,7 +159,8 @@ public class XpService : INService
var oldGuildLevelData = new LevelStats(usr.Xp + usr.AwardedXp);
usr.Xp += xp;
du.TotalXp += xp;
if (du.Club is not null) du.Club.Xp += xp;
if (du.Club is not null)
du.Club.Xp += xp;
var newGuildLevelData = new LevelStats(usr.Xp + usr.AwardedXp);
if (oldGlobalLevelData.Level < newGlobalLevelData.Level)
@@ -302,7 +306,11 @@ public class XpService : INService
if (rew is not null)
rew.Amount = amount;
else
settings.CurrencyRewards.Add(new() { Level = level, Amount = amount });
settings.CurrencyRewards.Add(new()
{
Level = level,
Amount = amount
});
}
uow.SaveChanges();
@@ -354,7 +362,12 @@ public class XpService : INService
}
else
{
settings.RoleRewards.Add(new() { Level = level, RoleId = roleId, Remove = remove });
settings.RoleRewards.Add(new()
{
Level = level,
RoleId = roleId,
Remove = remove
});
}
uow.SaveChanges();
@@ -411,7 +424,8 @@ public class XpService : INService
{
Task.Run(() =>
{
foreach (var channel in guild.VoiceChannels) ScanChannelForVoiceXp(channel);
foreach (var channel in guild.VoiceChannels)
ScanChannelForVoiceXp(channel);
});
return Task.CompletedTask;
@@ -422,9 +436,10 @@ public class XpService : INService
if (socketUser is not SocketGuildUser user || user.IsBot)
return Task.CompletedTask;
_= Task.Run(() =>
_ = Task.Run(() =>
{
if (before.VoiceChannel is not null) ScanChannelForVoiceXp(before.VoiceChannel);
if (before.VoiceChannel is not null)
ScanChannelForVoiceXp(before.VoiceChannel);
if (after.VoiceChannel is not null && after.VoiceChannel != before.VoiceChannel)
ScanChannelForVoiceXp(after.VoiceChannel);
@@ -482,7 +497,8 @@ public class XpService : INService
_cache.Redis.GetDatabase().KeyDelete(key);
// Allow for if this function gets called multiple times when a user leaves a channel.
if (value.IsNull) return;
if (value.IsNull)
return;
if (!value.TryParse(out long startUnixTime))
return;
@@ -494,14 +510,21 @@ public class XpService : INService
var actualXp = (int)Math.Floor(xp);
if (actualXp > 0)
_addMessageXp.Enqueue(new() { Guild = channel.Guild, User = user, XpAmount = actualXp });
_addMessageXp.Enqueue(new()
{
Guild = channel.Guild,
User = user,
XpAmount = actualXp
});
}
private bool ShouldTrackXp(SocketGuildUser user, ulong channelId)
{
if (_excludedChannels.TryGetValue(user.Guild.Id, out var chans) && chans.Contains(channelId)) return false;
if (_excludedChannels.TryGetValue(user.Guild.Id, out var chans) && chans.Contains(channelId))
return false;
if (_excludedServers.Contains(user.Guild.Id)) return false;
if (_excludedServers.Contains(user.Guild.Id))
return false;
if (_excludedRoles.TryGetValue(user.Guild.Id, out var roles) && user.Roles.Any(x => roles.Contains(x.Id)))
return false;
@@ -514,16 +537,18 @@ public class XpService : INService
if (arg.Author is not SocketGuildUser user || user.IsBot)
return Task.CompletedTask;
_= Task.Run(() =>
_ = Task.Run(() =>
{
if (!ShouldTrackXp(user, arg.Channel.Id))
return;
var xpConf = _xpConfig.Data;
var xp = 0;
if (arg.Attachments.Any(a => a.Height >= 128 && a.Width >= 128)) xp = xpConf.XpFromImage;
if (arg.Attachments.Any(a => a.Height >= 128 && a.Width >= 128))
xp = xpConf.XpFromImage;
if (arg.Content.Contains(' ') || arg.Content.Length >= 5) xp = Math.Max(xp, xpConf.XpPerMessage);
if (arg.Content.Contains(' ') || arg.Content.Length >= 5)
xp = Math.Max(xp, xpConf.XpPerMessage);
if (xp <= 0)
return;
@@ -531,16 +556,29 @@ public class XpService : INService
if (!SetUserRewarded(user.Id))
return;
_addMessageXp.Enqueue(new() { Guild = user.Guild, Channel = arg.Channel, User = user, XpAmount = xp });
_addMessageXp.Enqueue(new()
{
Guild = user.Guild,
Channel = arg.Channel,
User = user,
XpAmount = xp
});
});
return Task.CompletedTask;
}
public void AddXpDirectly(IGuildUser user, IMessageChannel channel, int amount)
{
if (amount <= 0) throw new ArgumentOutOfRangeException(nameof(amount));
if (amount <= 0)
throw new ArgumentOutOfRangeException(nameof(amount));
_addMessageXp.Enqueue(new() { Guild = user.Guild, Channel = channel, User = user, XpAmount = amount });
_addMessageXp.Enqueue(new()
{
Guild = user.Guild,
Channel = channel,
User = user,
XpAmount = amount
});
}
public void AddXp(ulong userId, ulong guildId, int amount)
@@ -622,11 +660,16 @@ public class XpService : INService
var roles = _excludedRoles.GetOrAdd(guildId, _ => new());
using var uow = _db.GetDbContext();
var xpSetting = uow.XpSettingsFor(guildId);
var excludeObj = new ExcludedItem { ItemId = rId, ItemType = ExcludedItemType.Role };
var excludeObj = new ExcludedItem
{
ItemId = rId,
ItemType = ExcludedItemType.Role
};
if (roles.Add(rId))
{
if (xpSetting.ExclusionList.Add(excludeObj)) uow.SaveChanges();
if (xpSetting.ExclusionList.Add(excludeObj))
uow.SaveChanges();
return true;
}
@@ -648,18 +691,24 @@ public class XpService : INService
var channels = _excludedChannels.GetOrAdd(guildId, _ => new());
using var uow = _db.GetDbContext();
var xpSetting = uow.XpSettingsFor(guildId);
var excludeObj = new ExcludedItem { ItemId = chId, ItemType = ExcludedItemType.Channel };
var excludeObj = new ExcludedItem
{
ItemId = chId,
ItemType = ExcludedItemType.Channel
};
if (channels.Add(chId))
{
if (xpSetting.ExclusionList.Add(excludeObj)) uow.SaveChanges();
if (xpSetting.ExclusionList.Add(excludeObj))
uow.SaveChanges();
return true;
}
channels.TryRemove(chId);
if (xpSetting.ExclusionList.Remove(excludeObj)) uow.SaveChanges();
if (xpSetting.ExclusionList.Remove(excludeObj))
uow.SaveChanges();
return false;
}
@@ -678,7 +727,8 @@ public class XpService : INService
{
TextOptions = new()
{
HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center
}
}.WithFallbackFonts(_fonts.FallBackFonts);
@@ -686,7 +736,8 @@ public class XpService : INService
{
TextOptions = new()
{
HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Top
}
}.WithFallbackFonts(_fonts.FallBackFonts);
@@ -864,7 +915,8 @@ public class XpService : INService
}
//club image
if (template.Club.Icon.Show) await DrawClubImage(img, stats);
if (template.Club.Icon.Show)
await DrawClubImage(img, stats);
img.Mutate(x => x.Resize(template.OutputSize.X, template.OutputSize.Y));
return ((Stream)img.ToStream(imageFormat), imageFormat);

View File

@@ -8,22 +8,102 @@ namespace NadekoBot.Modules.Xp;
public class XpTemplate
{
[JsonProperty("output_size")]
public XpTemplatePos OutputSize { get; set; } = new() { X = 450, Y = 220 };
public XpTemplatePos OutputSize { get; set; } = new()
{
X = 450,
Y = 220
};
public XpTemplateUser User { get; set; } = new()
{
Name = new() { FontSize = 50, Show = true, Pos = new() { X = 130, Y = 17 } },
Icon = new() { Show = true, Pos = new() { X = 32, Y = 10 }, Size = new() { X = 69, Y = 70 } },
GuildLevel = new() { Show = true, FontSize = 45, Pos = new() { X = 47, Y = 297 } },
GlobalLevel = new() { Show = true, FontSize = 45, Pos = new() { X = 47, Y = 149 } },
GuildRank = new() { Show = true, FontSize = 30, Pos = new() { X = 148, Y = 326 } },
GlobalRank = new() { Show = true, FontSize = 30, Pos = new() { X = 148, Y = 179 } },
Name = new()
{
FontSize = 50,
Show = true,
Pos = new()
{
X = 130,
Y = 17
}
},
Icon = new()
{
Show = true,
Pos = new()
{
X = 32,
Y = 10
},
Size = new()
{
X = 69,
Y = 70
}
},
GuildLevel = new()
{
Show = true,
FontSize = 45,
Pos = new()
{
X = 47,
Y = 297
}
},
GlobalLevel = new()
{
Show = true,
FontSize = 45,
Pos = new()
{
X = 47,
Y = 149
}
},
GuildRank = new()
{
Show = true,
FontSize = 30,
Pos = new()
{
X = 148,
Y = 326
}
},
GlobalRank = new()
{
Show = true,
FontSize = 30,
Pos = new()
{
X = 148,
Y = 179
}
},
TimeOnLevel =
new()
{
Format = "{0}d{1}h{2}m",
Global = new() { FontSize = 20, Show = true, Pos = new() { X = 50, Y = 204 } },
Guild = new() { FontSize = 20, Show = true, Pos = new() { X = 50, Y = 351 } }
Global = new()
{
FontSize = 20,
Show = true,
Pos = new()
{
X = 50,
Y = 204
}
},
Guild = new()
{
FontSize = 20,
Show = true,
Pos = new()
{
X = 50,
Y = 351
}
}
},
Xp = new()
{
@@ -35,28 +115,93 @@ public class XpTemplate
Direction = XpTemplateDirection.Right,
Length = 450,
Color = new(0, 0, 0, 0.4f),
PointA = new() { X = 321, Y = 104 },
PointB = new() { X = 286, Y = 235 }
PointA = new()
{
X = 321,
Y = 104
},
PointB = new()
{
X = 286,
Y = 235
}
},
Guild = new()
{
Direction = XpTemplateDirection.Right,
Length = 450,
Color = new(0, 0, 0, 0.4f),
PointA = new() { X = 282, Y = 248 },
PointB = new() { X = 247, Y = 379 }
PointA = new()
{
X = 282,
Y = 248
},
PointB = new()
{
X = 247,
Y = 379
}
}
},
Global = new() { Show = true, FontSize = 50, Pos = new() { X = 430, Y = 142 } },
Guild = new() { Show = true, FontSize = 50, Pos = new() { X = 400, Y = 282 } },
Awarded = new() { Show = true, FontSize = 25, Pos = new() { X = 445, Y = 347 } }
Global = new()
{
Show = true,
FontSize = 50,
Pos = new()
{
X = 430,
Y = 142
}
},
Guild = new()
{
Show = true,
FontSize = 50,
Pos = new()
{
X = 400,
Y = 282
}
},
Awarded = new()
{
Show = true,
FontSize = 25,
Pos = new()
{
X = 445,
Y = 347
}
}
}
};
public XpTemplateClub Club { get; set; } = new()
{
Icon = new() { Show = true, Pos = new() { X = 722, Y = 25 }, Size = new() { X = 45, Y = 45 } },
Name = new() { FontSize = 35, Pos = new() { X = 650, Y = 49 }, Show = true }
Icon = new()
{
Show = true,
Pos = new()
{
X = 722,
Y = 25
},
Size = new()
{
X = 45,
Y = 45
}
},
Name = new()
{
FontSize = 35,
Pos = new()
{
X = 650,
Y = 49
},
Show = true
}
};
}