Histacom2/Histacom2.Engine/MessageParser.cs

32 lines
1.1 KiB
C#
Raw Permalink Normal View History

2017-03-31 14:28:34 -04:00
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2017-08-23 13:38:40 -04:00
namespace Histacom2.Engine
2017-03-31 14:28:34 -04:00
{
2017-04-30 20:21:05 -04:00
public class MessageParser
2017-03-31 14:28:34 -04:00
{
public string ParseMessage(string json, int index, string user)
{
JObject message = JObject.Parse(JObject.Parse(json)["messages"][index].ToString());
string newmsg = message["message"].ToString().Replace("@user", user);
2017-07-21 00:15:10 -04:00
if (!message["special"].ToString().StartsWith(".")) newmsg += Environment.NewLine;
2017-03-31 17:44:01 -04:00
if (message["userchat"].ToObject<bool>()) return message["user"].ToString() + ": " + newmsg;
else return newmsg;
2017-03-31 14:28:34 -04:00
}
public int GetMessageDelay(string json, int index)
{
JObject message = JObject.Parse(JObject.Parse(json)["messages"][index].ToString());
return message["delay"].ToObject<int>();
}
2017-03-31 17:44:01 -04:00
public string GetSpecial(string json, int index)
{
JObject message = JObject.Parse(JObject.Parse(json)["messages"][index].ToString());
return message["special"].ToString();
}
2017-03-31 14:28:34 -04:00
}
}