mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
Using pattern matching for nulls where applicable, discarded unused lambda parameters, cleaned up some classes. Unignored ServerLog commands which was mistakenly ignored due to a .gitignore rule
This commit is contained in:
@@ -18,7 +18,7 @@ public partial class Xp
|
||||
{
|
||||
var club = _service.TransferClub(ctx.User, newOwner);
|
||||
|
||||
if (club != null)
|
||||
if (club is not null)
|
||||
await ReplyConfirmLocalizedAsync(strs.club_transfered(Format.Bold(club.Name),
|
||||
Format.Bold(newOwner.ToString())));
|
||||
else
|
||||
@@ -66,7 +66,7 @@ public partial class Xp
|
||||
[Cmd]
|
||||
public async partial Task ClubIcon([Leftover] string url = null)
|
||||
{
|
||||
if ((!Uri.IsWellFormedUriString(url, UriKind.Absolute) && url != null)
|
||||
if ((!Uri.IsWellFormedUriString(url, UriKind.Absolute) && url is not null)
|
||||
|| !await _service.SetClubIcon(ctx.User.Id, url is null ? null : new Uri(url)))
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.club_icon_error);
|
||||
@@ -166,7 +166,7 @@ public partial class Xp
|
||||
var bans = club.Bans.Select(x => x.User).ToArray();
|
||||
|
||||
return ctx.SendPaginatedConfirmAsync(page,
|
||||
curPage =>
|
||||
_ =>
|
||||
{
|
||||
var toShow = string.Join("\n", bans.Skip(page * 10).Take(10).Select(x => x.ToString()));
|
||||
|
||||
@@ -193,7 +193,7 @@ public partial class Xp
|
||||
var apps = club.Applicants.Select(x => x.User).ToArray();
|
||||
|
||||
return ctx.SendPaginatedConfirmAsync(page,
|
||||
curPage =>
|
||||
_ =>
|
||||
{
|
||||
var toShow = string.Join("\n", apps.Skip(page * 10).Take(10).Select(x => x.ToString()));
|
||||
|
||||
|
@@ -88,7 +88,7 @@ public class ClubService : INService
|
||||
|
||||
public async Task<bool> SetClubIcon(ulong ownerUserId, Uri url)
|
||||
{
|
||||
if (url != null)
|
||||
if (url is not null)
|
||||
{
|
||||
using var http = _httpFactory.CreateClient();
|
||||
using var temp = await http.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
|
||||
@@ -134,7 +134,7 @@ public class ClubService : INService
|
||||
var du = uow.GetOrCreateUser(user);
|
||||
uow.SaveChanges();
|
||||
|
||||
if (du.Club != null
|
||||
if (du.Club is not null
|
||||
|| new LevelStats(du.TotalXp).Level < club.MinimumLevelReq
|
||||
|| club.Bans.Any(x => x.UserId == du.Id)
|
||||
|| club.Applicants.Any(x => x.UserId == du.Id))
|
||||
@@ -258,7 +258,7 @@ public class ClubService : INService
|
||||
club.Users.Remove(usr);
|
||||
|
||||
var app = club.Applicants.FirstOrDefault(x => x.UserId == usr.Id);
|
||||
if (app != null)
|
||||
if (app is not null)
|
||||
club.Applicants.Remove(app);
|
||||
|
||||
uow.SaveChanges();
|
||||
@@ -299,7 +299,7 @@ public class ClubService : INService
|
||||
|
||||
club.Users.Remove(usr);
|
||||
var app = club.Applicants.FirstOrDefault(x => x.UserId == usr.Id);
|
||||
if (app != null)
|
||||
if (app is not null)
|
||||
club.Applicants.Remove(app);
|
||||
uow.SaveChanges();
|
||||
|
||||
|
@@ -90,7 +90,7 @@ public class XpService : INService
|
||||
});
|
||||
|
||||
//load settings
|
||||
var allGuildConfigs = bot.AllGuildConfigs.Where(x => x.XpSettings != null).ToList();
|
||||
var allGuildConfigs = bot.AllGuildConfigs.Where(x => x.XpSettings is not null).ToList();
|
||||
|
||||
_excludedChannels = allGuildConfigs.ToDictionary(x => x.GuildId,
|
||||
x => new ConcurrentHashSet<ulong>(x.XpSettings.ExclusionList
|
||||
@@ -156,7 +156,7 @@ public class XpService : INService
|
||||
var oldGuildLevelData = new LevelStats(usr.Xp + usr.AwardedXp);
|
||||
usr.Xp += xp;
|
||||
du.TotalXp += xp;
|
||||
if (du.Club != 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)
|
||||
@@ -194,7 +194,7 @@ public class XpService : INService
|
||||
for (var i = oldGuildLevelData.Level + 1; i <= newGuildLevelData.Level; i++)
|
||||
{
|
||||
var rrew = rrews.FirstOrDefault(x => x.Level == i);
|
||||
if (rrew != null)
|
||||
if (rrew is not null)
|
||||
{
|
||||
var role = first.User.Guild.GetRole(rrew.RoleId);
|
||||
if (role is not null)
|
||||
@@ -208,7 +208,7 @@ public class XpService : INService
|
||||
|
||||
//get currency reward for this level
|
||||
var crew = crews.FirstOrDefault(x => x.Level == i);
|
||||
if (crew != null)
|
||||
if (crew is not null)
|
||||
//give the user the reward if it exists
|
||||
await _cs.AddAsync(item.Key.User.Id, "Level-up Reward", crew.Amount);
|
||||
}
|
||||
@@ -228,7 +228,7 @@ public class XpService : INService
|
||||
Format.Bold(x.Level.ToString()),
|
||||
Format.Bold(x.Guild.ToString() ?? "-")),
|
||||
x.Guild.Id));
|
||||
else if (x.MessageChannel != null) // channel
|
||||
else if (x.MessageChannel is not null) // channel
|
||||
await x.MessageChannel.SendConfirmAsync(_eb,
|
||||
_strings.GetText(strs.level_up_channel(x.User.Mention,
|
||||
Format.Bold(x.Level.ToString())),
|
||||
@@ -289,7 +289,7 @@ public class XpService : INService
|
||||
if (amount <= 0)
|
||||
{
|
||||
var toRemove = settings.CurrencyRewards.FirstOrDefault(x => x.Level == level);
|
||||
if (toRemove != null)
|
||||
if (toRemove is not null)
|
||||
{
|
||||
uow.Remove(toRemove);
|
||||
settings.CurrencyRewards.Remove(toRemove);
|
||||
@@ -299,7 +299,7 @@ public class XpService : INService
|
||||
{
|
||||
var rew = settings.CurrencyRewards.FirstOrDefault(x => x.Level == level);
|
||||
|
||||
if (rew != null)
|
||||
if (rew is not null)
|
||||
rew.Amount = amount;
|
||||
else
|
||||
settings.CurrencyRewards.Add(new() { Level = level, Amount = amount });
|
||||
@@ -326,7 +326,7 @@ public class XpService : INService
|
||||
var settings = uow.XpSettingsFor(guildId);
|
||||
|
||||
var toRemove = settings.RoleRewards.FirstOrDefault(x => x.Level == level);
|
||||
if (toRemove != null)
|
||||
if (toRemove is not null)
|
||||
{
|
||||
uow.Remove(toRemove);
|
||||
settings.RoleRewards.Remove(toRemove);
|
||||
@@ -347,7 +347,7 @@ public class XpService : INService
|
||||
|
||||
var rew = settings.RoleRewards.FirstOrDefault(x => x.Level == level);
|
||||
|
||||
if (rew != null)
|
||||
if (rew is not null)
|
||||
{
|
||||
rew.RoleId = roleId;
|
||||
rew.Remove = remove;
|
||||
@@ -424,9 +424,9 @@ public class XpService : INService
|
||||
|
||||
var _ = Task.Run(() =>
|
||||
{
|
||||
if (before.VoiceChannel != null) ScanChannelForVoiceXp(before.VoiceChannel);
|
||||
if (before.VoiceChannel is not null) ScanChannelForVoiceXp(before.VoiceChannel);
|
||||
|
||||
if (after.VoiceChannel != null && after.VoiceChannel != before.VoiceChannel)
|
||||
if (after.VoiceChannel is not null && after.VoiceChannel != before.VoiceChannel)
|
||||
ScanChannelForVoiceXp(after.VoiceChannel);
|
||||
else if (after.VoiceChannel is null)
|
||||
// In this case, the user left the channel and the previous for loops didn't catch
|
||||
@@ -634,7 +634,7 @@ public class XpService : INService
|
||||
roles.TryRemove(rId);
|
||||
|
||||
var toDelete = xpSetting.ExclusionList.FirstOrDefault(x => x.Equals(excludeObj));
|
||||
if (toDelete != null)
|
||||
if (toDelete is not null)
|
||||
{
|
||||
uow.Remove(toDelete);
|
||||
uow.SaveChanges();
|
||||
@@ -822,7 +822,7 @@ public class XpService : INService
|
||||
new(_template.User.TimeOnLevel.Guild.Pos.X, _template.User.TimeOnLevel.Guild.Pos.Y)));
|
||||
//avatar
|
||||
|
||||
if (stats.User.AvatarId != null && _template.User.Icon.Show)
|
||||
if (stats.User.AvatarId is not null && _template.User.Icon.Show)
|
||||
try
|
||||
{
|
||||
var avatarUrl = stats.User.RealAvatarUrl();
|
||||
|
@@ -247,13 +247,13 @@ public partial class Xp : NadekoModule<XpService>
|
||||
var serverExcluded = _service.IsServerExcluded(ctx.Guild.Id);
|
||||
var roles = _service.GetExcludedRoles(ctx.Guild.Id)
|
||||
.Select(x => ctx.Guild.GetRole(x))
|
||||
.Where(x => x != null)
|
||||
.Where(x => x is not null)
|
||||
.Select(x => $"`role` {x.Mention}")
|
||||
.ToList();
|
||||
|
||||
var chans = (await _service.GetExcludedChannels(ctx.Guild.Id)
|
||||
.Select(x => ctx.Guild.GetChannelAsync(x))
|
||||
.WhenAll()).Where(x => x != null)
|
||||
.WhenAll()).Where(x => x is not null)
|
||||
.Select(x => $"`channel` <#{x.Id}>")
|
||||
.ToList();
|
||||
|
||||
|
Reference in New Issue
Block a user