Skip to content
This repository was archived by the owner on Apr 30, 2024. It is now read-only.
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
143 changes: 143 additions & 0 deletions Quarrel.sln

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion samples/Quarrel.Samples.RichPresence/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private async void Connect(object sender, RoutedEventArgs e)
private async void SetActivity(object sender, RoutedEventArgs e)
{
Activity activity = new Activity(ActivityName.Text);
bool success = await _connection.SetActivity(activity);
await _connection.SetActivity(activity);
}
}
}
1 change: 1 addition & 0 deletions src/API/Discord.API.Status/Discord.API.Status.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Configurations>Debug;Insider;Alpha;Release</Configurations>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions src/API/Discord.API.Status/Models/Datum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

using System.Text.Json.Serialization;

// JSON models don't need to respect standard nullable rules.
#pragma warning disable CS8618

namespace Discord.API.Status.Models
{
/// <summary>
Expand Down
12 changes: 12 additions & 0 deletions src/API/Discord.API.Status/Models/Summary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,25 @@

using System.Text.Json.Serialization;

// JSON models don't need to respect standard nullable rules.
#pragma warning disable CS8618

namespace Discord.API.Status.Models
{
/// <summary>
/// A summary of a data set.
/// </summary>
public partial class Summary
{
/// <summary>
/// The sum of the data.
/// </summary>
[JsonPropertyName("sum")]
public double Sum { get; set; }

/// <summary>
/// The mean of the data.
/// </summary>
[JsonPropertyName("mean")]
public double Mean { get; set; }
}
Expand Down
4 changes: 4 additions & 0 deletions src/API/Discord.API/Discord.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
<PackageReference Include="Refit" Version="6.3.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Libs\Quarrel.Common\Quarrel.Common.csproj" />
</ItemGroup>

</Project>
7 changes: 4 additions & 3 deletions src/API/Discord.API/Gateways/Gateway.Requests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Quarrel © 2022

using Discord.API.Gateways.Models;
using Discord.API.Models.Enums.Users;
using System;
using System.Threading.Tasks;

Expand Down Expand Up @@ -43,19 +44,19 @@ public void SubscribeToGuildAsync(ulong[] channelIds)
throw new NotImplementedException();
}

public async Task UpdateStatusAsync(string status, int? idleSince, bool isAfk)
public async Task UpdateStatusAsync(UserStatus status, int? idleSince = null, bool isAfk = false)
{
var payload = new StatusUpdate()
{
Status = status,
Status = status.GetStringValue(),
IdleSince = idleSince,
IsAFK = isAfk,
};

await UpdateStatusAsync(payload);
}

public async Task UpdateStatusAsync(StatusUpdate payload)
private async Task UpdateStatusAsync(StatusUpdate payload)
{
var frame = new SocketFrame<StatusUpdate>()
{
Expand Down
4 changes: 0 additions & 4 deletions src/API/Discord.API/Models/Enums/Messages/ComponentType.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// Quarrel © 2022

using System;
using System.Collections.Generic;
using System.Text;

namespace Discord.API.Models.Enums.Messages
{
public enum ComponentType
Expand Down
4 changes: 0 additions & 4 deletions src/API/Discord.API/Models/Enums/Messages/MessageFlags.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
// Quarrel © 2022

using System;
using System.Collections.Generic;
using System.Text;

namespace Discord.API.Models.Enums.Messages
{
public enum MessageFlags
Expand Down
8 changes: 8 additions & 0 deletions src/API/Discord.API/Models/Enums/Users/UserStatus.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Quarrel © 2022

using Quarrel.Attributes;

namespace Discord.API.Models.Enums.Users
{
/// <summary>
Expand All @@ -10,31 +12,37 @@ public enum UserStatus
/// <summary>
/// The user is offline.
/// </summary>
[StringValue("offline")]
Offline,

/// <summary>
/// The user is online.
/// </summary>
[StringValue("online")]
Online,

/// <summary>
/// The user is idle.
/// </summary>
[StringValue("idle")]
Idle,

/// <summary>
/// The user is AFK.
/// </summary>
[StringValue("afk")]
AFK,

/// <summary>
/// The user is on do not disturb.
/// </summary>
[StringValue("dnd")]
DoNotDisturb,

/// <summary>
/// The user is marked offline.
/// </summary>
[StringValue("invisible")]
Invisible,
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Quarrel © 2022

using Discord.API.Models.Json.Users;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

// JSON models don't need to respect standard nullable rules.
#pragma warning disable CS8618

namespace Discord.API.Models.Json.Applications
{
internal class JsonApplication
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Quarrel © 2022

using Discord.API.Models.Enums.Messages;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Json.Serialization;

// JSON models don't need to respect standard nullable rules.
#pragma warning disable CS8618

namespace Discord.API.Models.Json.Messages
{
internal class JsonMessageComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using Discord.API.Models.Json.Users;
using System.Text.Json.Serialization;

// JSON models don't need to respect standard nullable rules.
#pragma warning disable CS8618

namespace Discord.API.Models.Json.Messages
{
internal class JsonMessageInteraction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
using Discord.API.Models.Enums.Stickers;
using System.Text.Json.Serialization;

// JSON models don't need to respect standard nullable rules.
#pragma warning disable CS8618

namespace Discord.API.Models.Json.Messages
{
internal class JsonMessageStickerItem
Expand Down
15 changes: 15 additions & 0 deletions src/API/Discord.API/Models/Json/Settings/JsonModifyUserSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Quarrel © 2022

using System.Text.Json.Serialization;

// JSON models don't need to respect standard nullable rules.
#pragma warning disable CS8618

namespace Discord.API.Models.Json.Settings
{
internal class JsonModifyUserSettings
{
[JsonPropertyName("status")]
public string Status { get; set; }
}
}
8 changes: 8 additions & 0 deletions src/API/Discord.API/Rest/DiscordRestFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ internal IChannelService GetChannelService()
{
return RestService.For<IChannelService>(GetHttpClient(), _settings);
}

/// <summary>
/// Gets an instance of the <see cref="IUserService"/>.
/// </summary>
internal IUserService GetUserService()
{
return RestService.For<IUserService>(GetHttpClient(), _settings);
}

private HttpClient GetHttpClient(bool authenticated = true)
{
Expand Down
3 changes: 3 additions & 0 deletions src/API/Discord.API/Rest/IChannelService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@ internal interface IChannelService

[Post("/v9/channels/{channelId}/messages")]
Task<JsonMessage> CreateMessage([AliasAs("channelId")] ulong channelId, [Body] JsonMessageUpsert message);

[Delete("/v9/channels/{channelId}/messages/{messageId}")]
Task DeleteMessage([AliasAs("channelId")] ulong channelId, [AliasAs("messageId")] ulong messageId);
}
}
15 changes: 15 additions & 0 deletions src/API/Discord.API/Rest/IUserService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Quarrel © 2022

using Discord.API.Models.Json.Settings;
using Refit;
using System.Threading.Tasks;

namespace Discord.API.Rest
{
internal interface IUserService
{
[Patch("/v6/users/@me/settings")]
[Headers("Content-Type: application/json;")]
Task UpdateSettings([Body] JsonModifyUserSettings settings);
}
}
10 changes: 10 additions & 0 deletions src/Libs/Quarrel.Common/Quarrel.Common.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Quarrel.Common</AssemblyName>
<RootNamespace>Quarrel</RootNamespace>
<Configurations>Debug;Insider;Alpha;Release</Configurations>
</PropertyGroup>

</Project>
5 changes: 0 additions & 5 deletions src/Libs/Quarrel.Markdown/Quarrel.Markdown.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3814,11 +3814,6 @@
<Content Include="Assets\Emoji\ae.svg" />
<Content Include="Assets\Emoji\e50a.svg" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Xaml.Interactivity">
<HintPath>..\..\..\..\..\..\.nuget\packages\microsoft.xaml.behaviors.uwp.managed\2.0.1\lib\uap10.0\Microsoft.Xaml.Interactivity.dll</HintPath>
</Reference>
</ItemGroup>
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '14.0' ">
<VisualStudioVersion>14.0</VisualStudioVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ internal TimestampElement(Timestamp timestamp) : base(timestamp)
{
"F" or "" => timestamp.Time.ToString("F"),
"D" => timestamp.Time.ToString("d MMMM yyyy"),
"R" => timestamp.Time.Humanize(),
"T" => timestamp.Time.ToString("T"),
"d" => timestamp.Time.ToString("d"),
"f" => timestamp.Time.ToString("MMMM yyyy HH:mm"),
"t" => timestamp.Time.ToString("t"),
"R" or _ => timestamp.Time.Humanize(),
};
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/Quarrel.Client/Models/Messages/Embeds/Attachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,51 @@

namespace Quarrel.Client.Models.Messages.Embeds
{
/// <summary>
/// An attachment in a message.
/// </summary>
public class Attachment : SnowflakeItem
{
internal Attachment(JsonAttachment jsonAttachment, QuarrelClient context) :
base(context)
{
Id = jsonAttachment.Id;
Filename = jsonAttachment.Filename;
Size = jsonAttachment.Size;
Url = jsonAttachment.Url;
ProxyUrl = jsonAttachment.ProxyUrl;
Height = jsonAttachment.Height;
Width = jsonAttachment.Width;
}

/// <summary>
/// Gets the name of the attached file.
/// </summary>
public string Filename { get; }

/// <summary>
/// Gets the size of the attached file.
/// </summary>
public ulong Size { get; }

/// <summary>
/// Gets the url of the attached file.
/// </summary>
public string Url { get; }

/// <summary>
/// Gets the proxy url of the attached file.
/// </summary>
public string ProxyUrl { get; }

/// <summary>
/// Gets the height of the attached file if the file is an image or video.
/// </summary>
public int? Height { get; }

/// <summary>
/// Gets the width of the attached file if the file is an image or video.
/// </summary>
public int? Width { get; }
}
}
18 changes: 16 additions & 2 deletions src/Quarrel.Client/Models/Messages/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
using Quarrel.Client.Models.Users;
using System;

// JSON models don't need to respect standard nullable rules.
#pragma warning disable CS8618

namespace Quarrel.Client.Models.Messages
{
/// <summary>
Expand Down Expand Up @@ -66,8 +69,10 @@ internal Message(JsonMessage jsonMessage, QuarrelClient context) :
Interaction = jsonMessage.Interaction;
}

public ulong? ChannelId { get; private set; }
/// <inheritdoc/>
public ulong ChannelId { get; private set; }

/// <inheritdoc/>
public ulong? GuildId { get; private set; }

/// <inheritdoc/>
Expand All @@ -92,7 +97,10 @@ internal Message(JsonMessage jsonMessage, QuarrelClient context) :
public DateTimeOffset? EditedTimestamp { get; private set; }

/// <inheritdoc/>
public User? Author { get; private set; }
public User Author { get; private set; }

/// <inheritdoc/>
public bool IsOwn => Author.Id == Context.CurrentUser?.Id;

/// <inheritdoc/>
public User[] Mentions { get; private set; }
Expand All @@ -108,5 +116,11 @@ internal Message(JsonMessage jsonMessage, QuarrelClient context) :

/// <inheritdoc/>
public ulong? WebhookId { get; private set; }

/// <inheritdoc/>
public Uri MessageUri
=> new Uri($"https://discord.com/channels/{GuildDisplayId}/{ChannelId}/{Id}");

private string GuildDisplayId => GuildId.HasValue ? $"{GuildId.Value}" : "@me";
}
}
Loading