1
0
mirror of https://github.com/Earu/EasyChat.git synced 2025-03-04 03:13:20 -05:00

Add a convenient message history across sessions

This commit is contained in:
Earu 2020-07-26 19:56:05 +02:00
parent 3a3f6bbdf3
commit 17861c88c7
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,25 @@
local HISTORY_PATH = "easychat/msg_history.txt"
local function save_history()
if not file.Exists("easychat", "DATA") then
file.CreateDir("easychat")
end
if not IsValid(EasyChat.GUI.TextEntry) then return end
local history_length = #EasyChat.GUI.TextEntry.History
local start_pos = history_length > 100 and history_length - 100 or 1
local contents = table.concat(EasyChat.GUI.TextEntry.History, "\n", start_pos, history_length)
file.Write(HISTORY_PATH, contents)
end
hook.Add("ECPreDestroy", "EasyChatModuleMsgHistory", save_history)
hook.Add("ShutDown", "EasyChatModuleMsgHistory", save_history)
hook.Add("ECInitialized", "EasyChatModuleMsgHistory", function()
if not IsValid(EasyChat.GUI.TextEntry) then return end
local contents = file.Read(HISTORY_PATH, "DATA") or ""
EasyChat.GUI.TextEntry.History = contents:Split("\n")
EasyChat.GUI.TextEntry.HistoryPos = 0
end)
return "Message History"

View File

@ -2,6 +2,7 @@
title EasyChat Update
set /p changes="Changes: "
git add *
git commit -a -m "%changes%"
git push