Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 62 additions & 88 deletions addons/send/send.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,135 +5,109 @@ _addon.author = 'Byrth, Lili'

local debug = false

require('functions')
require('chat')

windower.register_event('addon command', function (...)
if ...:lower() == '@debug' then
debug = not debug
windower.add_to_chat(55, 'send: debug ' .. tostring(debug))
windower.register_event('addon command', function(target, ...)
if not target then
error('No target provided.')
return
end

local term = T{...}:map(function(str)
str = windower.convert_auto_trans(str):strip_format()
if str:find(' ', string.encoding.shift_jis) then
return str:enclose('"')
end
return str
if not ... then
error('No command provided.')
return
end

target = target:lower()

if target == '@debug' then
local arg = (... == 'on' or ... == 'off') and ... or error('Invalid argument. Usage: send @debug <on|off>')
debug = arg == 'on'
return windower.add_to_chat(55, 'send: debug ' .. tostring(debug))
end

local command = T{...}:map(string.strip_format .. windower.convert_auto_trans):map(function(str)
return str:find(' ', string.encoding.shift_jis) and str:enclose('"') or str
end):sconcat():gsub('<(%a+)id>', function(target_string)
local entity = windower.ffxi.get_mob_by_target(target_string)
return entity and entity.id or '<' .. target_string .. 'id>'
end)

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, ' '))
if player and target == player['name']:lower() then
execute_command(command)
return
elseif qual == '@all' or qual == '@'..player.main_job:lower() then
if player then
relevant_msg(table.concat(broken_init, ' '))
end
elseif qual:startswith('@party') then
elseif player and target == '@all' or target == '@'..player.main_job:lower() then
execute_command(command)
elseif target == '@party' then
if player then
relevant_msg(table.concat(broken_init, ' '))
execute_command(command)
end
local qual = qual .. windower.ffxi.get_player().name
term = qual .. ' ' .. table.concat(broken_init, ' ')
elseif qual:startswith('@zone') then
target = target .. player.name
elseif target == '@zone' then
if player then
relevant_msg(table.concat(broken_init, ' '))
execute_command(command)
end
local qual = qual .. windower.ffxi.get_info().zone
term = qual .. ' ' .. table.concat(broken_init, ' ')
target = target .. windower.ffxi.get_info().zone
end

windower.send_ipc_message('send ' .. term)
command = 'send ' .. target .. ' ' .. command

if debug then
windower.add_to_chat(207, 'send (debug): ' .. command)
end

windower.send_ipc_message(command)
end)

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' or #broken < 2 then
local info = windower.ffxi.get_info()
if not info.logged_in then
return
end

local qual = table.remove(broken, 1)
local player = windower.ffxi.get_player()
if not player then
local split = msg:split(' ', string.encoding.shift_jis, 3)
if #split < 3 or split[1] ~= 'send' 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()
local target = split[2]
local command = split[3]

local player = windower.ffxi.get_player()

if target:lower() == player.name:lower() then
execute_command(command)
elseif target:startswith('@') then
local arg = target:sub(2):lower()

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()
if arg == player.main_job:lower() or arg == 'all' or arg == 'others' then
execute_command(command)
elseif arg:startswith('party') then
local sender = 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
for i = 1, 5 do
local idx = 'p'..i
if party[idx] and party[idx].name:lower() == sender then
execute_command(command)
return
end
end()

if sameparty then
relevant_msg(table.concat(broken, ' '))
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, ' '))
elseif arg:startswith('zone') then
if tonumber(arg:sub(5)) == info.zone then
execute_command(command)
end
end
end
end)

function split(msg, match)
if msg == nil then return '' end
local length = msg:len()
local splitarr = {}
local u = 1
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()
else
u = length
end
else
splitarr[#splitarr + 1] = msg:sub(u, length)
u = length + 1
end
end
return splitarr
end

function relevant_msg(msg)
function execute_command(msg)
if msg:sub(1, 2) == '//' then
windower.send_command(msg:sub(3))
elseif msg:sub(1, 1) == '/' then
Expand Down