2022-01-10 16:10:32 +01:00
|
|
|
|
using Discord.WebSocket;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
2022-01-16 22:29:50 +01:00
|
|
|
|
namespace MinecraftDiscordBot.Models;
|
2022-01-10 16:10:32 +01:00
|
|
|
|
|
|
|
|
|
public abstract class Message {
|
|
|
|
|
[JsonProperty("type")]
|
|
|
|
|
public abstract string Type { get; }
|
|
|
|
|
}
|
2022-01-11 20:32:25 +01:00
|
|
|
|
|
|
|
|
|
public class CapabilityMessage : Message {
|
|
|
|
|
public override string Type => "roles";
|
|
|
|
|
[JsonProperty("role", Required = Required.Always)]
|
2022-01-15 21:26:32 +01:00
|
|
|
|
public string[] Role { get; set; } = default!;
|
2022-01-11 20:32:25 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-10 16:10:32 +01:00
|
|
|
|
public class TextMessage : Message {
|
|
|
|
|
public TextMessage(SocketMessage arg) : this(arg.Author.Username, arg.Content) { }
|
|
|
|
|
public TextMessage(string author, string content) {
|
|
|
|
|
Author = author;
|
|
|
|
|
Content = content;
|
|
|
|
|
}
|
|
|
|
|
public override string Type => "text";
|
2022-01-11 20:32:25 +01:00
|
|
|
|
[JsonProperty("author", Required = Required.Always)]
|
|
|
|
|
public string Author { get; set; }
|
|
|
|
|
[JsonProperty("message", Required = Required.Always)]
|
|
|
|
|
public string Content { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ReplyMessage : Message {
|
|
|
|
|
public ReplyMessage(int answerId, string result) {
|
|
|
|
|
AnswerId = answerId;
|
|
|
|
|
Result = result;
|
|
|
|
|
}
|
|
|
|
|
[JsonProperty("id", Required = Required.Always)]
|
|
|
|
|
public int AnswerId { get; set; }
|
|
|
|
|
[JsonProperty("result", Required = Required.Always)]
|
|
|
|
|
public string Result { get; set; }
|
2022-01-15 21:26:32 +01:00
|
|
|
|
[JsonProperty("chunk", Required = Required.DisallowNull)]
|
|
|
|
|
public int Chunk { get; set; } = 1;
|
|
|
|
|
[JsonProperty("total", Required = Required.DisallowNull)]
|
|
|
|
|
public int Total { get; set; } = 1;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// If at least one packet was received where
|
|
|
|
|
/// </summary>
|
|
|
|
|
[JsonProperty("success", Required = Required.DisallowNull)]
|
|
|
|
|
public bool Success { get; set; } = true;
|
2022-01-11 20:32:25 +01:00
|
|
|
|
public override string Type => "reply";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class RequestMessage : Message {
|
2022-01-16 21:31:07 +01:00
|
|
|
|
public RequestMessage(int answerId, string method, Dictionary<string, object>? parameters = null) {
|
2022-01-11 20:32:25 +01:00
|
|
|
|
AnswerId = answerId;
|
|
|
|
|
Method = method;
|
2022-01-16 21:31:07 +01:00
|
|
|
|
Parameters = (parameters ?? Enumerable.Empty<KeyValuePair<string, object>>())
|
2022-01-11 20:32:25 +01:00
|
|
|
|
.ToDictionary(i => i.Key, i => i.Value);
|
|
|
|
|
}
|
|
|
|
|
[JsonProperty("id")]
|
|
|
|
|
public int AnswerId { get; set; }
|
|
|
|
|
[JsonProperty("method")]
|
|
|
|
|
public string Method { get; set; }
|
|
|
|
|
[JsonProperty("params")]
|
2022-01-16 21:31:07 +01:00
|
|
|
|
public Dictionary<string, object> Parameters { get; }
|
2022-01-11 20:32:25 +01:00
|
|
|
|
public override string Type => "request";
|
2022-01-10 16:10:32 +01:00
|
|
|
|
}
|