초기커밋
This commit is contained in:
62
ServerCommon/EchoSystem/Models/EchoSystemSlackMessage.cs
Normal file
62
ServerCommon/EchoSystem/Models/EchoSystemSlackMessage.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace ServerCommon;
|
||||
|
||||
public class EchoSystemSlackMessage
|
||||
{
|
||||
[JsonProperty("text")] public string Text { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class EchoSystemSlackMessageBuilder
|
||||
{
|
||||
private EchoSystemSlackMessage m_message { get; set; } = new();
|
||||
|
||||
private string m_title { get; set; }
|
||||
private string m_server_name { get; set; }
|
||||
private string m_ip_port { get; set; }
|
||||
|
||||
private Dictionary<string, string> m_members { get; set; } = new();
|
||||
|
||||
public EchoSystemSlackMessageBuilder(string title, string serverName, string ipPort)
|
||||
{
|
||||
m_title = title;
|
||||
m_server_name = serverName;
|
||||
m_ip_port = ipPort;
|
||||
}
|
||||
|
||||
public EchoSystemSlackMessageBuilder appendValue(string key, string value, bool useCodeBlock = false)
|
||||
{
|
||||
if (useCodeBlock)
|
||||
{
|
||||
value = $"```{value}```";
|
||||
}
|
||||
|
||||
m_members.TryAdd(key, value);
|
||||
return this;
|
||||
}
|
||||
|
||||
public string build()
|
||||
{
|
||||
var txt = $">*Title*: {m_title}";
|
||||
|
||||
foreach (var member in m_members)
|
||||
{
|
||||
txt += $"\n>*{member.Key}*: {member.Value}";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(m_server_name))
|
||||
{
|
||||
txt += $"\n>*Server*: {m_server_name}";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(m_ip_port))
|
||||
{
|
||||
txt += $"\n>*IP/Port*: {m_ip_port}";
|
||||
}
|
||||
|
||||
m_message = new EchoSystemSlackMessage { Text = txt };
|
||||
var message = JsonConvert.SerializeObject(m_message);
|
||||
|
||||
return message;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user