mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 17:58:26 -04:00
Updated editorconfig to (mostly?) require braces around if/else statements, and applied the new formatting rules
This commit is contained in:
@@ -66,7 +66,11 @@ public partial class Utility
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
|
||||
config.CommandAliases.Add(new() { Mapping = mapping, Trigger = trigger });
|
||||
config.CommandAliases.Add(new()
|
||||
{
|
||||
Mapping = mapping,
|
||||
Trigger = trigger
|
||||
});
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
@@ -80,7 +84,11 @@ public partial class Utility
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
|
||||
var toAdd = new CommandAlias { Mapping = mapping, Trigger = trigger };
|
||||
var toAdd = new CommandAlias
|
||||
{
|
||||
Mapping = mapping,
|
||||
Trigger = trigger
|
||||
};
|
||||
var toRemove = config.CommandAliases.Where(x => x.Trigger == trigger).ToArray();
|
||||
if (toRemove.Any())
|
||||
uow.RemoveRange(toRemove);
|
||||
|
@@ -74,10 +74,13 @@ public class CommandMapService : IInputTransformer, INService
|
||||
try
|
||||
{
|
||||
var toDelete = await channel.SendConfirmAsync(_eb, $"{input} => {newInput}");
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(1500);
|
||||
await toDelete.DeleteAsync(new() { RetryMode = RetryMode.AlwaysRetry });
|
||||
await toDelete.DeleteAsync(new()
|
||||
{
|
||||
RetryMode = RetryMode.AlwaysRetry
|
||||
});
|
||||
});
|
||||
}
|
||||
catch { }
|
||||
|
@@ -107,7 +107,8 @@ public partial class Utility
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
value = "-";
|
||||
|
||||
if (prop != "currency.sign") value = Format.Code(Format.Sanitize(value.TrimTo(1000)), "json");
|
||||
if (prop != "currency.sign")
|
||||
value = Format.Code(Format.Sanitize(value.TrimTo(1000)), "json");
|
||||
|
||||
var embed = _eb.Create()
|
||||
.WithOkColor()
|
||||
@@ -137,12 +138,13 @@ public partial class Utility
|
||||
private string GetPropsAndValuesString(IConfigService config, IReadOnlyCollection<string> names)
|
||||
{
|
||||
var propValues = names.Select(pr =>
|
||||
{
|
||||
var val = config.GetSetting(pr);
|
||||
if (pr != "currency.sign")
|
||||
val = val?.TrimTo(28);
|
||||
return val?.Replace("\n", "") ?? "-";
|
||||
}).ToList();
|
||||
{
|
||||
var val = config.GetSetting(pr);
|
||||
if (pr != "currency.sign")
|
||||
val = val?.TrimTo(28);
|
||||
return val?.Replace("\n", "") ?? "-";
|
||||
})
|
||||
.ToList();
|
||||
|
||||
var strings = names.Zip(propValues, (name, value) => $"{name,-25} = {value}\n");
|
||||
|
||||
|
@@ -21,12 +21,12 @@ public partial class Utility
|
||||
[OwnerOnly]
|
||||
public partial Task ServerInfo([Leftover] string guildName)
|
||||
=> InternalServerInfo(guildName);
|
||||
|
||||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public partial Task ServerInfo()
|
||||
=> InternalServerInfo();
|
||||
|
||||
|
||||
private async Task InternalServerInfo(string guildName = null)
|
||||
{
|
||||
var channel = (ITextChannel)ctx.Channel;
|
||||
@@ -101,7 +101,8 @@ public partial class Utility
|
||||
return;
|
||||
|
||||
var embed = _eb.Create().AddField(GetText(strs.name), $"**{user.Username}**#{user.Discriminator}", true);
|
||||
if (!string.IsNullOrWhiteSpace(user.Nickname)) embed.AddField(GetText(strs.nickname), user.Nickname, true);
|
||||
if (!string.IsNullOrWhiteSpace(user.Nickname))
|
||||
embed.AddField(GetText(strs.nickname), user.Nickname, true);
|
||||
embed.AddField(GetText(strs.id), user.Id.ToString(), true)
|
||||
.AddField(GetText(strs.joined_server), $"{user.JoinedAt?.ToString("dd.MM.yyyy HH:mm") ?? "?"}", true)
|
||||
.AddField(GetText(strs.joined_discord), $"{user.CreatedAt:dd.MM.yyyy HH:mm}", true)
|
||||
@@ -131,12 +132,14 @@ public partial class Utility
|
||||
|
||||
var str = new StringBuilder();
|
||||
foreach (var kvp in _cmdHandler.UserMessagesSent.OrderByDescending(kvp => kvp.Value)
|
||||
.Skip(page * activityPerPage)
|
||||
.Take(activityPerPage))
|
||||
.Skip(page * activityPerPage)
|
||||
.Take(activityPerPage))
|
||||
{
|
||||
str.AppendLine(GetText(strs.activity_line(++startCount,
|
||||
Format.Bold(kvp.Key.ToString()),
|
||||
kvp.Value / _stats.GetUptime().TotalSeconds,
|
||||
kvp.Value)));
|
||||
}
|
||||
|
||||
await ctx.Channel.EmbedAsync(_eb.Create()
|
||||
.WithTitle(GetText(strs.activity_page(page + 1)))
|
||||
|
@@ -51,7 +51,7 @@ public class PatreonRewardsService : INService, IReadyExecutor
|
||||
{
|
||||
if (_client.ShardId != 0)
|
||||
return;
|
||||
|
||||
|
||||
var t = new PeriodicTimer(Interval);
|
||||
do
|
||||
{
|
||||
@@ -133,7 +133,7 @@ public class PatreonRewardsService : INService, IReadyExecutor
|
||||
|
||||
var lastUpdate = LastAccessTokenUpdate(creds);
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
|
||||
if (lastUpdate.Year != now.Year
|
||||
|| lastUpdate.Month != now.Month
|
||||
|| string.IsNullOrWhiteSpace(creds.Patreon.AccessToken))
|
||||
@@ -143,7 +143,7 @@ public class PatreonRewardsService : INService, IReadyExecutor
|
||||
// -> update access token
|
||||
if (!HasPatreonCreds(creds))
|
||||
return;
|
||||
|
||||
|
||||
var success = await UpdateAccessToken(creds);
|
||||
if (!success)
|
||||
return;
|
||||
@@ -198,7 +198,8 @@ public class PatreonRewardsService : INService, IReadyExecutor
|
||||
})
|
||||
.ToList();
|
||||
|
||||
foreach (var pledge in userData) await ClaimReward(pledge.UserId, pledge.PatreonUserId, pledge.EntitledTo);
|
||||
foreach (var pledge in userData)
|
||||
await ClaimReward(pledge.UserId, pledge.PatreonUserId, pledge.EntitledTo);
|
||||
}
|
||||
catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.Unauthorized)
|
||||
{
|
||||
@@ -229,7 +230,9 @@ public class PatreonRewardsService : INService, IReadyExecutor
|
||||
{
|
||||
users.Add(new()
|
||||
{
|
||||
PatreonUserId = patreonUserId, LastReward = now, AmountRewardedThisMonth = eligibleFor
|
||||
PatreonUserId = patreonUserId,
|
||||
LastReward = now,
|
||||
AmountRewardedThisMonth = eligibleFor
|
||||
});
|
||||
|
||||
await uow.SaveChangesAsync();
|
||||
|
@@ -62,16 +62,12 @@ public partial class Utility
|
||||
}
|
||||
|
||||
if (quotes.Any())
|
||||
{
|
||||
await SendConfirmAsync(GetText(strs.quotes_page(page + 1)),
|
||||
string.Join("\n",
|
||||
quotes.Select(q
|
||||
=> $"`#{q.Id}` {Format.Bold(q.Keyword.SanitizeAllMentions()),-20} by {q.AuthorName.SanitizeAllMentions()}")));
|
||||
}
|
||||
else
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.quotes_page_none);
|
||||
}
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -281,7 +277,7 @@ public partial class Utility
|
||||
}
|
||||
|
||||
var exprsDict = quotes.GroupBy(x => x.Keyword)
|
||||
.ToDictionary(x => x.Key, x => x.Select(ExportedQuote.FromModel));
|
||||
.ToDictionary(x => x.Key, x => x.Select(ExportedQuote.FromModel));
|
||||
|
||||
var text = PREPEND_EXPORT + _exportSerializer.Serialize(exprsDict).UnescapeUnicodeCodePoints();
|
||||
|
||||
@@ -374,7 +370,10 @@ public partial class Utility
|
||||
public static ExportedQuote FromModel(Quote quote)
|
||||
=> new()
|
||||
{
|
||||
Id = ((kwum)quote.Id).ToString(), An = quote.AuthorName, Aid = quote.AuthorId, Txt = quote.Text
|
||||
Id = ((kwum)quote.Id).ToString(),
|
||||
An = quote.AuthorName,
|
||||
Aid = quote.AuthorId,
|
||||
Txt = quote.Text
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -50,7 +50,8 @@ public partial class Utility
|
||||
if (!await RemindInternal(target,
|
||||
meorhere == MeOrHere.Me || ctx.Guild is null,
|
||||
remindData.Time,
|
||||
remindData.What)) await ReplyErrorLocalizedAsync(strs.remind_too_long);
|
||||
remindData.What))
|
||||
await ReplyErrorLocalizedAsync(strs.remind_too_long);
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
@@ -184,7 +185,8 @@ public partial class Utility
|
||||
if (ctx.Guild is not null)
|
||||
{
|
||||
var perms = ((IGuildUser)ctx.User).GetPermissions((IGuildChannel)ctx.Channel);
|
||||
if (!perms.MentionEveryone) message = message.SanitizeAllMentions();
|
||||
if (!perms.MentionEveryone)
|
||||
message = message.SanitizeAllMentions();
|
||||
}
|
||||
|
||||
var rem = new Reminder
|
||||
|
@@ -65,8 +65,8 @@ public class RemindService : INService
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
await uow.Reminders
|
||||
.ToLinqToDBTable()
|
||||
.DeleteAsync(x => reminders.Contains(x.Id));
|
||||
.ToLinqToDBTable()
|
||||
.DeleteAsync(x => reminders.Contains(x.Id));
|
||||
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public class RemindService : INService
|
||||
using var uow = _db.GetDbContext();
|
||||
return uow.Reminders
|
||||
.ToLinqToDBTable()
|
||||
.Where(x => (x.ServerId / 4194304 % (ulong)_creds.TotalShards == (ulong)_client.ShardId)
|
||||
.Where(x => x.ServerId / 4194304 % (ulong)_creds.TotalShards == (ulong)_client.ShardId
|
||||
&& x.When < now)
|
||||
// .FromSqlInterpolated(
|
||||
// $"select * from reminders where ((serverid >> 22) % {_creds.TotalShards}) == {_client.ShardId} and \"when\" < {now};")
|
||||
@@ -88,7 +88,8 @@ public class RemindService : INService
|
||||
var m = _regex.Match(input);
|
||||
|
||||
obj = default;
|
||||
if (m.Length == 0) return false;
|
||||
if (m.Length == 0)
|
||||
return false;
|
||||
|
||||
var values = new Dictionary<string, int>();
|
||||
|
||||
@@ -102,7 +103,8 @@ public class RemindService : INService
|
||||
|
||||
foreach (var groupName in _regex.GetGroupNames())
|
||||
{
|
||||
if (groupName is "0" or "what") continue;
|
||||
if (groupName is "0" or "what")
|
||||
continue;
|
||||
if (string.IsNullOrWhiteSpace(m.Groups[groupName].Value))
|
||||
{
|
||||
values[groupName] = 0;
|
||||
@@ -126,7 +128,11 @@ public class RemindService : INService
|
||||
|
||||
var ts = new TimeSpan((30 * values["mo"]) + (7 * values["w"]) + values["d"], values["h"], values["m"], 0);
|
||||
|
||||
obj = new() { Time = ts, What = what };
|
||||
obj = new()
|
||||
{
|
||||
Time = ts,
|
||||
What = what
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -18,7 +18,8 @@ public partial class Utility
|
||||
return;
|
||||
|
||||
var success = await _service.TriggerExternal(ctx.Guild.Id, index);
|
||||
if (!success) await ReplyErrorLocalizedAsync(strs.repeat_invoke_none);
|
||||
if (!success)
|
||||
await ReplyErrorLocalizedAsync(strs.repeat_invoke_none);
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
|
@@ -29,7 +29,7 @@ public sealed class RepeaterService : IReadyExecutor, INService
|
||||
|
||||
var uow = _db.GetDbContext();
|
||||
var shardRepeaters = uow.Set<Repeater>()
|
||||
.Where(x => ((int)(x.GuildId / Math.Pow(2, 22)) % _creds.TotalShards)
|
||||
.Where(x => (int)(x.GuildId / Math.Pow(2, 22)) % _creds.TotalShards
|
||||
== _client.ShardId)
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
@@ -80,10 +80,12 @@ public sealed class RepeaterService : IReadyExecutor, INService
|
||||
}
|
||||
|
||||
// execute
|
||||
foreach (var chunk in toExecute.Chunk(5)) await chunk.Select(Trigger).WhenAll();
|
||||
foreach (var chunk in toExecute.Chunk(5))
|
||||
await chunk.Select(Trigger).WhenAll();
|
||||
|
||||
// reinsert
|
||||
foreach (var rep in toExecute) await HandlePostExecute(rep);
|
||||
foreach (var rep in toExecute)
|
||||
await HandlePostExecute(rep);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -227,7 +229,8 @@ public sealed class RepeaterService : IReadyExecutor, INService
|
||||
try
|
||||
{
|
||||
var oldMsg = await channel.GetMessageAsync(lastMessageId);
|
||||
if (oldMsg is not null) await oldMsg.DeleteAsync();
|
||||
if (oldMsg is not null)
|
||||
await oldMsg.DeleteAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -289,7 +292,10 @@ public sealed class RepeaterService : IReadyExecutor, INService
|
||||
await using var uow = _db.GetDbContext();
|
||||
await uow.Repeaters.AsQueryable()
|
||||
.Where(x => x.Id == repeaterId)
|
||||
.UpdateAsync(rep => new() { LastMessageId = lastMsgId });
|
||||
.UpdateAsync(rep => new()
|
||||
{
|
||||
LastMessageId = lastMsgId
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<RunningRepeater?> AddRepeaterAsync(
|
||||
|
@@ -60,7 +60,8 @@ public sealed class RunningRepeater
|
||||
{
|
||||
// if the initial time is greater than now, that means the repeater didn't still execute a single time.
|
||||
// just schedule it
|
||||
if (initialDateTime > DateTime.UtcNow) return initialDateTime;
|
||||
if (initialDateTime > DateTime.UtcNow)
|
||||
return initialDateTime;
|
||||
|
||||
// else calculate based on minutes difference
|
||||
|
||||
|
@@ -19,12 +19,12 @@ public class StreamRoleService : INService
|
||||
_client = client;
|
||||
|
||||
_guildSettings = bot.AllGuildConfigs.ToDictionary(x => x.GuildId, x => x.StreamRole)
|
||||
.Where(x => x.Value is { Enabled: true })
|
||||
.ToConcurrent();
|
||||
.Where(x => x.Value is { Enabled: true })
|
||||
.ToConcurrent();
|
||||
|
||||
_client.GuildMemberUpdated += Client_GuildMemberUpdated;
|
||||
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -39,10 +39,11 @@ public class StreamRoleService : INService
|
||||
|
||||
private Task Client_GuildMemberUpdated(Cacheable<SocketGuildUser, ulong> cacheable, SocketGuildUser after)
|
||||
{
|
||||
_= Task.Run(async () =>
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
//if user wasn't streaming or didn't have a game status at all
|
||||
if (_guildSettings.TryGetValue(after.Guild.Id, out var setting)) await RescanUser(after, setting);
|
||||
if (_guildSettings.TryGetValue(after.Guild.Id, out var setting))
|
||||
await RescanUser(after, setting);
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
@@ -73,7 +74,11 @@ public class StreamRoleService : INService
|
||||
|
||||
if (listType == StreamRoleListType.Whitelist)
|
||||
{
|
||||
var userObj = new StreamRoleWhitelistedUser { UserId = userId, Username = userName };
|
||||
var userObj = new StreamRoleWhitelistedUser
|
||||
{
|
||||
UserId = userId,
|
||||
Username = userName
|
||||
};
|
||||
|
||||
if (action == AddRemove.Rem)
|
||||
{
|
||||
@@ -91,15 +96,17 @@ public class StreamRoleService : INService
|
||||
}
|
||||
else
|
||||
{
|
||||
var userObj = new StreamRoleBlacklistedUser { UserId = userId, Username = userName };
|
||||
var userObj = new StreamRoleBlacklistedUser
|
||||
{
|
||||
UserId = userId,
|
||||
Username = userName
|
||||
};
|
||||
|
||||
if (action == AddRemove.Rem)
|
||||
{
|
||||
var toRemove = streamRoleSettings.Blacklist.FirstOrDefault(x => x.Equals(userObj));
|
||||
if (toRemove is not null)
|
||||
{
|
||||
success = streamRoleSettings.Blacklist.Remove(toRemove);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -111,7 +118,8 @@ public class StreamRoleService : INService
|
||||
UpdateCache(guild.Id, streamRoleSettings);
|
||||
}
|
||||
|
||||
if (success) await RescanUsers(guild);
|
||||
if (success)
|
||||
await RescanUsers(guild);
|
||||
return success;
|
||||
}
|
||||
|
||||
@@ -186,8 +194,10 @@ public class StreamRoleService : INService
|
||||
UpdateCache(fromRole.Guild.Id, setting);
|
||||
|
||||
foreach (var usr in await fromRole.GetMembersAsync())
|
||||
{
|
||||
if (usr is { } x)
|
||||
await RescanUser(x, setting, addRole);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -294,8 +304,10 @@ public class StreamRoleService : INService
|
||||
var users = await guild.GetUsersAsync(CacheMode.CacheOnly);
|
||||
foreach (var usr in users.Where(x
|
||||
=> x.RoleIds.Contains(setting.FromRoleId) || x.RoleIds.Contains(addRole.Id)))
|
||||
{
|
||||
if (usr is { } x)
|
||||
await RescanUser(x, setting, addRole);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -57,11 +57,15 @@ public class ConverterService : INService, IReadyExecutor
|
||||
var currencyRates = await GetCurrencyRates();
|
||||
var baseType = new ConvertUnit
|
||||
{
|
||||
Triggers = new[] { currencyRates.Base }, Modifier = decimal.One, UnitType = unitTypeString
|
||||
Triggers = new[] { currencyRates.Base },
|
||||
Modifier = decimal.One,
|
||||
UnitType = unitTypeString
|
||||
};
|
||||
var range = currencyRates.ConversionRates.Select(u => new ConvertUnit
|
||||
{
|
||||
Triggers = new[] { u.Key }, Modifier = u.Value, UnitType = unitTypeString
|
||||
Triggers = new[] { u.Key },
|
||||
Modifier = u.Value,
|
||||
UnitType = unitTypeString
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
|
@@ -9,7 +9,7 @@ public partial class Utility
|
||||
public partial class UnitConverterCommands : NadekoSubmodule<ConverterService>
|
||||
{
|
||||
[Cmd]
|
||||
public async partial Task ConvertList()
|
||||
public async partial Task ConvertList()
|
||||
{
|
||||
var units = _service.Units;
|
||||
|
||||
@@ -17,8 +17,10 @@ public partial class Utility
|
||||
|
||||
|
||||
foreach (var g in units.GroupBy(x => x.UnitType))
|
||||
{
|
||||
embed.AddField(g.Key.ToTitleCase(),
|
||||
string.Join(", ", g.Select(x => x.Triggers.FirstOrDefault()).OrderBy(x => x)));
|
||||
}
|
||||
|
||||
await ctx.Channel.EmbedAsync(embed);
|
||||
}
|
||||
|
@@ -117,7 +117,7 @@ public partial class Utility : NadekoModule
|
||||
await _tracker.EnsureUsersDownloadedAsync(ctx.Guild);
|
||||
|
||||
var users = await ctx.Guild.GetUsersAsync(
|
||||
CacheMode.CacheOnly
|
||||
CacheMode.CacheOnly
|
||||
);
|
||||
|
||||
var roleUsers = users.Where(u => role is null ? u.RoleIds.Count == 1 : u.RoleIds.Contains(role.Id))
|
||||
|
@@ -54,7 +54,8 @@ public class VerboseErrorsService : INService
|
||||
|
||||
if (enabled == null)
|
||||
enabled = gc.VerboseErrors = !gc.VerboseErrors; // Old behaviour, now behind a condition
|
||||
else gc.VerboseErrors = (bool)enabled; // New behaviour, just set it.
|
||||
else
|
||||
gc.VerboseErrors = (bool)enabled; // New behaviour, just set it.
|
||||
|
||||
uow.SaveChanges();
|
||||
}
|
||||
|
Reference in New Issue
Block a user