Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Fluxer.Net.Example/Modules/BasicCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public async Task EmbedCommand()
.WithCurrentTimestamp()
.Build();

await Context.Rest.SendMessageAsync(Context.ChannelId, "Here's an example of a rich embed:",
await Context.Rest.SendMessageAsync(Context.Channel.Id, "Here's an example of a rich embed:",
embeds: new List<EmbedRequest> { embed }
);
}
Expand Down
6 changes: 3 additions & 3 deletions Fluxer.Net/Commands/Attributes/RequireContextAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public override Task<PreconditionResult> CheckPermissionsAsync(
{
bool isValid = false;

if (Contexts.HasFlag(ContextType.Guild) && context.GuildId.HasValue)
if (Contexts.HasFlag(ContextType.Guild) && context.Guild != null)
isValid = true;

if (Contexts.HasFlag(ContextType.DM) && !context.GuildId.HasValue)
if (Contexts.HasFlag(ContextType.DM) && context.Guild == null)
isValid = true;

if (Contexts.HasFlag(ContextType.Group) && context.Message.ChannelType == ChannelType.GroupDm)
if (Contexts.HasFlag(ContextType.Group) && context.Channel.Type == ChannelType.GroupDm)
isValid = true;

if (isValid)
Expand Down
41 changes: 30 additions & 11 deletions Fluxer.Net/Commands/CommandContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,42 @@ public class CommandContext
/// <summary>
/// Gets the API client.
/// </summary>
public ApiClient Rest { get; }
public FluxerClient Client { get; }

/// <summary>
/// Gets the API client.
/// </summary>
public ApiClient Rest => Client.Rest;

/// <summary>
/// Gets the gateway client.
/// </summary>
public GatewayClient Gateway { get; }
public GatewayClient Gateway => Client.Gateway;

/// <summary>
/// Gets the message that triggered the command.
/// </summary>
public MessageGatewayData Message { get; }
public SocketMessage Message { get; }

/// <summary>
/// Gets the channel the command was executed in.
/// </summary>
public ulong ChannelId => Message.ChannelId;
public Channel Channel => Message.Channel;

/// <summary>
/// Gets the guild the command was executed in, if any.
/// </summary>
public ulong? GuildId => Message.GuildId;
public SocketGuild? Guild { get; }

/// <summary>
/// Gets the user who executed the command.
/// </summary>
public User User { get; internal set; }
public SocketUser User { get; internal set; }

/// <summary>
/// Gets the member who executed the command.
/// </summary>
public GuildMemberGatewayData? Member => Message.Member;
public SocketGuildMember? Member { get; }

/// <summary>
/// Creates a new command context.
Expand All @@ -49,9 +54,23 @@ public class CommandContext
/// <param name="message">The message that triggered the command.</param>
public CommandContext(FluxerClient client, MessageGatewayData message)
{
User = User.Create(client, message.Author);
Rest = client.Rest;
Gateway = client.Gateway;
Message = message;
Client = client;
Message = SocketMessage.Create(client, message);
User = SocketUser.Create(client, message.Author);
if (message.GuildId.HasValue)
{

Guild = client.Gateway.GetGuild(message.GuildId.Value);
Member = Guild.GetMember(User.Id);
if (Member == null)
{
message.Member.User = message.Author;
Guild.AddOrUpdateMember(Client, message.Member);
Member = Guild.GetMember(User.Id);
}

if (Member.Guild == null)
Member.Guild = Guild;
}
}
}
4 changes: 2 additions & 2 deletions Fluxer.Net/Commands/ModuleBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ protected async Task<Message> ReplyAsync(string? content = null, List<EmbedReque
MessageReferenceRequest? reference = null, AllowedMentionsRequest? allowedMentions = null, MessageFlag flags = MessageFlag.None,
string? nonce = null, ulong? favoruteMemeId = null, bool? tts = null, List<ulong>? stickerIds = null, List<AttachmentRequest>? attachments = null)
{
return await Context.Rest.SendMessageAsync(Context.ChannelId, content, embeds, reference, allowedMentions, flags, nonce, favoruteMemeId, tts, stickerIds, attachments);
return await Context.Rest.SendMessageAsync(Context.Channel.Id, content, embeds, reference, allowedMentions, flags, nonce, favoruteMemeId, tts, stickerIds, attachments);
}

/// <summary>
/// Sends a message to the channel the command was executed in.
/// </summary>
protected async Task<Message> ReplyAsync(List<AttachmentRequest> attachments, string? content = null)
{
return await Context.Rest.SendMessageAsync(Context.ChannelId, content, attachments: attachments);
return await Context.Rest.SendMessageAsync(Context.Channel.Id, content, attachments: attachments);
}
}

Expand Down
6 changes: 6 additions & 0 deletions Fluxer.Net/Data/Expressions/GuildEmoji.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public class GuildEmoji : Emoji, IGuildEmoji
[JsonProperty("user")]
public User? Creator { get; set; }

/// <inheritdoc />
public string? GetEmojiUrl(int size = 160)
{
return $"https://fluxerusercontent.com/emojis/{Id}.webp?size={size}";
}

IUser? IGuildEmoji.Creator => Creator;

internal GuildEmoji(FluxerBaseClient client) : base(client)
Expand Down
6 changes: 6 additions & 0 deletions Fluxer.Net/Data/Expressions/GuildEmojiJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@ public class GuildEmojiJson : EmojiJson, IGuildEmoji
[JsonProperty("user")]
public UserJson? Creator { get; set; }

/// <inheritdoc />
public string? GetEmojiUrl(int size = 160)
{
return $"https://fluxerusercontent.com/emojis/{Id}.webp?size={size}";
}

IUser? IGuildEmoji.Creator => Creator;
}
6 changes: 6 additions & 0 deletions Fluxer.Net/Data/Expressions/GuildSticker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public class GuildSticker : Sticker, IGuildSticker
/// <inheritdoc />
public User? Creator { get; internal set; }

/// <inheritdoc />
public string? GetStickerUrl(int size = 320)
{
return $"https://fluxerusercontent.com/stickers/{Id}.webp?size={size}";
}

IUser? IGuildSticker.Creator => Creator;

internal GuildSticker(FluxerBaseClient client) : base(client)
Expand Down
6 changes: 6 additions & 0 deletions Fluxer.Net/Data/Expressions/GuildStickerJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ public class GuildStickerJson : StickerJson, IGuildSticker
[JsonProperty("user")]
public UserJson? Creator { get; set; }

/// <inheritdoc />
public string? GetStickerUrl(int size = 320)
{
return $"https://fluxerusercontent.com/stickers/{Id}.webp?size={size}";
}

IUser? IGuildSticker.Creator => Creator;
}
5 changes: 5 additions & 0 deletions Fluxer.Net/Data/Expressions/IGuildEmoji.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,9 @@ public interface IGuildEmoji : IEmoji
/// The user that created the emoji.
/// </summary>
IUser? Creator { get; }

/// <summary>
/// Get the emoji's image.
/// </summary>
string GetEmojiUrl(int size);
}
5 changes: 5 additions & 0 deletions Fluxer.Net/Data/Expressions/IGuildSticker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public interface IGuildSticker : ISticker
/// The user that created the sticker.
/// </summary>
IUser? Creator { get; }

/// <summary>
/// Get the sticker's image.
/// </summary>
string GetStickerUrl(int size);
}
26 changes: 23 additions & 3 deletions Fluxer.Net/Data/Guilds/IPartialGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,17 @@ public interface IPartialGuild
/// <summary>
/// The hash of the guild splash screen.
/// </summary>
string? SplashHash { get; }
string? InviteSplashHash { get; }

/// <summary>
/// The width of the guild splash in pixels.
/// </summary>
int? SplashWidth { get; }
int? InviteSplashWidth { get; }

/// <summary>
/// The height of the guild splash in pixels
/// </summary>
int? SplashHeight { get; }
int? InviteSplashHeight { get; }

/// <summary>
/// The alignment of the splash card.
Expand All @@ -77,4 +77,24 @@ public interface IPartialGuild
/// UNAVAILABLE_FOR_EVERYONE_BUT_STAFF, VISIONARY, OPERATOR, LARGE_GUILD_OVERRIDE, VERY_LARGE_GUILD (other values allowed)
/// </remarks>
string[]? Features { get; }

/// <summary>
/// Get the guild's icon.
/// </summary>
string? GetIconUrl(int size);

/// <summary>
/// Get the guild's banner.
/// </summary>
string? GetBannerUrl(int size);

/// <summary>
/// Get the guild's invite splash.
/// </summary>
string? GetInviteSplashUrl(int size);

/// <summary>
/// Get the guild's embed splash.
/// </summary>
string? GetEmbedSplashUrl(int size);
}
9 changes: 9 additions & 0 deletions Fluxer.Net/Data/Guilds/Members/GuildMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ public string GetAvatarOrDefaultUrl(int size = 160)
return GetAvatarUrl(size);
}

/// <inheritdoc />
public string? GetBannerUrl(int size = 1024)
{
if (string.IsNullOrEmpty(BannerHash))
return null;

return $"https://fluxerusercontent.com/guilds/{GuildId}/users/{UserId}/banners/{BannerHash}.webp?size={size}";
}

IUser IGuildMember.User => User;

internal GuildMember(FluxerBaseClient client) : base(client)
Expand Down
12 changes: 10 additions & 2 deletions Fluxer.Net/Data/Guilds/Members/GuildMemberJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public string GetDefaultAvatarUrl()
if (string.IsNullOrEmpty(AvatarHash))
return User.GetAvatarUrl();

return $"https://fluxerusercontent.com/avatars/{UserId}/{AvatarHash}.png?size={size}";
return $"https://fluxerusercontent.com/guilds/{GuildId}/users/{UserId}/avatars/{AvatarHash}.png?size={size}";
}

/// <inheritdoc />
Expand All @@ -87,6 +87,14 @@ public string GetAvatarOrDefaultUrl(int size = 160)
return GetAvatarUrl(size);
}

IUser IGuildMember.User => User;
/// <inheritdoc />
public string? GetBannerUrl(int size = 1024)
{
if (string.IsNullOrEmpty(BannerHash))
return null;

return $"https://fluxerusercontent.com/guilds/{GuildId}/users/{UserId}/banners/{BannerHash}.webp?size={size}";
}

IUser IGuildMember.User => User;
}
5 changes: 5 additions & 0 deletions Fluxer.Net/Data/Guilds/Members/IGuildMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ public interface IGuildMember
/// Get the members's avatar or fallback to default.
/// </summary>
string GetAvatarOrDefaultUrl(int size);

/// <summary>
/// Get the member's banner.
/// </summary>
string? GetBannerUrl(int size);
}
6 changes: 5 additions & 1 deletion Fluxer.Net/Data/Guilds/Members/SocketGuildMember.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
namespace Fluxer.Net;
using System.Collections.Concurrent;

namespace Fluxer.Net;

public class SocketGuildMember : GuildMember
{
public SocketGuild Guild { get; internal set; }

public ConcurrentDictionary<string, SocketVoiceState> VoiceStates { get; internal set; } = new ConcurrentDictionary<string, SocketVoiceState>();

public IEnumerable<SocketRole> Roles
=> RoleIds.Select(id => Guild.Roles[id]).Where(x => x != null);

Expand All @@ -23,7 +27,7 @@

}

public static SocketGuildMember Create(FluxerBaseClient client, GuildMemberJson json)

Check warning on line 30 in Fluxer.Net/Data/Guilds/Members/SocketGuildMember.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

'SocketGuildMember.Create(FluxerBaseClient, GuildMemberJson)' hides inherited member 'GuildMember.Create(FluxerBaseClient, GuildMemberJson)'. Use the new keyword if hiding was intended.

Check warning on line 30 in Fluxer.Net/Data/Guilds/Members/SocketGuildMember.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

'SocketGuildMember.Create(FluxerBaseClient, GuildMemberJson)' hides inherited member 'GuildMember.Create(FluxerBaseClient, GuildMemberJson)'. Use the new keyword if hiding was intended.
{
SocketGuildMember data = new SocketGuildMember(client);
data.Update(client, json);
Expand Down
48 changes: 42 additions & 6 deletions Fluxer.Net/Data/Guilds/PartialGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ public class PartialGuild : Entity, IPartialGuild
public int? EmbedSplashHeight { get; internal set; }

/// <inheritdoc />
public string? SplashHash { get; internal set; }
public string? InviteSplashHash { get; internal set; }

/// <inheritdoc />
public int? SplashWidth { get; internal set; }
public int? InviteSplashWidth { get; internal set; }

/// <inheritdoc />
public int? SplashHeight { get; internal set; }
public int? InviteSplashHeight { get; internal set; }

/// <inheritdoc />
public GuildSplashCardAlignment SplashCardAligment { get; internal set; }
Expand Down Expand Up @@ -70,10 +70,46 @@ internal void Update(FluxerBaseClient client, PartialGuildJson json)
EmbedSplashHash = json.EmbedSplashHash;
EmbedSplashWidth = json.EmbedSplashWidth;
EmbedSplashHeight = json.EmbedSplashHeight;
SplashHash = json.SplashHash;
SplashWidth = json.SplashWidth;
SplashHeight = json.SplashHeight;
InviteSplashHash = json.InviteSplashHash;
InviteSplashWidth = json.InviteSplashWidth;
InviteSplashHeight = json.InviteSplashHeight;
SplashCardAligment = json.SplashCardAligment;
Features = GuildFeatures.FromGuild(json);
}

/// <inheritdoc />
public string? GetIconUrl(int size = 160)
{
if (string.IsNullOrEmpty(IconHash))
return null;

return $"https://fluxerusercontent.com/icons/{Id}/{IconHash}.png?size={size}";
}

/// <inheritdoc />
public string? GetBannerUrl(int size = 1024)
{
if (string.IsNullOrEmpty(BannerHash))
return null;

return $"https://fluxerusercontent.com/banners/{Id}/{BannerHash}.webp?size={size}";
}

/// <inheritdoc />
public string? GetInviteSplashUrl(int size = 1024)
{
if (string.IsNullOrEmpty(InviteSplashHash))
return null;

return $"https://fluxerusercontent.com/splashes/{Id}/{InviteSplashHash}.webp?size={size}";
}

/// <inheritdoc />
public string? GetEmbedSplashUrl(int size = 1024)
{
if (string.IsNullOrEmpty(EmbedSplashHash))
return null;

return $"https://fluxerusercontent.com/embed-splashes/{Id}/{EmbedSplashHash}.webp?size={size}";
}
}
Loading
Loading