run dotnet format

This commit is contained in:
spiral
2021-08-27 11:03:47 -04:00
parent 05989242f9
commit ac2671452d
278 changed files with 1913 additions and 1808 deletions

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Threading.Tasks;
using Myriad.Cache;
@@ -15,7 +15,7 @@ namespace Myriad.Extensions
throw new KeyNotFoundException($"Guild {guildId} not found in cache");
return guild;
}
public static Channel GetChannel(this IDiscordCache cache, ulong channelId)
{
if (!cache.TryGetChannel(channelId, out var channel))
@@ -36,14 +36,14 @@ namespace Myriad.Extensions
throw new KeyNotFoundException($"User {userId} not found in cache");
return user;
}
public static Role GetRole(this IDiscordCache cache, ulong roleId)
{
if (!cache.TryGetRole(roleId, out var role))
throw new KeyNotFoundException($"User {roleId} not found in cache");
return role;
}
public static async ValueTask<User?> GetOrFetchUser(this IDiscordCache cache, DiscordApiClient rest, ulong userId)
{
if (cache.TryGetUser(userId, out var cacheUser))
@@ -54,7 +54,7 @@ namespace Myriad.Extensions
await cache.SaveUser(restUser);
return restUser;
}
public static async ValueTask<Channel?> GetOrFetchChannel(this IDiscordCache cache, DiscordApiClient rest, ulong channelId)
{
if (cache.TryGetChannel(channelId, out var cacheChannel))
@@ -79,9 +79,9 @@ namespace Myriad.Extensions
public static Channel GetRootChannel(this IDiscordCache cache, ulong channelOrThread)
{
var channel = cache.GetChannel(channelOrThread);
if (!channel.IsThread())
if (!channel.IsThread())
return channel;
var parent = cache.GetChannel(channel.ParentId!.Value);
return parent;
}

View File

@@ -1,4 +1,4 @@
using Myriad.Types;
using Myriad.Types;
namespace Myriad.Extensions
{

View File

@@ -1,7 +1,7 @@
namespace Myriad.Extensions
namespace Myriad.Extensions
{
public static class GuildExtensions
{
}
}

View File

@@ -1,4 +1,4 @@
using Myriad.Gateway;
using Myriad.Gateway;
using Myriad.Types;
namespace Myriad.Extensions
@@ -7,7 +7,7 @@ namespace Myriad.Extensions
{
public static string JumpLink(this Message msg) =>
$"https://discord.com/channels/{msg.GuildId}/{msg.ChannelId}/{msg.Id}";
public static string JumpLink(this MessageReactionAddEvent msg) =>
$"https://discord.com/channels/{msg.GuildId}/{msg.ChannelId}/{msg.MessageId}";
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -21,12 +21,12 @@ namespace Myriad.Extensions
if (!cache.TryGetChannel(channelId, out var channel))
// todo: handle channel not found better
return PermissionSet.Dm;
if (channel.GuildId == null)
return PermissionSet.Dm;
var rootChannel = cache.GetRootChannel(channelId);
var guild = cache.GetGuild(channel.GuildId.Value);
if (isWebhook)
@@ -34,10 +34,10 @@ namespace Myriad.Extensions
return PermissionsFor(guild, rootChannel, userId, member);
}
public static PermissionSet EveryonePermissions(this Guild guild) =>
guild.Roles.FirstOrDefault(r => r.Id == guild.Id)?.Permissions ?? PermissionSet.Dm;
public static PermissionSet EveryonePermissions(this IDiscordCache cache, Channel channel)
{
if (channel.Type == Channel.ChannelType.Dm)
@@ -62,7 +62,7 @@ namespace Myriad.Extensions
{
if (channel.Type == Channel.ChannelType.Dm)
return PermissionSet.Dm;
if (member == null)
// this happens with system (Discord platform-owned) users - they're not actually in the guild, so there is no member object.
return EveryonePermissions(guild);

View File

@@ -1,4 +1,4 @@
using System;
using System;
using Myriad.Types;
@@ -7,7 +7,7 @@ namespace Myriad.Extensions
public static class SnowflakeExtensions
{
public static readonly DateTimeOffset DiscordEpoch = new(2015, 1, 1, 0, 0, 0, TimeSpan.Zero);
public static DateTimeOffset SnowflakeToTimestamp(ulong snowflake) =>
DiscordEpoch + TimeSpan.FromMilliseconds(snowflake >> 22);

View File

@@ -1,4 +1,4 @@
using Myriad.Types;
using Myriad.Types;
namespace Myriad.Extensions
{
@@ -6,7 +6,7 @@ namespace Myriad.Extensions
{
public static string Mention(this User user) => $"<@{user.Id}>";
public static string AvatarUrl(this User user, string? format = "png", int? size = 128) =>
public static string AvatarUrl(this User user, string? format = "png", int? size = 128) =>
$"https://cdn.discordapp.com/avatars/{user.Id}/{user.Avatar}.{format}?size={size}";
}
}