mcdiscordbot/MinecraftDiscordBot/Message.cs
Michael Chen 0b9cb03bae
Implemented auto updating lua script
Downloads latest script from server if outdated (10 seconds)
Server sends encrypted token to client to keep session new and rejects
..old tokens
This allows updating the script in this repository
2022-01-16 21:31:07 +01:00

65 lines
2.2 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.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";
}