Skip to content

Commit 2d9416a

Browse files
authored
fix(chat): 🐛 Change to line-based triggers for chat capture (#44) (#47)
fix(chat): Chane to Line-based triggers for chat capture (#44) Moving to line-based triggers for chat capture This addresses #4 but should be tested because improper line captures can cause Mudlet to crash. Also, I am currently getting a strange echo of chats and events, which seems to be server-related, but I can't be sure. Authored-by: eterchun <[email protected]>
1 parent e85f777 commit 2d9416a

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

prs-chat.lua

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
PRSchat = PRSchat or {}
2+
PRSchat.triggers = PRSchat.triggers or {}
3+
24
function PRSchat.tabs()
35
local EMCO = require("PRS.emco")
46
PRSchat.UW = Geyser.UserWindow:new({name = "Chat", titleText ="Procedural Realms", y="50%", docked = true})
@@ -30,3 +32,104 @@ function PRSchat.tabs()
3032
preserveBackground = true,
3133
}, PRSchat.UW)
3234
end
35+
36+
37+
function PRSchat.stop()
38+
for k, v in pairs(PRSchat.triggers) do
39+
killTrigger(v)
40+
end
41+
42+
return true
43+
end
44+
45+
function PRSchat.initialize()
46+
if not PRSchat.triggers.chat_trigger_id then
47+
PRSchat.triggers.chat_trigger_id = tempRegexTrigger("^< Chat \\| (?<sender>.+) > (?<msg>.+)$", function()
48+
local chat_lines = {}
49+
50+
PRSchat.triggers.chat_line_id = tempRegexTrigger(".*", function()
51+
if isPrompt() then
52+
local concat_lines = table.concat(chat_lines)
53+
local result = concat_lines:sub(1, -2).."\n"
54+
55+
PRSchat.EMCO:decho("Chat", result, false)
56+
killTrigger(PRSchat.triggers.chat_line_id)
57+
else
58+
table.insert(chat_lines, copy2decho().." ")
59+
end
60+
end)
61+
end)
62+
end
63+
64+
if not PRSchat.triggers.newbie_trigger_id then
65+
PRSchat.triggers.newbie_trigger_id = tempRegexTrigger("^< Newbie \\| (?<sender>.+) > (?<msg>.+)$", function()
66+
local chat_lines = {}
67+
68+
PRSchat.triggers.newbie_line_id = tempRegexTrigger(".*", function()
69+
if isPrompt() then
70+
local concat_lines = table.concat(chat_lines)
71+
local result = concat_lines:sub(1, -2).."\n"
72+
73+
PRSchat.EMCO:decho("Newbie", result, false)
74+
killTrigger(PRSchat.triggers.newbie_line_id)
75+
else
76+
table.insert(chat_lines, copy2decho().." ")
77+
end
78+
end)
79+
end)
80+
end
81+
82+
if not PRSchat.triggers.trade_trigger_id then
83+
PRSchat.triggers.trade_trigger_id = tempRegexTrigger("^< Trade \\| (?<sender>.+) > (?<msg>.+)$", function()
84+
local chat_lines = {}
85+
86+
PRSchat.triggers.trade_line_id = tempRegexTrigger(".*", function()
87+
if isPrompt() then
88+
local concat_lines = table.concat(chat_lines)
89+
local result = concat_lines:sub(1, -2).."\n"
90+
91+
PRSchat.EMCO:decho("Trade", result, false)
92+
killTrigger(PRSchat.triggers.trade_line_id)
93+
else
94+
table.insert(chat_lines, copy2decho().." ")
95+
end
96+
end)
97+
end)
98+
end
99+
100+
if not PRSchat.triggers.local_trigger_id then
101+
PRSchat.triggers.local_trigger_id = tempRegexTrigger("^(?<sender>.+) say(?<s>s)?, '(?<msg>.+)$", function()
102+
local chat_lines = {}
103+
104+
PRSchat.triggers.local_line_id = tempRegexTrigger(".+", function()
105+
table.insert(chat_lines, copy2decho().." ")
106+
if string.ends(line, "'") then
107+
local concat_lines = table.concat(chat_lines)
108+
local result = concat_lines:sub(1, -2).."\n"
109+
110+
PRSchat.EMCO:decho("Local", result, false)
111+
killTrigger(PRSchat.triggers.local_line_id)
112+
end
113+
end)
114+
end)
115+
end
116+
117+
if not PRSchat.triggers.tell_trigger_id then
118+
PRSchat.triggers.tell_trigger_id = tempRegexTrigger("^(?<from>.+) tell(?<s>s)? (?<to>\\w+), '(?<msg>.+)$", function()
119+
local chat_lines = {}
120+
121+
PRSchat.triggers.tell_line_id = tempRegexTrigger(".+", function()
122+
table.insert(chat_lines, copy2decho().." ")
123+
if string.ends(line, "'") then
124+
local concat_lines = table.concat(chat_lines)
125+
local result = concat_lines:sub(1, -2).."\n"
126+
127+
PRSchat.EMCO:decho("Tell", result, false)
128+
killTrigger(PRSchat.triggers.tell_line_id)
129+
end
130+
end)
131+
end)
132+
end
133+
end
134+
135+
PRSchat.initialize()

0 commit comments

Comments
 (0)