added save/load support (not enabled) to chat AI

OnUnload() doesn't actually seem to get called, ever, so I added
an ifdef'd out line to the message send function that would save
the cache every single time the user sent a message. It works, but
eugh... my poor SSD works hard. I want to give it a break.
This commit is contained in:
RogueAI42 2017-08-03 22:11:35 +10:00
parent 19fceb8326
commit 80f7d54de9

View file

@ -93,7 +93,12 @@ namespace ShiftOS.Frontend.Apps
//Let's try the AI stuff... :P
if (!messagecache.Contains(_messages.Last().Message))
{
messagecache.Add(_messages.Last().Message);
#if RIP_USERS_SSD
SaveCache();
#endif
}
var rmsg = messagecache[rnd.Next(messagecache.Count)];
var split = new List<string>(rmsg.Split(' '));
List<string> nmsg = new List<string>();
@ -127,7 +132,7 @@ namespace ShiftOS.Frontend.Apps
readonly string[] outcomes = new string[] { "ok", "sure", "yeah", "yes", "no", "nope", "alright" };
Random rnd = new Random();
List<string> messagecache = new List<string>();
private List<string> messagecache = new List<string>();
public void SendClientMessage(string nick, string message)
{
@ -170,21 +175,30 @@ namespace ShiftOS.Frontend.Apps
}
gfx.DrawRectangle(vertSeparatorLeft, 0, 1, _bottomseparator, UIManager.SkinTextures["ControlTextColor"]);
}
public void OnLoad()
{
if (System.IO.File.Exists("aicache.dat"))
messagecache = System.IO.File.ReadAllLines("aicache.dat").ToList();
}
public void OnSkinLoad()
{
}
public bool OnUnload()
{
// this doesn't get called... dammit
SaveCache();
return true;
}
private void SaveCache()
{
// It's watching you...
System.IO.File.WriteAllLines("aicache.dat", messagecache);
}
public void OnUpgrade()
{
}