Skip to content

Commit

Permalink
Moving to line-based triggers for chat capture
Browse files Browse the repository at this point in the history
This addresses iLPdev#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.
  • Loading branch information
eterchun committed Feb 17, 2023
1 parent b4e4d40 commit 88cc73f
Showing 1 changed file with 103 additions and 0 deletions.
103 changes: 103 additions & 0 deletions prs-chat.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PRSchat = PRSchat or {}
PRSchat.triggers = PRSchat.triggers or {}

function PRSchat.tabs()
local EMCO = require("PRS.emco")
PRSchat.UW = Geyser.UserWindow:new({name = "Chat", titleText ="Procedural Realms", y="50%", docked = true})
Expand Down Expand Up @@ -30,3 +32,104 @@ function PRSchat.tabs()
preserveBackground = true,
}, PRSchat.UW)
end


function PRSchat.stop()
for k, v in pairs(PRSchat.triggers) do
killTrigger(v)
end

return true
end

function PRSchat.initialize()
if not PRSchat.triggers.chat_trigger_id then
PRSchat.triggers.chat_trigger_id = tempRegexTrigger("^< Chat \\| (?<sender>.+) > (?<msg>.+)$", function()
local chat_lines = {}

PRSchat.triggers.chat_line_id = tempRegexTrigger(".*", function()
if isPrompt() then
local concat_lines = table.concat(chat_lines)
local result = concat_lines:sub(1, -2).."\n"

PRSchat.EMCO:decho("Chat", result, false)
killTrigger(PRSchat.triggers.chat_line_id)
else
table.insert(chat_lines, copy2decho().." ")
end
end)
end)
end

if not PRSchat.triggers.newbie_trigger_id then
PRSchat.triggers.newbie_trigger_id = tempRegexTrigger("^< Newbie \\| (?<sender>.+) > (?<msg>.+)$", function()
local chat_lines = {}

PRSchat.triggers.newbie_line_id = tempRegexTrigger(".*", function()
if isPrompt() then
local concat_lines = table.concat(chat_lines)
local result = concat_lines:sub(1, -2).."\n"

PRSchat.EMCO:decho("Newbie", result, false)
killTrigger(PRSchat.triggers.newbie_line_id)
else
table.insert(chat_lines, copy2decho().." ")
end
end)
end)
end

if not PRSchat.triggers.trade_trigger_id then
PRSchat.triggers.trade_trigger_id = tempRegexTrigger("^< Trade \\| (?<sender>.+) > (?<msg>.+)$", function()
local chat_lines = {}

PRSchat.triggers.trade_line_id = tempRegexTrigger(".*", function()
if isPrompt() then
local concat_lines = table.concat(chat_lines)
local result = concat_lines:sub(1, -2).."\n"

PRSchat.EMCO:decho("Trade", result, false)
killTrigger(PRSchat.triggers.trade_line_id)
else
table.insert(chat_lines, copy2decho().." ")
end
end)
end)
end

if not PRSchat.triggers.local_trigger_id then
PRSchat.triggers.local_trigger_id = tempRegexTrigger("^(?<sender>.+) say(?<s>s)?, '(?<msg>.+)$", function()
local chat_lines = {}

PRSchat.triggers.local_line_id = tempRegexTrigger(".+", function()
table.insert(chat_lines, copy2decho().." ")
if string.ends(line, "'") then
local concat_lines = table.concat(chat_lines)
local result = concat_lines:sub(1, -2).."\n"

PRSchat.EMCO:decho("Local", result, false)
killTrigger(PRSchat.triggers.local_line_id)
end
end)
end)
end

if not PRSchat.triggers.tell_trigger_id then
PRSchat.triggers.tell_trigger_id = tempRegexTrigger("^(?<from>.+) tell(?<s>s)? (?<to>\\w+), '(?<msg>.+)$", function()
local chat_lines = {}

PRSchat.triggers.tell_line_id = tempRegexTrigger(".+", function()
table.insert(chat_lines, copy2decho().." ")
if string.ends(line, "'") then
local concat_lines = table.concat(chat_lines)
local result = concat_lines:sub(1, -2).."\n"

PRSchat.EMCO:decho("Tell", result, false)
killTrigger(PRSchat.triggers.tell_line_id)
end
end)
end)
end
end

PRSchat.initialize()

0 comments on commit 88cc73f

Please sign in to comment.