Added many more braces for multiline if's, Improved .crypto command quite a bit and applied locale-specific format

This commit is contained in:
Kwoth
2022-02-04 06:00:17 +01:00
parent f77f2f433f
commit eda38e64d1
129 changed files with 635 additions and 233 deletions

View File

@@ -57,6 +57,7 @@ public class CommandMapService : IInputTransformer, INService
return input;
if (guild is not null)
{
if (AliasMaps.TryGetValue(guild.Id, out var maps))
{
var keys = maps.Keys.OrderByDescending(x => x.Length);
@@ -88,6 +89,7 @@ public class CommandMapService : IInputTransformer, INService
return newInput;
}
}
}
return input;
}

View File

@@ -67,8 +67,11 @@ public partial class Utility
embed.WithThumbnailUrl(guild.IconUrl);
if (guild.Emotes.Any())
{
embed.AddField(GetText(strs.custom_emojis) + $"({guild.Emotes.Count})",
string.Join(" ", guild.Emotes.Shuffle().Take(20).Select(e => $"{e.Name} {e}")).TrimTo(1020));
}
await ctx.Channel.EmbedAsync(embed);
}

View File

@@ -62,10 +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);
}
@@ -227,9 +229,7 @@ public partial class Utility
var q = uow.Quotes.GetById(id);
if (q?.GuildId != ctx.Guild.Id || (!hasManageMessages && q.AuthorId != ctx.Message.Author.Id))
{
response = GetText(strs.quotes_remove_none);
}
else
{
uow.Quotes.Remove(q);

View File

@@ -124,9 +124,7 @@ public partial class Utility
}
}
else
{
embed.WithDescription(GetText(strs.reminders_none));
}
embed.AddPaginatedFooter(page + 1, null);
await ctx.Channel.EmbedAsync(embed);

View File

@@ -150,9 +150,7 @@ public class RemindService : INService
ch = await user.CreateDMChannelAsync();
}
else
{
ch = _client.GetGuild(r.ServerId)?.GetTextChannel(r.ChannelId);
}
if (ch is null)
return;

View File

@@ -193,8 +193,10 @@ public sealed class RepeaterService : IReadyExecutor, INService
var channel = _client.GetChannel(repeater.ChannelId) as ITextChannel;
if (channel is null)
{
try { channel = await _client.Rest.GetChannelAsync(repeater.ChannelId) as ITextChannel; }
catch { }
}
if (channel is null)
{
@@ -210,6 +212,7 @@ public sealed class RepeaterService : IReadyExecutor, INService
}
if (_noRedundant.Contains(repeater.Id))
{
try
{
var lastMsgInChannel = await channel.GetMessagesAsync(2).Flatten().FirstAsync();
@@ -224,8 +227,10 @@ public sealed class RepeaterService : IReadyExecutor, INService
guild.Id,
channel.Id);
}
}
if (repeater.LastMessageId is { } lastMessageId)
{
try
{
var oldMsg = await channel.GetMessageAsync(lastMessageId);
@@ -239,6 +244,7 @@ public sealed class RepeaterService : IReadyExecutor, INService
guild.Id,
channel.Id);
}
}
var rep = new ReplacementBuilder().WithDefault(guild.CurrentUser, channel, guild, _client).Build();

View File

@@ -57,10 +57,12 @@ public partial class Utility
user.ToString());
if (action == AddRemove.Add)
{
if (success)
await ReplyConfirmLocalizedAsync(strs.stream_role_bl_add(Format.Bold(user.ToString())));
else
await ReplyConfirmLocalizedAsync(strs.stream_role_bl_add_fail(Format.Bold(user.ToString())));
}
else if (success)
await ReplyConfirmLocalizedAsync(strs.stream_role_bl_rem(Format.Bold(user.ToString())));
else
@@ -80,10 +82,12 @@ public partial class Utility
user.ToString());
if (action == AddRemove.Add)
{
if (success)
await ReplyConfirmLocalizedAsync(strs.stream_role_wl_add(Format.Bold(user.ToString())));
else
await ReplyConfirmLocalizedAsync(strs.stream_role_wl_add_fail(Format.Bold(user.ToString())));
}
else if (success)
await ReplyConfirmLocalizedAsync(strs.stream_role_wl_rem(Format.Bold(user.ToString())));
else

View File

@@ -90,9 +90,7 @@ public class StreamRoleService : INService
}
}
else
{
success = streamRoleSettings.Whitelist.Add(userObj);
}
}
else
{
@@ -109,9 +107,7 @@ public class StreamRoleService : INService
success = streamRoleSettings.Blacklist.Remove(toRemove);
}
else
{
success = streamRoleSettings.Blacklist.Add(userObj);
}
}
await uow.SaveChangesAsync();
@@ -270,6 +266,7 @@ public class StreamRoleService : INService
{
//check if user is in the addrole
if (user.RoleIds.Contains(setting.AddRoleId))
{
try
{
addRole ??= user.Guild.GetRole(setting.AddRoleId);
@@ -287,6 +284,7 @@ public class StreamRoleService : INService
Log.Warning(ex, "Error removing stream role(s). Forcibly disabling stream role feature");
throw new StreamRolePermissionException();
}
}
}
}

View File

@@ -48,9 +48,7 @@ public partial class Utility
decimal res;
if (originUnit.Triggers == targetUnit.Triggers)
{
res = value;
}
else if (originUnit.UnitType == "temperature")
{
//don't really care too much about efficiency, so just convert to Kelvin, then to target

View File

@@ -98,11 +98,13 @@ public partial class Utility : NadekoModule
if (arr.Length == 0)
await ReplyErrorLocalizedAsync(strs.nobody_playing_game);
else
{
await SendConfirmAsync("```css\n"
+ string.Join("\n",
arr.GroupBy(_ => i++ / 2)
.Select(ig => string.Concat(ig.Select(el => $"• {el,-27}"))))
+ "\n```");
}
}
[Cmd]
@@ -215,8 +217,10 @@ public partial class Utility : NadekoModule
if (!roles.Any())
await ReplyErrorLocalizedAsync(strs.no_roles_on_page);
else
{
await SendConfirmAsync(GetText(strs.roles_page(page, Format.Bold(target.ToString()))),
"\n• " + string.Join("\n• ", (IEnumerable<IRole>)roles).SanitizeMentions(true));
}
}
else
{
@@ -228,8 +232,10 @@ public partial class Utility : NadekoModule
if (!roles.Any())
await ReplyErrorLocalizedAsync(strs.no_roles_on_page);
else
{
await SendConfirmAsync(GetText(strs.roles_all_page(page)),
"\n• " + string.Join("\n• ", (IEnumerable<IRole>)roles).SanitizeMentions(true));
}
}
}
@@ -436,18 +442,20 @@ public partial class Utility : NadekoModule
if (string.IsNullOrWhiteSpace(s.ToString()))
{
if (s.Attachments.Any())
{
msg += "FILES_UPLOADED: "
+ string.Join("\n", s.Attachments.Select(x => x.Url));
}
else if (s.Embeds.Any())
{
msg += "EMBEDS: "
+ string.Join("\n--------\n",
s.Embeds.Select(x
=> $"Description: {x.Description}"));
}
}
else
{
msg += s.ToString();
}
return msg;
})