JacobTech
d8fbf281d0
I moved the two server types to their own classes to prevent API calls to a server, not of that type.
60 lines
1.9 KiB
C#
Executable File
60 lines
1.9 KiB
C#
Executable File
using Luski.net.Interfaces;
|
|
using Luski.net.JsonTypes.BaseTypes;
|
|
using System;
|
|
using System.Text;
|
|
using System.Text.Json.Serialization;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using JacobTechEncryption;
|
|
|
|
namespace Luski.net.Structures.Main;
|
|
|
|
public class MainSocketMessage : IncomingHTTP
|
|
{
|
|
public MainServer Server { get; internal set; } = default!;
|
|
[JsonPropertyName("id")]
|
|
[JsonInclude]
|
|
public long Id { get; internal set; } = default!;
|
|
[JsonPropertyName("user_id")]
|
|
[JsonInclude]
|
|
public long AuthorID { get; internal set; } = default!;
|
|
[JsonPropertyName("content")]
|
|
[JsonInclude]
|
|
public string Context { get; internal set; } = default!;
|
|
[JsonPropertyName("channel_id")]
|
|
[JsonInclude]
|
|
public long ChannelID { get; internal set; } = default!;
|
|
[JsonPropertyName("files")]
|
|
[JsonInclude]
|
|
public File[]? Files { get; internal set; } = default!;
|
|
public async Task<IUser> GetAuthor(CancellationToken CancellationToken)
|
|
{
|
|
if (Server.User.Id != AuthorID) return await Server.GetUser<MainSocketUserBase>(AuthorID, CancellationToken);
|
|
else return Server.User;
|
|
}
|
|
|
|
internal void decrypt(string? key, CancellationToken CancellationToken)
|
|
{
|
|
if (string.IsNullOrEmpty(key)) throw new ArgumentNullException(nameof(key));
|
|
Context = Encoding.UTF8.GetString(Encryption.AES.Decrypt(Convert.FromBase64String(Context), key));
|
|
if (Files is not null && Files.Length > 0)
|
|
{
|
|
for (int i = 0; i < Files.Length; i++)
|
|
{
|
|
Files[i].key = key;
|
|
Files[i].decrypt();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
[JsonSerializable(typeof(MainSocketMessage))]
|
|
[JsonSourceGenerationOptions(
|
|
GenerationMode = JsonSourceGenerationMode.Default,
|
|
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
|
|
WriteIndented = false)]
|
|
public partial class MainSocketMessageContext : JsonSerializerContext
|
|
{
|
|
|
|
}
|