mcdiscordbot/MinecraftDiscordBot/Models/Message.cs

65 lines
2.2 KiB
C#
Raw Normal View History

2022-01-10 16:10:32 +01:00
using Discord.WebSocket;
using Newtonsoft.Json;
namespace MinecraftDiscordBot.Models;
2022-01-10 16:10:32 +01:00
public abstract class Message {
[JsonProperty("type")]
public abstract string Type { get; }
}
public class CapabilityMessage : Message {
public override string Type => "roles";
[JsonProperty("role", Required = Required.Always)]
public string[] Role { get; set; } = default!;
}
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";
[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; }
[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;
public override string Type => "reply";
}
public class RequestMessage : Message {
public RequestMessage(int answerId, string method, Dictionary<string, object>? parameters = null) {
AnswerId = answerId;
Method = method;
Parameters = (parameters ?? Enumerable.Empty<KeyValuePair<string, object>>())
.ToDictionary(i => i.Key, i => i.Value);
}
[JsonProperty("id")]
public int AnswerId { get; set; }
[JsonProperty("method")]
public string Method { get; set; }
[JsonProperty("params")]
public Dictionary<string, object> Parameters { get; }
public override string Type => "request";
2022-01-10 16:10:32 +01:00
}