mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 09:48:26 -04:00
- Updated editorconfig rules to hopefully look a bit nicer.
- Removed configureawait(false) from everywhere as it doesnt' do anything in a console app and just makes the code look ugly - Started using .WhenAll extension instead of Task.WhenAll to make it look nicer when chaining methods
This commit is contained in:
@@ -84,4 +84,13 @@ public static class EnumerableExtensions
|
||||
/// <returns>A task that represents the completion of all of the supplied tasks.</returns>
|
||||
public static Task<TResult[]> WhenAll<TResult>(this IEnumerable<Task<TResult>> tasks)
|
||||
=> Task.WhenAll(tasks);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a task that will complete when all of the <see cref="Task"/> objects in an enumerable
|
||||
/// collection have completed
|
||||
/// </summary>
|
||||
/// <param name="tasks">The tasks to wait on for completion.</param>
|
||||
/// <returns>A task that represents the completion of all of the supplied tasks.</returns>
|
||||
public static Task WhenAll(this IEnumerable<Task> tasks)
|
||||
=> Task.WhenAll(tasks);
|
||||
}
|
||||
|
@@ -213,13 +213,13 @@ public static class Extensions
|
||||
{
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(seconds * 1000).ConfigureAwait(false);
|
||||
await Task.Delay(seconds * 1000);
|
||||
if (logService != null)
|
||||
{
|
||||
logService.AddDeleteIgnore(msg.Id);
|
||||
}
|
||||
|
||||
try { await msg.DeleteAsync().ConfigureAwait(false); }
|
||||
try { await msg.DeleteAsync(); }
|
||||
catch { }
|
||||
}
|
||||
);
|
||||
@@ -238,7 +238,7 @@ public static class Extensions
|
||||
|
||||
public static async Task<IEnumerable<IGuildUser>> GetMembersAsync(this IRole role)
|
||||
{
|
||||
var users = await role.Guild.GetUsersAsync(CacheMode.CacheOnly).ConfigureAwait(false);
|
||||
var users = await role.Guild.GetUsersAsync(CacheMode.CacheOnly);
|
||||
return users.Where(u => u.RoleIds.Contains(role.Id));
|
||||
}
|
||||
|
||||
|
@@ -127,7 +127,7 @@ public static class MessageChannelExtensions
|
||||
int itemsPerPage,
|
||||
bool addPaginatedFooter = true)
|
||||
{
|
||||
var embed = await pageFunc(currentPage).ConfigureAwait(false);
|
||||
var embed = await pageFunc(currentPage);
|
||||
|
||||
var lastPage = (totalElements - 1) / itemsPerPage;
|
||||
|
||||
@@ -141,16 +141,16 @@ public static class MessageChannelExtensions
|
||||
else if (addPaginatedFooter)
|
||||
embed.AddPaginatedFooter(currentPage, lastPage);
|
||||
|
||||
var msg = await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false);
|
||||
var msg = await ctx.Channel.EmbedAsync(embed);
|
||||
|
||||
if (lastPage == 0 ||
|
||||
!canPaginate)
|
||||
return;
|
||||
|
||||
await msg.AddReactionAsync(_arrowLeft).ConfigureAwait(false);
|
||||
await msg.AddReactionAsync(_arrowRight).ConfigureAwait(false);
|
||||
await msg.AddReactionAsync(_arrowLeft);
|
||||
await msg.AddReactionAsync(_arrowRight);
|
||||
|
||||
await Task.Delay(2000).ConfigureAwait(false);
|
||||
await Task.Delay(2000);
|
||||
|
||||
var lastPageChange = DateTime.MinValue;
|
||||
|
||||
@@ -167,20 +167,20 @@ public static class MessageChannelExtensions
|
||||
if (currentPage == 0)
|
||||
return;
|
||||
lastPageChange = DateTime.UtcNow;
|
||||
var toSend = await pageFunc(--currentPage).ConfigureAwait(false);
|
||||
var toSend = await pageFunc(--currentPage);
|
||||
if (addPaginatedFooter)
|
||||
toSend.AddPaginatedFooter(currentPage, lastPage);
|
||||
await msg.ModifyAsync(x => x.Embed = toSend.Build()).ConfigureAwait(false);
|
||||
await msg.ModifyAsync(x => x.Embed = toSend.Build());
|
||||
}
|
||||
else if (r.Emote.Name == _arrowRight.Name)
|
||||
{
|
||||
if (lastPage > currentPage)
|
||||
{
|
||||
lastPageChange = DateTime.UtcNow;
|
||||
var toSend = await pageFunc(++currentPage).ConfigureAwait(false);
|
||||
var toSend = await pageFunc(++currentPage);
|
||||
if (addPaginatedFooter)
|
||||
toSend.AddPaginatedFooter(currentPage, lastPage);
|
||||
await msg.ModifyAsync(x => x.Embed = toSend.Build()).ConfigureAwait(false);
|
||||
await msg.ModifyAsync(x => x.Embed = toSend.Build());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,7 +192,7 @@ public static class MessageChannelExtensions
|
||||
|
||||
using (msg.OnReaction((DiscordSocketClient)ctx.Client, ChangePage, ChangePage))
|
||||
{
|
||||
await Task.Delay(30000).ConfigureAwait(false);
|
||||
await Task.Delay(30000);
|
||||
}
|
||||
|
||||
try
|
||||
@@ -200,13 +200,13 @@ public static class MessageChannelExtensions
|
||||
if (msg.Channel is ITextChannel &&
|
||||
((SocketGuild)ctx.Guild).CurrentUser.GuildPermissions.ManageMessages)
|
||||
{
|
||||
await msg.RemoveAllReactionsAsync().ConfigureAwait(false);
|
||||
await msg.RemoveAllReactionsAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await Task.WhenAll(msg.Reactions.Where(x => x.Value.IsMe)
|
||||
await msg.Reactions.Where(x => x.Value.IsMe)
|
||||
.Select(x => msg.RemoveReactionAsync(x.Key, ctx.Client.CurrentUser))
|
||||
);
|
||||
.WhenAll();
|
||||
}
|
||||
}
|
||||
catch
|
||||
|
@@ -90,8 +90,8 @@ public static class StringExtensions
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
var sw = new StreamWriter(ms);
|
||||
await sw.WriteAsync(str).ConfigureAwait(false);
|
||||
await sw.FlushAsync().ConfigureAwait(false);
|
||||
await sw.WriteAsync(str);
|
||||
await sw.FlushAsync();
|
||||
ms.Position = 0;
|
||||
return ms;
|
||||
}
|
||||
|
Reference in New Issue
Block a user