+ DiscordConfig + CDN + MentionUtils + LogMessage + LogSeveritypull/988/head
@@ -4,8 +4,10 @@ namespace Discord | |||
{ | |||
public static class CDN | |||
{ | |||
/// <summary> Returns the Discord developer application icon. </summary> | |||
public static string GetApplicationIconUrl(ulong appId, string iconId) | |||
=> iconId != null ? $"{DiscordConfig.CDNUrl}app-icons/{appId}/{iconId}.jpg" : null; | |||
/// <summary> Returns the user avatar URL based on the size and <see cref="ImageFormat"/>. </summary> | |||
public static string GetUserAvatarUrl(ulong userId, string avatarId, ushort size, ImageFormat format) | |||
{ | |||
if (avatarId == null) | |||
@@ -13,21 +15,27 @@ namespace Discord | |||
string extension = FormatToExtension(format, avatarId); | |||
return $"{DiscordConfig.CDNUrl}avatars/{userId}/{avatarId}.{extension}?size={size}"; | |||
} | |||
/// <summary> Returns the guild icon URL based on the guild and icon ID. </summary> | |||
public static string GetGuildIconUrl(ulong guildId, string iconId) | |||
=> iconId != null ? $"{DiscordConfig.CDNUrl}icons/{guildId}/{iconId}.jpg" : null; | |||
/// <summary> Returns the guild splash URL based on the guild and icon ID. </summary> | |||
public static string GetGuildSplashUrl(ulong guildId, string splashId) | |||
=> splashId != null ? $"{DiscordConfig.CDNUrl}splashes/{guildId}/{splashId}.jpg" : null; | |||
/// <summary> Returns the channel icon URL based on the guild and icon ID. </summary> | |||
public static string GetChannelIconUrl(ulong channelId, string iconId) | |||
=> iconId != null ? $"{DiscordConfig.CDNUrl}channel-icons/{channelId}/{iconId}.jpg" : null; | |||
/// <summary> Returns the emoji URL based on the emoji ID. </summary> | |||
public static string GetEmojiUrl(ulong emojiId, bool animated) | |||
=> $"{DiscordConfig.CDNUrl}emojis/{emojiId}.{(animated ? "gif" : "png")}"; | |||
/// <summary> Returns the rich presence asset URL based on the asset ID and <see cref="ImageFormat"/>. </summary> | |||
public static string GetRichAssetUrl(ulong appId, string assetId, ushort size, ImageFormat format) | |||
{ | |||
string extension = FormatToExtension(format, ""); | |||
return $"{DiscordConfig.CDNUrl}app-assets/{appId}/{assetId}.{extension}?size={size}"; | |||
} | |||
/// <summary> Returns the Spotify album URL based on the album art ID. </summary> | |||
public static string GetSpotifyAlbumArtUrl(string albumArtId) | |||
=> $"https://i.scdn.co/image/{albumArtId}"; | |||
@@ -1,24 +1,35 @@ | |||
using System.Reflection; | |||
using System.Reflection; | |||
namespace Discord | |||
{ | |||
public class DiscordConfig | |||
{ | |||
public const int APIVersion = 6; | |||
/// <summary> Returns the gateway version Discord.NET uses. </summary> | |||
public const int APIVersion = 6; | |||
/// <summary> Returns the Discord.NET verion, including the build number. </summary> | |||
public static string Version { get; } = | |||
typeof(DiscordConfig).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? | |||
typeof(DiscordConfig).GetTypeInfo().Assembly.GetName().Version.ToString(3) ?? | |||
"Unknown"; | |||
/// <summary> Returns the user agent that Discord.NET uses in its clients. </summary> | |||
public static string UserAgent { get; } = $"DiscordBot (https://github.com/RogueException/Discord.Net, v{Version})"; | |||
/// <summary> Returns the base Discord API URL. </summary> | |||
public static readonly string APIUrl = $"https://discordapp.com/api/v{APIVersion}/"; | |||
/// <summary> Returns the base Discord CDN URL. </summary> | |||
public const string CDNUrl = "https://cdn.discordapp.com/"; | |||
/// <summary> Returns the base Discord invite URL. </summary> | |||
public const string InviteUrl = "https://discord.gg/"; | |||
/// <summary> Returns the default timeout for requests. </summary> | |||
public const int DefaultRequestTimeout = 15000; | |||
/// <summary> Returns the max length for a Discord message. </summary> | |||
public const int MaxMessageSize = 2000; | |||
/// <summary> Returns the max messages allowed to be in a request. </summary> | |||
public const int MaxMessagesPerBatch = 100; | |||
/// <summary> Returns the max users allowed to be in a request. </summary> | |||
public const int MaxUsersPerBatch = 1000; | |||
/// <summary> Returns the max guilds allowed to be in a request. </summary> | |||
public const int MaxGuildsPerBatch = 100; | |||
/// <summary> Gets or sets how a request should act in the case of an error, by default. </summary> | |||
@@ -1,13 +1,18 @@ | |||
using System; | |||
using System; | |||
using System.Text; | |||
namespace Discord | |||
{ | |||
/// <summary> The message object for logging purposes. </summary> | |||
public struct LogMessage | |||
{ | |||
/// <summary> The severity of the log message. </summary> | |||
public LogSeverity Severity { get; } | |||
/// <summary> The source of the log message. </summary> | |||
public string Source { get; } | |||
/// <summary> The message of the log message. </summary> | |||
public string Message { get; } | |||
/// <summary> The exception of the log message. </summary> | |||
public Exception Exception { get; } | |||
public LogMessage(LogSeverity severity, string source, string message, Exception exception = null) | |||
@@ -1,12 +1,31 @@ | |||
namespace Discord | |||
namespace Discord | |||
{ | |||
public enum LogSeverity | |||
{ | |||
/// <summary> | |||
/// Logs that contain the most severe level of error. | |||
/// This type of error indicate that immediate attention may be required. | |||
/// </summary> | |||
Critical = 0, | |||
/// <summary> | |||
/// Logs that highlight when the flow of execution is stopped due to a failure. | |||
/// </summary> | |||
Error = 1, | |||
/// <summary> | |||
/// Logs that highlight an abnormal activity in the flow of execution. | |||
/// </summary> | |||
Warning = 2, | |||
/// <summary> | |||
/// Logs that track the general flow of the application. | |||
/// </summary> | |||
Info = 3, | |||
/// <summary> | |||
/// Logs that are used for interactive investigation during development. | |||
/// </summary> | |||
Verbose = 4, | |||
/// <summary> | |||
/// Logs that contain the most detailed messages. | |||
/// </summary> | |||
Debug = 5 | |||
} | |||
} |
@@ -1,4 +1,4 @@ | |||
using System; | |||
using System; | |||
using System.Globalization; | |||
using System.Text; | |||
@@ -10,10 +10,13 @@ namespace Discord | |||
//If the system can't be positive a user doesn't have a nickname, assume useNickname = true (source: Jake) | |||
internal static string MentionUser(string id, bool useNickname = true) => useNickname ? $"<@!{id}>" : $"<@{id}>"; | |||
/// <summary> Returns a mention string based on the user ID. </summary> | |||
public static string MentionUser(ulong id) => MentionUser(id.ToString(), true); | |||
internal static string MentionChannel(string id) => $"<#{id}>"; | |||
/// <summary> Returns a mention string based on the channel ID. </summary> | |||
public static string MentionChannel(ulong id) => MentionChannel(id.ToString()); | |||
internal static string MentionRole(string id) => $"<@&{id}>"; | |||
internal static string MentionRole(string id) => $"<@&{id}>"; | |||
/// <summary> Returns a mention string based on the role ID. </summary> | |||
public static string MentionRole(ulong id) => MentionRole(id.ToString()); | |||
/// <summary> Parses a provided user mention string. </summary> | |||