mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 01:38:27 -04:00
More common refactorings like renaming variables, removing empty statements and unused variables, etc
This commit is contained in:
@@ -34,8 +34,6 @@ public partial class Utility
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async partial Task Alias(string trigger, [Leftover] string mapping = null)
|
||||
{
|
||||
var channel = (ITextChannel)ctx.Channel;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(trigger))
|
||||
return;
|
||||
|
||||
@@ -52,7 +50,6 @@ public partial class Utility
|
||||
await 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 tr = config.CommandAliases.FirstOrDefault(x => x.Trigger == trigger);
|
||||
if (tr is not null)
|
||||
uow.Set<CommandAlias>().Remove(tr);
|
||||
@@ -84,9 +81,9 @@ public partial class Utility
|
||||
{
|
||||
var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
|
||||
var toAdd = new CommandAlias { Mapping = mapping, Trigger = trigger };
|
||||
var toRemove = config.CommandAliases.Where(x => x.Trigger == trigger);
|
||||
var toRemove = config.CommandAliases.Where(x => x.Trigger == trigger).ToArray();
|
||||
if (toRemove.Any())
|
||||
uow.RemoveRange(toRemove.ToArray());
|
||||
uow.RemoveRange(toRemove);
|
||||
config.CommandAliases.Add(toAdd);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
@@ -103,7 +100,6 @@ public partial class Utility
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async partial Task AliasList(int page = 1)
|
||||
{
|
||||
var channel = (ITextChannel)ctx.Channel;
|
||||
page -= 1;
|
||||
|
||||
if (page < 0)
|
||||
|
@@ -107,7 +107,7 @@ 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()
|
||||
@@ -134,7 +134,7 @@ public partial class Utility
|
||||
await ctx.OkAsync();
|
||||
}
|
||||
|
||||
private string GetPropsAndValuesString(IConfigService config, IEnumerable<string> names)
|
||||
private string GetPropsAndValuesString(IConfigService config, IReadOnlyCollection<string> names)
|
||||
{
|
||||
var propValues = names.Select(pr =>
|
||||
{
|
||||
@@ -142,7 +142,7 @@ public partial class Utility
|
||||
if (pr != "currency.sign")
|
||||
val = val?.TrimTo(28);
|
||||
return val?.Replace("\n", "") ?? "-";
|
||||
});
|
||||
}).ToList();
|
||||
|
||||
var strings = names.Zip(propValues, (name, value) => $"{name,-25} = {value}\n");
|
||||
|
||||
|
@@ -150,7 +150,7 @@ public class PatreonRewardsService : INService
|
||||
+ "?fields%5Bmember%5D=full_name,currently_entitled_amount_cents"
|
||||
+ "&fields%5Buser%5D=social_connections"
|
||||
+ "&include=user";
|
||||
PatreonResponse data = null;
|
||||
PatreonResponse data;
|
||||
do
|
||||
{
|
||||
var res = await http.GetStringAsync(page);
|
||||
|
@@ -62,12 +62,16 @@ 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]
|
||||
|
@@ -55,7 +55,6 @@ public sealed class RunningRepeater
|
||||
/// <summary>
|
||||
/// Calculate when is the proper time to run the repeater again based on initial time repeater ran.
|
||||
/// </summary>
|
||||
/// <param name="repeaterter"></param>
|
||||
/// <param name="initialDateTime">Initial time repeater ran at (or should run at).</param>
|
||||
private DateTime CalculateInitialInterval(DateTime initialDateTime)
|
||||
{
|
||||
|
@@ -23,7 +23,7 @@ public class ConverterService : INService
|
||||
_httpFactory = factory;
|
||||
|
||||
if (client.ShardId == 0)
|
||||
_currencyUpdater = new(async shouldLoad => await UpdateCurrency((bool)shouldLoad),
|
||||
_currencyUpdater = new(async shouldLoad => await UpdateCurrency((bool)shouldLoad!),
|
||||
client.ShardId == 0,
|
||||
TimeSpan.Zero,
|
||||
_updateInterval);
|
||||
@@ -55,7 +55,9 @@ public class ConverterService : INService
|
||||
.ToArray();
|
||||
|
||||
var fileData = JsonConvert.DeserializeObject<ConvertUnit[]>(File.ReadAllText("data/units.json"))
|
||||
.Where(x => x.UnitType != "currency");
|
||||
?.Where(x => x.UnitType != "currency");
|
||||
if (fileData is null)
|
||||
return;
|
||||
|
||||
var data = JsonConvert.SerializeObject(range.Append(baseType).Concat(fileData).ToList());
|
||||
_cache.Redis.GetDatabase().StringSet("converter_units", data);
|
||||
|
@@ -6,7 +6,7 @@ namespace NadekoBot.Modules.Utility.Services;
|
||||
|
||||
public class VerboseErrorsService : INService
|
||||
{
|
||||
private readonly ConcurrentHashSet<ulong> guildsEnabled;
|
||||
private readonly ConcurrentHashSet<ulong> _guildsEnabled;
|
||||
private readonly DbService _db;
|
||||
private readonly CommandHandler _ch;
|
||||
private readonly HelpService _hs;
|
||||
@@ -23,12 +23,12 @@ public class VerboseErrorsService : INService
|
||||
|
||||
_ch.CommandErrored += LogVerboseError;
|
||||
|
||||
guildsEnabled = new(bot.AllGuildConfigs.Where(x => x.VerboseErrors).Select(x => x.GuildId));
|
||||
_guildsEnabled = new(bot.AllGuildConfigs.Where(x => x.VerboseErrors).Select(x => x.GuildId));
|
||||
}
|
||||
|
||||
private async Task LogVerboseError(CommandInfo cmd, ITextChannel channel, string reason)
|
||||
{
|
||||
if (channel is null || !guildsEnabled.Contains(channel.GuildId))
|
||||
if (channel is null || !_guildsEnabled.Contains(channel.GuildId))
|
||||
return;
|
||||
|
||||
try
|
||||
@@ -60,9 +60,9 @@ public class VerboseErrorsService : INService
|
||||
}
|
||||
|
||||
if ((bool)enabled) // This doesn't need to be duplicated inside the using block
|
||||
guildsEnabled.Add(guildId);
|
||||
_guildsEnabled.Add(guildId);
|
||||
else
|
||||
guildsEnabled.TryRemove(guildId);
|
||||
_guildsEnabled.TryRemove(guildId);
|
||||
|
||||
return (bool)enabled;
|
||||
}
|
||||
|
Reference in New Issue
Block a user