mcdiscordbot/MinecraftDiscordBot/Message.cs
Michael Chen 1579430f76
ChunkWise message waiter
Refined Storage basic implementation
2022-01-11 20:32:25 +01:00

60 lines
2.0 KiB
C#

using Discord.WebSocket;
using Newtonsoft.Json;
namespace MinecraftDiscordBot;
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!;
}
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.Always)]
public int Chunk { get; set; }
[JsonProperty("total", Required = Required.Always)]
public int Total { get; set; }
public override string Type => "reply";
}
public class RequestMessage : Message {
public RequestMessage(int answerId, string method, Dictionary<string, string>? parameters = null) {
AnswerId = answerId;
Method = method;
Parameters = (parameters ?? Enumerable.Empty<KeyValuePair<string, string>>())
.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, string> Parameters { get; }
public override string Type => "request";
}