From 4f25f903dd18acd7fd57f501f7e36a7b34c865f2 Mon Sep 17 00:00:00 2001 From: lili-ffxi <40600148+lili-ffxi@users.noreply.github.com> Date: Wed, 3 Apr 2024 23:17:59 +0100 Subject: [PATCH 1/3] Update send.lua Extensive code revision Added two new targets: @party and @zone --- addons/send/send.lua | 118 +++++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 44 deletions(-) diff --git a/addons/send/send.lua b/addons/send/send.lua index c25fe441a..12383de2d 100644 --- a/addons/send/send.lua +++ b/addons/send/send.lua @@ -1,7 +1,7 @@ -_addon.version = '1.1' +_addon.version = '1.2' _addon.name = 'Send' _addon.command = 'send' -_addon.author = 'Byrth' +_addon.author = 'Byrth, Lili' local debug = false @@ -10,10 +10,10 @@ require('chat') windower.register_event('addon command', function (...) if ...:lower() == '@debug' then debug = not debug - windower.add_to_chat(55, 'send: debug ' .. tostring(dbg)) + windower.add_to_chat(55, 'send: debug ' .. tostring(debug)) return end - + local term = T{...}:map(function(str) str = windower.convert_auto_trans(str):strip_format() if str:find(' ', string.encoding.shift_jis) then @@ -25,55 +25,86 @@ windower.register_event('addon command', function (...) return entity and entity.id or '<' .. target_string .. 'id>' end) - if dbg then + if debug then windower.add_to_chat(207, 'send (debug): '..term) end - local broken_init = split(term,' ') - local qual = table.remove(broken_init,1) + local broken_init = split(term, ' ') + local qual = table.remove(broken_init, 1):lower() local player = windower.ffxi.get_player() - - if player and qual:lower()==player['name']:lower() then - if broken_init ~= nil then - relevant_msg(table.concat(broken_init,' ')) + + if #broken_init < 1 then + return + end + + if player and qual == player['name']:lower() then + relevant_msg(table.concat(broken_init, ' ')) + return + elseif qual == '@all' or qual == '@'..player.main_job:lower() then + if player then + relevant_msg(table.concat(broken_init, ' ')) end - elseif qual:lower()=='@all' or qual:lower()=='@'..player.main_job:lower() then - if broken_init ~= nil then - relevant_msg(table.concat(broken_init,' ')) + elseif qual:startswith('@party') then + if player then + relevant_msg(table.concat(broken_init, ' ')) end - windower.send_ipc_message('send ' .. term) - else - windower.send_ipc_message('send ' .. term) + local qual = qual .. windower.ffxi.get_player().name + term = qual .. ' ' .. table.concat(broken_init, ' ') + elseif qual:startswith('@zone') then + if player then + relevant_msg(table.concat(broken_init, ' ')) + end + local qual = qual .. windower.ffxi.get_info().zone + term = qual .. ' ' .. table.concat(broken_init, ' ') end + + windower.send_ipc_message('send ' .. term) end) -windower.register_event('ipc message',function (msg) - local broken = split(msg, ' ') +windower.register_event('ipc message', function (msg) + if debug then + windower.add_to_chat(207, 'send receive (debug): ' .. msg) + end + local broken = split(msg, ' ') local command = table.remove(broken, 1) - if command ~= 'send' then + + if command ~= 'send' or #broken < 2 then return end - - if #broken < 2 then return end local qual = table.remove(broken,1) local player = windower.ffxi.get_player() - if player and qual:lower()==player.name:lower() then - relevant_msg(table.concat(broken, ' ')) + if not player then + return end - if string.char(qual:byte(1)) == '@' then - local arg = string.char(qual:byte(2, qual:len())) - if player and arg:upper() == player.main_job:upper() then - if broken ~= nil then - relevant_msg(table.concat(broken, ' ')) - end - elseif arg:upper() == 'ALL' then - if broken ~= nil then + + if qual:lower() == player.name:lower() then + relevant_msg(table.concat(broken, ' ')) + elseif string.char(qual:byte(1)) == '@' then + local arg = string.char(qual:byte(2, qual:len())):upper() + + if arg == player.main_job:upper() or arg == 'ALL' or arg == 'OTHERS' then + relevant_msg(table.concat(broken, ' ')) + elseif arg:startswith('PARTY') then + local name = arg:sub(6,#arg):lower() + local party = windower.ffxi.get_party() + local sameparty = function() + for i=1,5 do + local idx = 'p'..i + if party[idx] and party[idx].name:lower() == name then + return true + end + end + end() + + if sameparty then relevant_msg(table.concat(broken, ' ')) end - elseif arg:upper() == 'OTHERS' then - if broken ~= nil then + elseif arg:upper():startswith('ZONE') then + local samezone = tonumber(arg:sub(5,#arg)) == windower.ffxi.get_info().zone + + if samezone then relevant_msg(table.concat(broken, ' ')) end end @@ -88,29 +119,28 @@ function split(msg, match) while u <= length do local nextanch = msg:find(match, string.encoding.shift_jis, u) if nextanch ~= nil then - splitarr[#splitarr+1] = msg:sub(u,nextanch-match:len()) - if nextanch~=length then - u = nextanch+match:len() + splitarr[#splitarr + 1] = msg:sub(u, nextanch - match:len()) + if nextanch ~= length then + u = nextanch + match:len() else u = length end else - splitarr[#splitarr+1] = msg:sub(u,length) - u = length+1 + splitarr[#splitarr + 1] = msg:sub(u, length) + u = length + 1 end end return splitarr end function relevant_msg(msg) - if msg:sub(1,2)=='//' then + if msg:sub(1,2) == '//' then windower.send_command(msg:sub(3)) - elseif msg:sub(1,1)=='/' then + elseif msg:sub(1,1) == '/' then windower.send_command('input '..msg) - elseif msg:sub(1,3)=='atc' then - windower.add_to_chat(55,msg:sub(5)) + elseif msg:sub(1,3) == 'atc' then + windower.add_to_chat(55, msg:sub(5)) else windower.send_command(msg) end - end From 2ed4ac2185ba3fb0c5903367fa9f38d8299e00fa Mon Sep 17 00:00:00 2001 From: lili-ffxi <40600148+lili-ffxi@users.noreply.github.com> Date: Wed, 3 Apr 2024 23:24:02 +0100 Subject: [PATCH 2/3] Update send.lua All commas are now properly married to a space each --- addons/send/send.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/addons/send/send.lua b/addons/send/send.lua index 12383de2d..1512cf346 100644 --- a/addons/send/send.lua +++ b/addons/send/send.lua @@ -73,7 +73,7 @@ windower.register_event('ipc message', function (msg) return end - local qual = table.remove(broken,1) + local qual = table.remove(broken, 1) local player = windower.ffxi.get_player() if not player then return @@ -87,10 +87,10 @@ windower.register_event('ipc message', function (msg) if arg == player.main_job:upper() or arg == 'ALL' or arg == 'OTHERS' then relevant_msg(table.concat(broken, ' ')) elseif arg:startswith('PARTY') then - local name = arg:sub(6,#arg):lower() + local name = arg:sub(6, #arg):lower() local party = windower.ffxi.get_party() local sameparty = function() - for i=1,5 do + for i=1, 5 do local idx = 'p'..i if party[idx] and party[idx].name:lower() == name then return true @@ -102,7 +102,7 @@ windower.register_event('ipc message', function (msg) relevant_msg(table.concat(broken, ' ')) end elseif arg:upper():startswith('ZONE') then - local samezone = tonumber(arg:sub(5,#arg)) == windower.ffxi.get_info().zone + local samezone = tonumber(arg:sub(5, #arg)) == windower.ffxi.get_info().zone if samezone then relevant_msg(table.concat(broken, ' ')) @@ -134,11 +134,11 @@ function split(msg, match) end function relevant_msg(msg) - if msg:sub(1,2) == '//' then + if msg:sub(1, 2) == '//' then windower.send_command(msg:sub(3)) - elseif msg:sub(1,1) == '/' then + elseif msg:sub(1, 1) == '/' then windower.send_command('input '..msg) - elseif msg:sub(1,3) == 'atc' then + elseif msg:sub(1, 3) == 'atc' then windower.add_to_chat(55, msg:sub(5)) else windower.send_command(msg) From 8a08e008d43c86ac8af8f9802f0943fab59ae4b8 Mon Sep 17 00:00:00 2001 From: lili-ffxi <40600148+lili-ffxi@users.noreply.github.com> Date: Wed, 3 Apr 2024 23:25:28 +0100 Subject: [PATCH 3/3] Update send.lua Removed all trailing spaces --- addons/send/send.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/addons/send/send.lua b/addons/send/send.lua index 1512cf346..65c53f0ca 100644 --- a/addons/send/send.lua +++ b/addons/send/send.lua @@ -13,10 +13,10 @@ windower.register_event('addon command', function (...) windower.add_to_chat(55, 'send: debug ' .. tostring(debug)) return end - + local term = T{...}:map(function(str) str = windower.convert_auto_trans(str):strip_format() - if str:find(' ', string.encoding.shift_jis) then + if str:find(' ', string.encoding.shift_jis) then return str:enclose('"') end return str @@ -25,18 +25,18 @@ windower.register_event('addon command', function (...) return entity and entity.id or '<' .. target_string .. 'id>' end) - if debug then + if debug then windower.add_to_chat(207, 'send (debug): '..term) end local broken_init = split(term, ' ') local qual = table.remove(broken_init, 1):lower() local player = windower.ffxi.get_player() - + if #broken_init < 1 then return end - + if player and qual == player['name']:lower() then relevant_msg(table.concat(broken_init, ' ')) return @@ -62,28 +62,28 @@ windower.register_event('addon command', function (...) end) windower.register_event('ipc message', function (msg) - if debug then + if debug then windower.add_to_chat(207, 'send receive (debug): ' .. msg) end local broken = split(msg, ' ') local command = table.remove(broken, 1) - - if command ~= 'send' or #broken < 2 then + + if command ~= 'send' or #broken < 2 then return end - + local qual = table.remove(broken, 1) local player = windower.ffxi.get_player() if not player then return end - + if qual:lower() == player.name:lower() then relevant_msg(table.concat(broken, ' ')) elseif string.char(qual:byte(1)) == '@' then local arg = string.char(qual:byte(2, qual:len())):upper() - + if arg == player.main_job:upper() or arg == 'ALL' or arg == 'OTHERS' then relevant_msg(table.concat(broken, ' ')) elseif arg:startswith('PARTY') then @@ -103,7 +103,7 @@ windower.register_event('ipc message', function (msg) end elseif arg:upper():startswith('ZONE') then local samezone = tonumber(arg:sub(5, #arg)) == windower.ffxi.get_info().zone - + if samezone then relevant_msg(table.concat(broken, ' ')) end