Skip to content

Commit 802b2ad

Browse files
committed
ChatMon: Fixes, cleanup
1 parent 2cf2f27 commit 802b2ad

File tree

10 files changed

+199
-134
lines changed

10 files changed

+199
-134
lines changed

addons/chatmon/ChatMon.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" ?>
2+
<ChatMon>
3+
<settings
4+
DisableOnFocus="false"
5+
TellSound="Tell"
6+
ExamineSound=""
7+
EmoteSound="Emote"
8+
TalkSound="Talk"
9+
InviteSound="Invite"
10+
SoundInterval="0"
11+
DisableFilters="true"
12+
/>
13+
<!-- Add Triggers below. The line below is a comment for an example -->
14+
<!-- Valid From entries: Say, Shout, Party, Linkshell, Tell, Invite, Emote, Examine, All -->
15+
<!-- match should not be used for Emote. Examine matches to Examiners name, Invite matches to Inviters name. -->
16+
<!-- <trigger match="*YourNickNameHere*" notmatch="*SomecommonMatch*" notfrom="Tell" from="Party|Linkshell" sound="Talk" /> -->
17+
<trigger match="*[2]&lt;*Me*&gt;*" from="ALL" sound="" />
18+
<trigger match="*me*" from="Linkshell" sound="Talk" />
19+
<trigger match="*[2]*me*" from="ALL" sound="Talk" />
20+
<trigger match="*me*" from="Party" sound="Talk" />
21+
<trigger match="*" from="Party" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\MetallicCLICK.wav" />
22+
<trigger match="*" from="Linkshell" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\MetallicCLICK.wav" />
23+
<trigger match="*[2]&lt;*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\MetallicCLICK.wav" />
24+
<trigger match="*A mog tablet has been discovered in*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\MogTablet.wav" />
25+
<trigger match="*Airship ===*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\Airship.wav" />
26+
<trigger match="*A Campaign battle has begun.*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\Campaign.wav" />
27+
<trigger match="*has begun their relentless attack on*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\Campaign.wav" />
28+
<trigger match="*stalwart defense of*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\Campaign.wav" />
29+
<trigger match="*charmed*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\alarm8.wav" />
30+
<trigger match="*embolden*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\mixkit-classic-short-alarm-993.wav" />
31+
<trigger match="*stopped augmenting*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\alarm8.wav" />
32+
<trigger match="*have breached the Balrahn Defense Line*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\BesiegedIsStarting.wav" />
33+
<trigger match="*Word has been received of a*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\BesiegedIsAdvancing.wav" />
34+
<!--
35+
36+
<trigger match="*Word has been received of a*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\BesiegedIsAdvancing.wav" />
37+
<trigger match="*Weather:*Sandstorms*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\EarthWeather.wav" />
38+
<trigger match="*=== Area: Walk of Echoes [P] ===*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\Lilith.wav" />
39+
<trigger match="*woodworking*" from="ALL" sound="C:\Program Files (x86)\Windower4\plugins\ChatMon\Woodworking.wav" />
40+
<trigger match="*Weather:*Thunderstorms*" from="ALL" sound="C:\Users\Default.Default-PC\Desktop\Windower\plugins\ChatMon\Thunder.wav" />
41+
<trigger match="*Weather:*Gales*" from="ALL" sound="C:\Users\Default.Default-PC\Desktop\Windower\plugins\ChatMon\Gales.wav" />
42+
<trigger match="*Weather:*Dark*" from="ALL" sound="C:\Users\Default.Default-PC\Desktop\Windower\plugins\ChatMon\DarkWeather.wav" />
43+
<trigger match="*Weather:*Fog*" from="ALL" sound="C:\Users\Default.Default-PC\Desktop\Windower\plugins\ChatMon\Fog.wav" />
44+
<trigger match="*Weather:*Heat*" from="ALL" sound="C:\Users\Default.Default-PC\Desktop\Windower\plugins\ChatMon\Heat.wav" />
45+
<trigger match="*Weather:*Rain*" from="ALL" sound="C:\Users\Default.Default-PC\Desktop\Windower\plugins\ChatMon\Rain.wav" />
46+
-->
47+
</ChatMon>

addons/chatmon/chatmon.lua

100644100755
Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ require('sets')
88
require('strings')
99
local config = require('config')
1010
local chat_res = require('resources').chat
11-
local plugin_settings = require('depercate_plugin')
11+
local plugin_settings = require('deprecate_plugin')
1212
local get_triggers = require('get_triggers')
1313

14+
windower.create_dir(windower.addon_path .. '/data/sounds/')
15+
1416
local defaults = {
1517
DisableOnFocus=false,
1618
SoundInterval=5,
@@ -33,37 +35,46 @@ windower.register_event('load', on_load)
3335

3436
local last_sound = 0
3537
local function play_sound(sound)
36-
if (os.time() - last_sound >= settings.SoundInterval) then
38+
if os.time() - last_sound >= settings.SoundInterval then
3739
last_sound = os.time();
38-
if(windower.file_exists(windower.addon_path .. "/data/sounds/" .. sound)) then
39-
windower.play_sound(windower.addon_path .. "/data/sounds/" .. sound)
40-
elseif (windower.file_exists(sound)) then
40+
if windower.file_exists(windower.addon_path .. '/sounds/' .. sound) then
41+
windower.play_sound(windower.addon_path .. '/sounds/' .. sound)
42+
elseif windower.file_exists(windower.addon_path .. '/data/sounds/' .. sound) then
43+
windower.play_sound(windower.addon_path .. '/data/sounds/' .. sound)
44+
elseif windower.file_exists(sound) then
4145
windower.play_sound(sound)
4246
end
4347
end
4448
end
4549

50+
local function get_match(match)
51+
if match ~= '<name>' then
52+
return match
53+
end
54+
55+
-- this is done to have parity with the old plugin.
56+
local player_name = windower.ffxi.get_player().name:lower()
57+
return '* ' .. player_name .. '|'
58+
.. player_name .. ' *|*\''
59+
.. player_name .. '\'*|*('
60+
.. player_name .. ')*|'
61+
.. player_name .. '|* '
62+
.. player_name .. ' *|* '
63+
.. player_name .. '? *|* '
64+
.. player_name .. '?|'
65+
.. player_name .. '? *|'
66+
.. player_name .. '?|*<'
67+
.. player_name .. '>*'
68+
end
69+
4670
local function check_triggers(from, text)
47-
if (windower.has_focus() and settings.DisableOnFocus) then
71+
if windower.has_focus() and settings.DisableOnFocus then
4872
return
4973
end
5074

5175
for _, trigger in ipairs(triggers) do
52-
if trigger.match == '<name>' then -- this is done to have parity with the old plugin.
53-
local player_name = windower.ffxi.get_player().name:lower()
54-
trigger.match = "* " .. player_name .. "|"
55-
.. player_name .. " *|*\""
56-
.. player_name .. "\"*|*("
57-
.. player_name .. ")*|"
58-
.. player_name .. "|* "
59-
.. player_name .. " *|* "
60-
.. player_name .. "? *|* "
61-
.. player_name .. "?|"
62-
.. player_name .. "? *|"
63-
.. player_name .. "?|*<"
64-
.. player_name .. ">*"
65-
end
66-
if (trigger.from:contains('all') or trigger.from:contains(from)) and not trigger.notFrom:contains(from) and windower.wc_match(text, trigger.match) and not windower.wc_match(text, trigger.notMatch) then
76+
local match = get_match(trigger.match)
77+
if (trigger.from:contains('all') or trigger.from:contains(from)) and not trigger.notFrom:contains(from) and windower.wc_match(text, match) and not windower.wc_match(text, trigger.notMatch) then
6778
play_sound(trigger.sound)
6879
return
6980
end

addons/chatmon/depercate_plugin.lua

Lines changed: 0 additions & 113 deletions
This file was deleted.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
if not windower.file_exists(windower.windower_path .. 'plugins\\ChatMon.dll') then
2+
return false
3+
end
4+
5+
local function read_all_lines(file_name)
6+
local f = assert(io.open(file_name, 'r'))
7+
local text = f:read('*all')
8+
f:close()
9+
return text
10+
end
11+
12+
local file = windower.windower_path .. 'plugins\\ChatMon.xml'
13+
local text = read_all_lines(file)
14+
15+
if text == '' then
16+
return nil
17+
end
18+
19+
require('strings')
20+
require('lists')
21+
22+
local quote = function(token)
23+
return '\'' .. token .. '\''
24+
end
25+
26+
local function format_set(values)
27+
if values == nil or values:length() == 0 then
28+
return 'S{}'
29+
end
30+
31+
return 'S{ ' .. values:map(quote):concat(', ') .. ' }'
32+
end
33+
34+
local sounds = {
35+
['tell'] = 'IncomingTell.wav',
36+
['talk'] = 'IncomingTalk.wav',
37+
['emote'] = 'IncomingEmote.wav',
38+
['invite'] = 'PartyInvitation.wav',
39+
['examine'] = 'IncomingExamine.wav',
40+
}
41+
42+
local function format_trigger(from, not_from, match, not_match, sound)
43+
return '{ ' .. L{
44+
'from = ' .. format_set(from),
45+
'notFrom = ' .. format_set(not_from),
46+
'match = ' .. quote(match or '*'),
47+
'notMatch = ' .. quote(not_match or ''),
48+
'sound = ' .. quote(sound),
49+
}:concat(', ') .. ' }'
50+
end
51+
52+
local entities = {
53+
amp = '&',
54+
lt = '<',
55+
gt = '>',
56+
apos = '\'',
57+
quot = '"',
58+
}
59+
60+
local converted = text
61+
:gsub('.*<ChatMon>', 'return {')
62+
:gsub('(=".-")', '%1,')
63+
:gsub('<settings', 'settings = {')
64+
:gsub('<%!%-%-.-%-%->%s*', '')
65+
:gsub('<trigger', '{')
66+
:gsub('</ChatMon>', '}')
67+
:gsub('/?>', '},')
68+
:gsub('&(%w+);', entities)
69+
70+
local chatmon_plugin_xml = loadstring(converted)()
71+
72+
local defaults = L{
73+
{ name='tell' },
74+
{ name='emote' },
75+
{ name='invite', sound='invitation' },
76+
{ name='examine' },
77+
{ name='talk', from=L{'say', 'shout', 'party', 'linkshell', 'linkshell2'}, match='<name>' },
78+
}
79+
80+
local triggers = L{}
81+
82+
for data in defaults:it() do
83+
local name = data.name:ucfirst()
84+
local comment = chatmon_plugin_xml.settings[name .. 'Sound']:lower() == 'none'
85+
triggers:append((comment and '-- ' or '') .. format_trigger(data.from, data.not_from, data.match, data.not_match, sounds[data.name]))
86+
end
87+
88+
local function parse_from(from)
89+
local matches = L{}
90+
91+
for match in string.gmatch((from or ''):lower(), '[^|/\\,%s]+') do
92+
matches:append(match)
93+
end
94+
95+
return matches
96+
end
97+
98+
for _, trigger in ipairs(chatmon_plugin_xml) do
99+
local sound = trigger.sound and (sounds[trigger.sound:lower()] or trigger.sound) or 'IncomingTalk.wav'
100+
triggers:append(format_trigger(parse_from(trigger.from), parse_from(trigger.not_from), trigger.match, trigger.not_match, sound))
101+
end
102+
103+
local trigger_text = 'return {\n' .. triggers:map(function(line) return ' ' .. line .. ',\n' end):concat() .. '}\n'
104+
105+
local global = assert(io.open(windower.addon_path .. '/data/triggers/global.lua', 'w'))
106+
global:write(trigger_text)
107+
global:close()
108+
109+
local settings = {}
110+
local truthy_set = S{'true', 't', 'yes', 'y', 'on', 'o'}
111+
settings.DisableOnFocus = not truthy_set:contains(string.lower(chatmon_plugin_xml.settings.DisableOnFocus))
112+
settings.SoundInterval = tonumber(chatmon_plugin_xml.settings.SoundInterval)
113+
114+
-- coroutine.schedule(function()
115+
-- windower.create_dir(windower.windower_path .. 'plugins\\deprecated')
116+
-- os.rename(windower.windower_path .. 'plugins\\ChatMon.xml', windower.windower_path .. 'plugins\\depercated\\ChatMon.xml')
117+
-- os.rename(windower.windower_path .. 'plugins\\ChatMon.dll', windower.windower_path .. 'plugins\\depercated\\ChatMon.dll')
118+
-- end, 0)
119+
120+
return settings

addons/chatmon/get_triggers.lua

100644100755
File mode changed.

0 commit comments

Comments
 (0)