diff --git a/.travis.yml b/.travis.yml index 1a9c128..60ac6b1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ install: script: - lua -lluacov tests/TestUtility.lua -v - lua -lluacov tests/TestSettings.lua -v + - lua -lluacov tests/TestSystemEventHandler.lua -v after_success: - luacov-coveralls diff --git a/API.lua b/API.lua index 1e1b4c5..cf15386 100644 --- a/API.lua +++ b/API.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/CHANGELOG.md b/CHANGELOG.md index f00df49..b2e6d3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,18 @@ This project uses [Semantic Versioning](http://semver.org/). +## [1.11.0] -- Unreleased +### Removed +- Removed replication of achievements and loot announcements between co-guilds. + +### Changed +- Updated the TOC for WoW 8.3.0. +- Refactored CHAT_MSG_SYSTEM handling to use an abstract factory and added + full unit testing for the polymorphic classes. + +### Fixed +- Updated debug message call stack parsing for 8.3. + ## [1.10.1] -- 2019-09-24 ### Updated - Updated the TOC for WoW 8.2.5. @@ -623,6 +635,7 @@ flapping roster announcements for characters in peer co-guilds. ## 0.9.00 -- 2010-11-01 Initial commit. +[1.11.0]: https://github.com/AIE-Guild/GreenWall/compare/v1.10.1...v1.11.0 [1.10.1]: https://github.com/AIE-Guild/GreenWall/compare/v1.10.0...v1.10.1 [1.10.0]: https://github.com/AIE-Guild/GreenWall/compare/v1.9.15...v1.10.0 [1.9.15]: https://github.com/AIE-Guild/GreenWall/compare/v1.9.14...v1.9.15 diff --git a/Channel.lua b/Channel.lua index 02f1262..6e9a6bc 100644 --- a/Channel.lua +++ b/Channel.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -262,7 +262,6 @@ Transmit Methods -- @param type The message type. -- Accepted values are: -- GW_MTYPE_CHAT --- GW_MTYPE_ACHIEVEMENT -- GW_MTYPE_BROADCAST -- GW_MTYPE_NOTICE -- GW_MTYPE_REQUEST @@ -298,10 +297,6 @@ function GwChannel:tl_send(type, message) local opcode if type == GW_MTYPE_CHAT then opcode = 'C' - elseif type == GW_MTYPE_ACHIEVEMENT then - opcode = 'A' - elseif type == GW_MTYPE_LOOT then - opcode = 'L' elseif type == GW_MTYPE_BROADCAST then opcode = 'B' elseif type == GW_MTYPE_NOTICE then @@ -471,10 +466,6 @@ function GwChannel:tl_receive(...) local type = GW_MTYPE_NONE if opcode == 'C' then type = GW_MTYPE_CHAT - elseif opcode == 'A' then - type = GW_MTYPE_ACHIEVEMENT - elseif opcode == 'L' then - type = GW_MTYPE_LOOT elseif opcode == 'B' then type = GW_MTYPE_BROADCAST elseif opcode == 'N' then @@ -486,7 +477,7 @@ function GwChannel:tl_receive(...) elseif opcode == 'E' then type = GW_MTYPE_EXTERNAL else - gw.Debug(GW_LOG_ERROR, 'unknown segment opcode: %s', opcode) + gw.Debug(GW_LOG_WARNING, 'unknown segment opcode: %s', opcode) end return sender, guild_id, type, message end diff --git a/Chat.lua b/Chat.lua index 8d7c2e1..07386b6 100644 --- a/Chat.lua +++ b/Chat.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -37,14 +37,6 @@ function gw.handlerGuildChat(type, guild_id, content, arglist) local sender = arglist[2] if type == GW_MTYPE_CHAT then gw.ReplicateMessage('GUILD', content[1], guild_id, arglist) - elseif type == GW_MTYPE_ACHIEVEMENT then - if gw.settings:get('achievements') then - gw.ReplicateMessage('GUILD_ACHIEVEMENT', content[1], guild_id, arglist) - end - elseif type == GW_MTYPE_LOOT then - if gw.settings:get('achievements') then - gw.ReplicateMessage('LOOT', content[1], guild_id, arglist) - end elseif type == GW_MTYPE_BROADCAST then local action, target, rank = unpack(content) if action == 'join' then @@ -95,8 +87,6 @@ end -- Accepted values: -- 'GUILD' -- 'OFFICER' --- 'GUILD_ACHIEVEMENT' --- 'LOOT' -- 'SYSTEM' -- @param message The message to replicate. -- @param guild_id (optional) Guild ID of the sender. diff --git a/Compat.lua b/Compat.lua index b7a6553..428ae38 100644 --- a/Compat.lua +++ b/Compat.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Config.lua b/Config.lua index 2742952..f81c46b 100644 --- a/Config.lua +++ b/Config.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Constants.lua b/Constants.lua index afa2d29..698e8e7 100644 --- a/Constants.lua +++ b/Constants.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -64,15 +64,13 @@ GW_CTYPE_ADDON = 2 -- GW_MTYPE_NONE = 0 GW_MTYPE_CHAT = 1 -GW_MTYPE_ACHIEVEMENT = 2 -GW_MTYPE_LOOT = 3 -GW_MTYPE_BROADCAST = 4 -GW_MTYPE_CONTROL = 5 -GW_MTYPE_REQUEST = 6 -GW_MTYPE_RESPONSE = 7 -GW_MTYPE_NOTICE = 8 -GW_MTYPE_ADDON = 9 -GW_MTYPE_EXTERNAL = 10 +GW_MTYPE_BROADCAST = 2 +GW_MTYPE_CONTROL = 3 +GW_MTYPE_REQUEST = 4 +GW_MTYPE_RESPONSE = 5 +GW_MTYPE_NOTICE = 6 +GW_MTYPE_ADDON = 7 +GW_MTYPE_EXTERNAL = 8 -- diff --git a/GUILD_QUICKSTART.md b/GUILD_QUICKSTART.md index c0abe6e..bf5895a 100644 --- a/GUILD_QUICKSTART.md +++ b/GUILD_QUICKSTART.md @@ -20,7 +20,7 @@ Definitions ----------- Bridging -> Replication of chat events within one guild into the guild, achievement, and officer chat of another guild. +> Replication of chat events within one guild into the guild and officer chat channels of another guild. Confederation > A large WoW guild that is partitioned into smaller guilds to comply with Blizzard's guild size limit. diff --git a/Globals.lua b/Globals.lua index a968be1..328ab1b 100644 --- a/Globals.lua +++ b/Globals.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -70,8 +70,6 @@ gw.usage = [[ -- Reload the configuration. reset -- Reset communications and reload the configuration. - achievements - -- Toggle display of confederation achievements. roster -- Toggle display of confederation online, offline, join, and leave messages. rank diff --git a/GreenWall.lua b/GreenWall.lua index 480d410..c696035 100644 --- a/GreenWall.lua +++ b/GreenWall.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -176,9 +176,7 @@ function GreenWall_OnLoad(self) self:RegisterEvent('CHAT_MSG_CHANNEL_LEAVE') self:RegisterEvent('CHAT_MSG_CHANNEL_NOTICE') self:RegisterEvent('CHAT_MSG_GUILD') - self:RegisterEvent('CHAT_MSG_LOOT') self:RegisterEvent('CHAT_MSG_OFFICER') - self:RegisterEvent('CHAT_MSG_GUILD_ACHIEVEMENT') self:RegisterEvent('CHAT_MSG_SYSTEM') self:RegisterEvent('GUILD_ROSTER_UPDATE') self:RegisterEvent('PLAYER_ENTERING_WORLD') @@ -297,18 +295,6 @@ function GreenWall_OnEvent(self, event, ...) local message, sender, language, _, _, flags, _, chanNum = select(1, ...) gw.Debug(GW_LOG_DEBUG, 'event=%s, sender=%s, message=%q', event, sender, message) - elseif event == 'CHAT_MSG_LOOT' then - - local message, sender, _, _, _, flags, _, chanNum = select(1, ...) - gw.Debug(GW_LOG_DEBUG, 'event=%s, sender=%s, message=%q', event, sender, message) - item = gw.GetItemString(message) - if item and gw.IsLegendary(item) then - if gw.iCmp(gw.GlobalName(sender), gw.player) then - newmsg = message:gsub('You receive', gw.player .. ' receives') -- Convert to third-person - gw.config.channel.guild:send(GW_MTYPE_LOOT, newmsg) - end - end - elseif event == 'CHAT_MSG_OFFICER' then -- Messages will be forwarded by the ChatEdit_ParseText hook @@ -322,14 +308,6 @@ function GreenWall_OnEvent(self, event, ...) gw.ReceiveLocal(gw.GlobalName(sender), payload) end - elseif event == 'CHAT_MSG_GUILD_ACHIEVEMENT' then - - local message, sender, _, _, _, flags, _, chanNum = select(1, ...) - gw.Debug(GW_LOG_DEBUG, 'event=%s, sender=%s, message=%q', event, sender, message) - if gw.iCmp(gw.GlobalName(sender), gw.player) then - gw.config.channel.guild:send(GW_MTYPE_ACHIEVEMENT, message) - end - elseif event == 'CHAT_MSG_CHANNEL_JOIN' then local _, player, _, _, _, _, _, number = select(1, ...) @@ -407,96 +385,9 @@ function GreenWall_OnEvent(self, event, ...) elseif event == 'CHAT_MSG_SYSTEM' then local message = select(1, ...) - gw.Debug(GW_LOG_DEBUG, 'event=%s, message=%q', event, message) - - local pat_online = ERR_FRIEND_ONLINE_SS:format('(.+)', '(.+)'):gsub('([%[%]])', '%%%1') - local pat_offline = ERR_FRIEND_OFFLINE_S:format('(.+)') - local pat_join = ERR_GUILD_JOIN_S:format('(.+)') - local pat_leave = ERR_GUILD_LEAVE_S:format('(.+)') - local pat_quit = ERR_GUILD_QUIT_S:format(gw.player) - local pat_removed = ERR_GUILD_REMOVE_SS:format('(.+)', '(.+)') - local pat_kick = ERR_GUILD_REMOVE_SS:format('(.+)', '(.+)') - local pat_promote = ERR_GUILD_PROMOTE_SSS:format('(.+)', '(.+)', '(.+)') - local pat_demote = ERR_GUILD_DEMOTE_SSS:format('(.+)', '(.+)', '(.+)') - - if message:match(pat_online) then - - local _, player = message:match(pat_online) - player = gw.GlobalName(player) - gw.config.comember_cache:hold(player) - gw.Debug(GW_LOG_DEBUG, 'comember_cache: updated %s', player) - - elseif message:match(pat_offline) then - - local player = message:match(pat_offline) - player = gw.GlobalName(player) - gw.config.comember_cache:hold(player) - gw.Debug(GW_LOG_DEBUG, 'comember_cache: updated %s', player) - - elseif message:match(pat_join) then - - local player = message:match(pat_join) - if gw.GlobalName(player) == gw.player then - -- We have joined the guild. - gw.Debug(GW_LOG_NOTICE, 'guild join detected.') - gw.config.channel.guild:send(GW_MTYPE_BROADCAST, 'join') - end - - elseif message:match(pat_leave) then - - local player = message:match(pat_leave) - if gw.GlobalName(player) == gw.player then - -- We have left the guild. - gw.Debug(GW_LOG_NOTICE, 'guild quit detected.') - gw.config.channel.guild:send(GW_MTYPE_BROADCAST, 'leave') - gw.config:reset() - end - - elseif message:match(pat_quit) then - - local player = message:match(pat_quit) - if gw.GlobalName(player) == gw.player then - -- We have left the guild. - gw.Debug(GW_LOG_NOTICE, 'guild quit detected.') - gw.config.channel.guild:send(GW_MTYPE_BROADCAST, 'leave') - gw.config:reset() - end - - elseif message:match(pat_removed) then - - local player = message:match(pat_removed) - if gw.GlobalName(player) == gw.player then - -- We have been kicked from the guild. - gw.Debug(GW_LOG_NOTICE, 'guild kick detected.') - gw.config.channel.guild:send(GW_MTYPE_BROADCAST, 'leave') - gw.config:reset() - end - - elseif message:match(pat_kick) then - - local target, player = message:match(pat_kick) - if gw.GlobalName(player) == gw.player then - gw.Debug(GW_LOG_NOTICE, 'you kicked %s', target) - gw.config.channel.guild:send(GW_MTYPE_BROADCAST, 'remove', target) - end - - elseif message:match(pat_promote) then - - local player, target, rank = message:match(pat_promote) - if gw.GlobalName(player) == gw.player then - gw.Debug(GW_LOG_NOTICE, 'you promoted %s to %s', target, rank) - gw.config.channel.guild:send(GW_MTYPE_BROADCAST, 'promote', target, rank) - end - - elseif message:match(pat_demote) then - - local player, target, rank = message:match(pat_demote) - if gw.GlobalName(player) == gw.player then - gw.Debug(GW_LOG_NOTICE, 'you demoted %s to %s', target, rank) - gw.config.channel.guild:send(GW_MTYPE_BROADCAST, 'demote', target, rank) - end - end + handler = GwSystemEventHandler:factory(gw.config, message) + handler:run() elseif event == 'GUILD_ROSTER_UPDATE' then diff --git a/GreenWall.toc b/GreenWall.toc index d25a0af..3fe3240 100644 --- a/GreenWall.toc +++ b/GreenWall.toc @@ -1,15 +1,15 @@ -## Interface: 80205 +## Interface: 80300 ## Title: GreenWall ## Notes: Common communication channel as a replacement for guild chat in guild confederations. ## Author: Mark Rogaski -## Version: 1.10.1 +## Version: 1.11.0-dev ## URL: https://github.com/AIE-Guild/GreenWall ## URL: https://www.curseforge.com/wow/addons/greenwall ## DefaultState: enabled ## SavedVariables: GreenWallAccount ## SavedVariablesPerCharacter: GreenWall,GreenWallMeta,GreenWallLog ## X-Category: Guild -## X-Date: 2019-09-24 +## X-Date: 2020-03-27 Lib\Load.xml Constants.lua @@ -21,6 +21,7 @@ Config.lua Compat.lua Chat.lua Channel.lua +SystemEventHandler.lua API.lua Interface.lua GreenWall.lua diff --git a/GreenWall.xml b/GreenWall.xml index a4d58db..a493d34 100644 --- a/GreenWall.xml +++ b/GreenWall.xml @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -98,22 +98,9 @@ C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd"> getglobal(self:GetName() .. "Text"):SetText("Show co-guild tags"); - - - - - - - - - - getglobal(self:GetName() .. "Text"):SetText("Show co-guild achievement announcements"); - - - diff --git a/HoldDown.lua b/HoldDown.lua index 5674854..0277814 100644 --- a/HoldDown.lua +++ b/HoldDown.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Interface.lua b/Interface.lua index 2f1f49d..7bed02d 100644 --- a/Interface.lua +++ b/Interface.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -40,7 +40,6 @@ function GreenWallInterfaceFrame_LoadOptions(self, mode) end getglobal(self:GetName() .. "OptionMode"):SetChecked(mode == GW_MODE_ACCOUNT) getglobal(self:GetName() .. "OptionTag"):SetChecked(gw.settings:get('tag', mode)) - getglobal(self:GetName() .. "OptionAchievements"):SetChecked(gw.settings:get('achievements', mode)) getglobal(self:GetName() .. "OptionRoster"):SetChecked(gw.settings:get('roster', mode)) getglobal(self:GetName() .. "OptionRank"):SetChecked(gw.settings:get('rank', mode)) getglobal(self:GetName() .. "OptionJoinDelay"):SetValue(gw.settings:get('joindelay', mode)) @@ -77,8 +76,6 @@ function GreenWallInterfaceFrame_SaveUpdates(self) local mode = getglobal(self:GetName() .. "OptionMode"):GetChecked() and GW_MODE_ACCOUNT or GW_MODE_CHARACTER gw.settings:set('mode', mode) gw.settings:set('tag', getglobal(self:GetName() .. "OptionTag"):GetChecked() and true or false, mode) - gw.settings:set('achievements', - getglobal(self:GetName() .. "OptionAchievements"):GetChecked() and true or false, mode) gw.settings:set('roster', getglobal(self:GetName() .. "OptionRoster"):GetChecked() and true or false, mode) gw.settings:set('rank', getglobal(self:GetName() .. "OptionRank"):GetChecked() and true or false, mode) gw.settings:set('joindelay', getglobal(self:GetName() .. "OptionJoinDelay"):GetValue(), mode) diff --git a/LICENSE b/LICENSE index 02a32b8..60c8f7d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Lib/Base64BCA.lua b/Lib/Base64BCA.lua index 77c98ca..69f6bde 100644 --- a/Lib/Base64BCA.lua +++ b/Lib/Base64BCA.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Lib/CRC16-CCITT.lua b/Lib/CRC16-CCITT.lua index f086cc3..39306a2 100644 --- a/Lib/CRC16-CCITT.lua +++ b/Lib/CRC16-CCITT.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Lib/SemanticVersion.lua b/Lib/SemanticVersion.lua index a4d0cc3..dcea33e 100644 --- a/Lib/SemanticVersion.lua +++ b/Lib/SemanticVersion.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 4bd932e..0173507 100644 --- a/README.md +++ b/README.md @@ -123,12 +123,6 @@ You will be able to set the following options. Default: on -- __achievements__ - _Show Co-Guild Achievement Announcements_ - - Show achievements from other co-guilds. - - Default: off - - __roster__ - _Show Co-Guild Roster Announcements_ Show guild join and leave messages from other co-guilds. @@ -187,12 +181,6 @@ To view the current configuration, you would enter one of the following. Default: on -- achievements [ on | off ] - - Show achievements from other co-guilds. - - Default: off - - roster [ on | off ] Show guild join and leave messages from other co-guilds. @@ -269,7 +257,7 @@ to establish communication with other co-guilds in a confederation. - Bridging - Replication of chat events within one guild into the guild, achievement, and officer chat of another guild. + Replication of chat events within one guild into the guild and officer chat of another guild. - Confederation @@ -400,7 +388,7 @@ issue tracker, please e-mail the details and I will add an issue record. The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Settings.lua b/Settings.lua index db80543..017e885 100644 --- a/Settings.lua +++ b/Settings.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -61,10 +61,6 @@ function GwSettings:new() value = true, desc = "co-guild tagging" }, - achievements = { - value = false, - desc = "co-guild achievement announcements" - }, roster = { value = true, desc = "co-guild roster announcements" diff --git a/SystemEventHandler.lua b/SystemEventHandler.lua new file mode 100644 index 0000000..2dc6a15 --- /dev/null +++ b/SystemEventHandler.lua @@ -0,0 +1,210 @@ +--[[----------------------------------------------------------------------- + +The MIT License (MIT) + +Copyright (c) 2010-2020 Mark Rogaski + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +--]]----------------------------------------------------------------------- + +local pat_online = ERR_FRIEND_ONLINE_SS:format('(.+)', '(.+)'):gsub('([%[%]])', '%%%1') +local pat_online_raw = "(.+) has come online." +local pat_offline = ERR_FRIEND_OFFLINE_S:format('(.+)') +local pat_join = ERR_GUILD_JOIN_S:format('(.+)') +local pat_leave = ERR_GUILD_LEAVE_S:format('(.+)') +local pat_quit = ERR_GUILD_QUIT_S:format('(.+)') +local pat_removed = ERR_GUILD_REMOVE_SS:format('(.+)', '(.+)') +local pat_kick = ERR_GUILD_REMOVE_SELF +local pat_promote = ERR_GUILD_PROMOTE_SSS:format('(.+)', '(.+)', '(.+)') +local pat_demote = ERR_GUILD_DEMOTE_SSS:format('(.+)', '(.+)', '(.+)') + +GwSystemEventHandler = { config = nil, player = nil, rank = nil } + +function GwSystemEventHandler:new(obj) + obj = obj or {} + setmetatable(obj, self) + self.__index = self + return obj +end + +function GwSystemEventHandler:run() +end + +GwOnlineSystemEventHandler = GwSystemEventHandler:new() + +function GwOnlineSystemEventHandler:run() + self.config.comember_cache:hold(self.player) + gw.Debug(GW_LOG_DEBUG, 'comember_cache: updated %s', self.player) +end + +GwOfflineSystemEventHandler = GwSystemEventHandler:new() + +function GwOfflineSystemEventHandler:run() + self.config.comember_cache:hold(self.player) + gw.Debug(GW_LOG_DEBUG, 'comember_cache: updated %s', self.player) +end + +GwJoinSystemEventHandler = GwSystemEventHandler:new() + +function GwJoinSystemEventHandler:run() + if self.player == gw.player then + gw.Debug(GW_LOG_NOTICE, 'guild join detected.') + self.config.channel.guild:send(GW_MTYPE_BROADCAST, 'join') + end +end + +GwLeaveSystemEventHandler = GwSystemEventHandler:new() + +function GwLeaveSystemEventHandler:run() + if self.player == gw.player then + gw.Debug(GW_LOG_NOTICE, 'guild quit detected.') + self.config.channel.guild:send(GW_MTYPE_BROADCAST, 'leave') + self.config:reset() + end +end + +GwQuitSystemEventHandler = GwSystemEventHandler:new() + +function GwQuitSystemEventHandler:run() + gw.Debug(GW_LOG_NOTICE, 'guild quit detected.') + self.config.channel.guild:send(GW_MTYPE_BROADCAST, 'leave') + self.config:reset() +end + +GwRemoveSystemEventHandler = GwSystemEventHandler:new() + +function GwRemoveSystemEventHandler:run() + if self.player == gw.player then + gw.Debug(GW_LOG_NOTICE, 'guild kick detected.') + self.config.channel.guild:send(GW_MTYPE_BROADCAST, 'remove') + self.config:reset() + end +end + +GwKickSystemEventHandler = GwSystemEventHandler:new() + +function GwKickSystemEventHandler:run() + gw.Debug(GW_LOG_NOTICE, 'guild kick detected.') + self.config.channel.guild:send(GW_MTYPE_BROADCAST, 'leave') + self.config:reset() +end + +GwPromoteSystemEventHandler = GwSystemEventHandler:new() + +function GwPromoteSystemEventHandler:run() + if self.player == gw.player then + gw.Debug(GW_LOG_NOTICE, 'you promoted %s to %s', self.target, self.rank) + self.config.channel.guild:send(GW_MTYPE_BROADCAST, 'promote', self.target, self.rank) + end +end + +GwDemoteSystemEventHandler = GwSystemEventHandler:new() + +function GwDemoteSystemEventHandler:run() + if self.player == gw.player then + gw.Debug(GW_LOG_NOTICE, 'you demoted %s to %s', self.target, self.rank) + self.config.channel.guild:send(GW_MTYPE_BROADCAST, 'demote', self.target, self.rank) + end +end + +function GwSystemEventHandler:factory(config, message) + -- Remove coloring + message = string.gsub(message, "|c%w%w%w%w%w%w%w%w([^|]*)|r", "%1") + + if message:match(pat_online) then + + local _, player = message:match(pat_online) + player = gw.GlobalName(player) + gw.Debug(GW_LOG_NOTICE, 'player online: %s', player) + return GwOnlineSystemEventHandler:new({ config = config, player = player }) + + elseif message:match(pat_online_raw) then + + local player = message:match(pat_online_raw) + player = gw.GlobalName(player) + gw.Debug(GW_LOG_NOTICE, 'player online: %s', player) + return GwOnlineSystemEventHandler:new({ config = config, player = player }) + + elseif message:match(pat_offline) then + + local player = message:match(pat_offline) + player = gw.GlobalName(player) + gw.Debug(GW_LOG_NOTICE, 'player offline: %s', player) + return GwOfflineSystemEventHandler:new({ config = config, player = player }) + + elseif message:match(pat_join) then + + local player = message:match(pat_join) + player = gw.GlobalName(player) + gw.Debug(GW_LOG_NOTICE, 'player join: %s', player) + return GwJoinSystemEventHandler:new({ config = config, player = player }) + + elseif message:match(pat_leave) then + + local player = message:match(pat_leave) + player = gw.GlobalName(player) + gw.Debug(GW_LOG_NOTICE, 'player leave: %s', player) + return GwLeaveSystemEventHandler:new({ config = config, player = player }) + + elseif message:match(pat_quit) then + + local player = UnitName('player') + player = gw.GlobalName(player) + gw.Debug(GW_LOG_NOTICE, 'player leave: %s', player) + return GwQuitSystemEventHandler:new({ config = config, player = player }) + + elseif message:match(pat_removed) then + + local player = message:match(pat_removed) + player = gw.GlobalName(player) + gw.Debug(GW_LOG_NOTICE, 'player removed: %s', player) + return GwRemoveSystemEventHandler:new({ config = config, player = player }) + + elseif message:match(pat_kick) then + + local player = UnitName('player') + player = gw.GlobalName(player) + gw.Debug(GW_LOG_NOTICE, 'player removed: %s', player) + return GwKickSystemEventHandler:new({ config = config, player = player }) + + elseif message:match(pat_promote) then + + local player, target, rank = message:match(pat_promote) + player = gw.GlobalName(player) + target = gw.GlobalName(target) + gw.Debug(GW_LOG_NOTICE, 'player promoted: %s, %s', target, rank) + return GwPromoteSystemEventHandler:new({ config = config, player = player, target = target, rank = rank }) + + elseif message:match(pat_demote) then + + local player, target, rank = message:match(pat_demote) + player = gw.GlobalName(player) + target = gw.GlobalName(target) + gw.Debug(GW_LOG_NOTICE, 'player demoted: %s, %s', target, rank) + return GwDemoteSystemEventHandler:new({ config = config, player = player, target = target, rank = rank }) + + else + + -- Unhandled system message + return GwSystemEventHandler:new({ config = config }) + + end + +end \ No newline at end of file diff --git a/Utility.lua b/Utility.lua index abdbb27..6ba31ac 100644 --- a/Utility.lua +++ b/Utility.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -60,7 +60,7 @@ function gw.Log(msg) if gw.settings and gw.settings:get('log') then local ts = date('%Y-%m-%d %H:%M:%S') tinsert(GreenWallLog, format('%s -- %s', ts, msg)) - while # GreenWallLog > gw.settings:get('logsize') do + while #GreenWallLog > gw.settings:get('logsize') do tremove(GreenWallLog, 1) end end @@ -70,7 +70,7 @@ end --- Write a message to the default chat frame. -- @param ... A list of the string and arguments for substitution using the syntax of string.format. function gw.Write(...) - local msg = string.format(unpack({...})) + local msg = string.format(unpack({ ... })) DEFAULT_CHAT_FRAME:AddMessage('|cff0bda51GreenWall:|r ' .. msg) gw.Log(msg) end @@ -79,7 +79,7 @@ end --- Write an error message to the default chat frame. -- @param ... A list of the string and arguments for substitution using the syntax of string.format. function gw.Error(...) - local msg = string.format(unpack({...})) + local msg = string.format(unpack({ ... })) DEFAULT_CHAT_FRAME:AddMessage('|cffabd473GreenWall:|r |cffff6000[ERROR] ' .. msg) gw.Log('[ERROR] ' .. msg) end @@ -92,15 +92,18 @@ end function gw.Debug(level, ...) local function get_caller() local s = debugstack(3, 1, 0) - local loc = strmatch(s, '([%a%._-]+:%d+): in function') - local fun = strmatch(s, 'in function \`([%a_-]+)\'') - return fun and loc .. '(' .. fun .. ')' or loc + local file, loc = strmatch(s, '%[string "(.+)"%]:(%d+): in function') + local f = strmatch(s, 'in function \`([%a_-]+)\'') + file = file == nil and "" or file + loc = loc == nil and "" or loc + f = f == nil and "?" or f + return format('%s:%s:%s', file, loc, f) end if gw.settings then if level <= gw.settings:get('debug') then - local msg = string.format(unpack({...})) - local trace = format('[debug/%d@%s] %s', level, get_caller(), msg) + local msg = string.format(unpack({ ... })) + local trace = format('debug/%d [%s] %s', level, get_caller(), msg) gw.Log(trace) if gw.settings:get('verbose') then DEFAULT_CHAT_FRAME:AddMessage(format('|cff009a7dGreenWall:|r |cff778899%s|r', trace)) @@ -131,6 +134,10 @@ end -- @param realm Name of the realm. -- @return A formatted cross-realm address. function gw.GlobalName(name, realm) + if name == nil then + return + end + -- Pass formatted names without modification. if name:match("[^-]+-[^-]+$") then return name @@ -234,7 +241,7 @@ end -- @return True is the player has joined any world channels, false otherwise. function gw.WorldChannelFound() gw.Debug(GW_LOG_DEBUG, 'scanning for world channels') - for i, v in pairs({GetChannelList()}) do + for i, v in pairs({ GetChannelList() }) do local name, header, _, _, _, _, category = GetChannelDisplayInfo(i) if not header then if category == 'CHANNEL_CATEGORY_WORLD' then diff --git a/run_tests.bat b/run_tests.bat new file mode 100644 index 0000000..0af3c6e --- /dev/null +++ b/run_tests.bat @@ -0,0 +1,4 @@ +set LUA_PATH="tests/?;tests/?.lua;;" +lua -lluacov tests/TestUtility.lua -v +lua -lluacov tests/TestSettings.lua -v +lua -lluacov tests/TestSystemEventHandler.lua -v diff --git a/tests/Loader.lua b/tests/Loader.lua index 7542366..d865dd0 100644 --- a/tests/Loader.lua +++ b/tests/Loader.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -33,6 +33,7 @@ require('Lib/SemanticVersion') require('Constants') require('Globals') require('Settings') +require('SystemEventHandler') require('Utility') require('HoldDown') require('Config') diff --git a/tests/MockAPI.lua b/tests/MockAPI.lua index 7983ffd..eaa7c48 100644 --- a/tests/MockAPI.lua +++ b/tests/MockAPI.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -44,6 +44,19 @@ while true do end f:close() +-- +-- Constants +-- +ERR_FRIEND_ONLINE_SS = "|Hplayer:%s|h[%s]|h has come online." +ERR_FRIEND_OFFLINE_S = "%s has gone offline." +ERR_GUILD_JOIN_S = "%s has joined the guild." +ERR_GUILD_LEAVE_S = "%s has left the guild." +ERR_GUILD_QUIT_S = "You are no longer a member of %s." +ERR_GUILD_REMOVE_SS = "%s has been kicked out of the guild by %s." +ERR_GUILD_REMOVE_SELF = "You have been kicked out of the guild." +ERR_GUILD_PROMOTE_SSS = "%s has promoted %s to %s." +ERR_GUILD_DEMOTE_SSS = "%s has demoted %s to %s." + function date(...) return os.date(...) end diff --git a/tests/TestSettings.lua b/tests/TestSettings.lua index fdad0ac..1c05edc 100644 --- a/tests/TestSettings.lua +++ b/tests/TestSettings.lua @@ -2,7 +2,7 @@ The MIT License (MIT) -Copyright (c) 2010-2019 Mark Rogaski +Copyright (c) 2010-2020 Mark Rogaski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -71,7 +71,6 @@ function TestSettingsCreate:test_initialize() lu.assertStrMatches(tab.created, '%d%d%d%d%-%d%d%-%d%d %d%d:%d%d:%d%d') lu.assertStrMatches(tab.updated, '%d%d%d%d%-%d%d%-%d%d %d%d:%d%d:%d%d') lu.assertEquals(tab.tag, true) - lu.assertEquals(tab.achievements, false) lu.assertEquals(tab.roster, true) lu.assertEquals(tab.rank, false) lu.assertEquals(tab.debug, GW_LOG_NONE) @@ -96,7 +95,6 @@ function TestSettingsLoad:setUp() GreenWall = { created = "2018-01-01 17:28:47", updated = "2018-01-01 01:04:46", - achievements = true, roster = false, } GreenWallAccount = { @@ -123,7 +121,6 @@ end function TestSettingsLoad:test_character() local settings = GwSettings:new() lu.assertEquals(GreenWall.tag, true) - lu.assertEquals(GreenWall.achievements, true) lu.assertEquals(GreenWall.roster, false) lu.assertEquals(GreenWall.rank, false) end @@ -149,14 +146,12 @@ function TestSettingsAccess:setUp() created = "2018-01-01 17:28:47", updated = "2018-01-01 01:04:46", tag = true, - achievements = true, logsize = 1024, } GreenWallAccount = { created = "2018-01-01 17:28:47", updated = "2018-01-01 01:04:46", tag = false, - achievements = false, logsize = 2048, } end @@ -167,22 +162,18 @@ function TestSettingsAccess:test_get() lu.assertEquals(settings:get('mode'), GW_MODE_ACCOUNT) lu.assertEquals(settings:get('tag'), false) - lu.assertEquals(settings:get('achievements'), false) lu.assertEquals(settings:get('logsize'), 2048) lu.assertEquals(settings:get('tag',GW_MODE_CHARACTER), true) - lu.assertEquals(settings:get('achievements', GW_MODE_CHARACTER), true) lu.assertEquals(settings:get('logsize', GW_MODE_CHARACTER), 1024) settings:set('mode', GW_MODE_CHARACTER) lu.assertEquals(settings:get('mode'), GW_MODE_CHARACTER) lu.assertEquals(settings:get('tag'), true) - lu.assertEquals(settings:get('achievements'), true) lu.assertEquals(settings:get('logsize'), 1024) lu.assertEquals(settings:get('tag', GW_MODE_ACCOUNT), false) - lu.assertEquals(settings:get('achievements', GW_MODE_ACCOUNT), false) lu.assertEquals(settings:get('logsize', GW_MODE_ACCOUNT), 2048) end diff --git a/tests/TestSystemEventHandler.lua b/tests/TestSystemEventHandler.lua new file mode 100644 index 0000000..f6c374c --- /dev/null +++ b/tests/TestSystemEventHandler.lua @@ -0,0 +1,331 @@ +--[[-------------------------------------------------------------------------- + +The MIT License (MIT) + +Copyright (c) 2010-2020 Mark Rogaski + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +--]]-------------------------------------------------------------------------- + +-- +-- Includes +-- + +lu = require('luaunit') +require('Loader') + +-- +-- Mocks +-- +local MockChan = {} +MockChan.__index = MockChan + +function MockChan:new() + local self = {} + setmetatable(self, MockChan) + self.input = {} + return self +end + +function MockChan:send(mtype, ...) + table.insert(self.input, { mtype, ... }) +end + +local MockCache = {} +MockCache.__index = MockCache + +function MockCache:new(output) + local self = {} + setmetatable(self, MockCache) + self.input = {} + self.output = output and true or false + return self +end + +function MockCache:hold(s) + table.insert(self.input, s) + return self.output +end + +local MockConfig = {} +MockConfig.__index = MockConfig + +function MockConfig:new(holddown) + local self = {} + setmetatable(self, MockConfig) + self.channel = { guild = MockChan:new() } + self.comember_cache = MockCache:new(holddown) + self.is_reset = false + return self +end + +function MockConfig:reset() + self.is_reset = true +end + + +-- +-- Test Cases +-- + +TestSystemEventHandler = {} + +function TestSystemEventHandler:test_online_init() + config = MockConfig:new() + message = "|Hplayer:Eggolas|h[Eggolas]|h has come online." + handler = GwSystemEventHandler:factory(config, message) + lu.assertEquals(getmetatable(handler), GwOnlineSystemEventHandler) + lu.assertEquals(handler.player, "Eggolas-EarthenRing") + lu.assertNil(handler.rank) + lu.assertEquals(handler.config, config) +end + +function TestSystemEventHandler:test_online_raw_init() + config = MockConfig:new() + message = "Eggolas has come |cff298F00online|r." + handler = GwSystemEventHandler:factory(config, message) + lu.assertEquals(getmetatable(handler), GwOnlineSystemEventHandler) + lu.assertEquals(handler.player, "Eggolas-EarthenRing") + lu.assertNil(handler.rank) +end + +function TestSystemEventHandler:test_online_run() + config = MockConfig:new() + message = "|Hplayer:Eggolas|h[Eggolas]|h has come online." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertEquals(config.comember_cache.input[1], "Eggolas-EarthenRing") +end + +function TestSystemEventHandler:test_online_run_cached() + config = MockConfig:new(true) + message = "|Hplayer:Eggolas|h[Eggolas]|h has come online." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertEquals(config.comember_cache.input[1], "Eggolas-EarthenRing") +end + +function TestSystemEventHandler:test_offline_init() + config = MockConfig:new() + message = "Eggolas has gone offline." + handler = GwSystemEventHandler:factory(config, message) + lu.assertEquals(getmetatable(handler), GwOfflineSystemEventHandler) + lu.assertEquals(handler.player, "Eggolas-EarthenRing") + lu.assertNil(handler.rank) +end + +function TestSystemEventHandler:test_offline_run() + config = MockConfig:new() + message = "Eggolas has gone offline." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertEquals(config.comember_cache.input[1], "Eggolas-EarthenRing") +end + +function TestSystemEventHandler:test_offline_run_cached() + config = MockConfig:new(true) + message = "Eggolas has gone offline." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertEquals(config.comember_cache.input[1], "Eggolas-EarthenRing") +end + +function TestSystemEventHandler:test_join_init() + config = MockConfig:new() + message = "Eggolas has joined the guild." + handler = GwSystemEventHandler:factory(config, message) + lu.assertEquals(getmetatable(handler), GwJoinSystemEventHandler) + lu.assertEquals(handler.player, "Eggolas-EarthenRing") + lu.assertNil(handler.rank) +end + +function TestSystemEventHandler:test_join_run() + config = MockConfig:new() + message = "Ralff has joined the guild." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertEquals(config.channel.guild.input[1], { GW_MTYPE_BROADCAST, "join" }) +end + +function TestSystemEventHandler:test_join_run_skip() + config = MockConfig:new() + message = "Eggolas has joined the guild." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertNil(config.channel.guild.input[1]) +end + +function TestSystemEventHandler:test_leave_init() + config = MockConfig:new() + message = "Eggolas has left the guild." + handler = GwSystemEventHandler:factory(config, message) + lu.assertEquals(getmetatable(handler), GwLeaveSystemEventHandler) + lu.assertEquals(handler.player, "Eggolas-EarthenRing") + lu.assertNil(handler.rank) +end + +function TestSystemEventHandler:test_leave_run() + config = MockConfig:new() + message = "Ralff has left the guild." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertEquals(config.channel.guild.input[1], { GW_MTYPE_BROADCAST, "leave" }) + lu.assertTrue(config.is_reset) +end + +function TestSystemEventHandler:test_leave_run_skip() + config = MockConfig:new() + message = "Eggolas has left the guild." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertNil(config.channel.guild.input[1]) + lu.assertFalse(config.is_reset) +end + +function TestSystemEventHandler:test_quit_init() + config = MockConfig:new() + message = "You are no longer a member of SparkleMotion." + handler = GwSystemEventHandler:factory(config, message) + lu.assertEquals(getmetatable(handler), GwQuitSystemEventHandler) + lu.assertEquals(handler.player, "Ralff-EarthenRing") + lu.assertNil(handler.rank) +end + +function TestSystemEventHandler:test_quit_run() + config = MockConfig:new() + message = "You are no longer a member of SparkleMotion." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertEquals(config.channel.guild.input[1], { GW_MTYPE_BROADCAST, "leave" }) + lu.assertTrue(config.is_reset) +end + +function TestSystemEventHandler:test_remove_init() + config = MockConfig:new() + message = "Eggolas has been kicked out of the guild by Ralff." + handler = GwSystemEventHandler:factory(config, message) + lu.assertEquals(getmetatable(handler), GwRemoveSystemEventHandler) + lu.assertEquals(handler.player, "Eggolas-EarthenRing") + lu.assertNil(handler.rank) +end + +function TestSystemEventHandler:test_remove_run() + config = MockConfig:new() + message = "Ralff has been kicked out of the guild by Eggolas." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertEquals(config.channel.guild.input[1], { GW_MTYPE_BROADCAST, "remove" }) + lu.assertTrue(config.is_reset) +end + +function TestSystemEventHandler:test_remove_run_skip() + config = MockConfig:new() + message = "Eggolas has been kicked out of the guild by Ralff." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertNil(config.channel.guild.input[1]) + lu.assertFalse(config.is_reset) +end + +function TestSystemEventHandler:test_kick_init() + config = MockConfig:new() + message = "You have been kicked out of the guild." + handler = GwSystemEventHandler:factory(config, message) + lu.assertEquals(getmetatable(handler), GwKickSystemEventHandler) + lu.assertEquals(handler.player, "Ralff-EarthenRing") + lu.assertNil(handler.rank) +end + +function TestSystemEventHandler:test_kick_run() + config = MockConfig:new() + message = "You have been kicked out of the guild." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertEquals(config.channel.guild.input[1], { GW_MTYPE_BROADCAST, "leave" }) + lu.assertTrue(config.is_reset) +end + +function TestSystemEventHandler:test_promote_init() + config = MockConfig:new() + message = "Ralff has promoted Eggolas to Cohort." + handler = GwSystemEventHandler:factory(config, message) + lu.assertEquals(getmetatable(handler), GwPromoteSystemEventHandler) + lu.assertEquals(handler.player, "Ralff-EarthenRing") + lu.assertEquals(handler.target, "Eggolas-EarthenRing") + lu.assertEquals(handler.rank, "Cohort") +end + +function TestSystemEventHandler:test_promote_run() + config = MockConfig:new() + message = "Ralff has promoted Eggolas to Cohort." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertEquals(config.channel.guild.input[1], { GW_MTYPE_BROADCAST, "promote", "Eggolas-EarthenRing", "Cohort" }) +end + +function TestSystemEventHandler:test_promote_run_skip() + config = MockConfig:new() + message = "Stigg has promoted Eggolas to Cohort." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertNil(config.channel.guild.input[1]) +end + +function TestSystemEventHandler:test_demote_init() + config = MockConfig:new() + message = "Ralff has demoted Eggolas to Pleb." + handler = GwSystemEventHandler:factory(config, message) + lu.assertEquals(getmetatable(handler), GwDemoteSystemEventHandler) + lu.assertEquals(handler.player, "Ralff-EarthenRing") + lu.assertEquals(handler.target, "Eggolas-EarthenRing") + lu.assertEquals(handler.rank, "Pleb") +end + +function TestSystemEventHandler:test_demote_run() + config = MockConfig:new() + message = "Ralff has demoted Eggolas to Pleb." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertEquals(config.channel.guild.input[1], { GW_MTYPE_BROADCAST, "demote", "Eggolas-EarthenRing", "Pleb" }) +end + +function TestSystemEventHandler:test_demote_run_skip() + config = MockConfig:new() + message = "Stigg has demoted Eggolas to Pleb." + handler = GwSystemEventHandler:factory(config, message) + handler:run() + lu.assertNil(config.channel.guild.input[1]) +end + +function TestSystemEventHandler:test_no_match() + config = MockConfig:new() + message = "Don't panic." + handler = GwSystemEventHandler:factory(config, message) + lu.assertEquals(getmetatable(handler), GwSystemEventHandler) + lu.assertNil(handler.player) + lu.assertNil(handler.rank) +end + + +-- +-- Run the tests +-- + +os.exit(lu.run()) diff --git a/tests/TestUtility.lua b/tests/TestUtility.lua index ab84aca..460704e 100644 --- a/tests/TestUtility.lua +++ b/tests/TestUtility.lua @@ -41,9 +41,24 @@ require('Loader') -- Test Cases -- -TestItemInfo = {} +TestUtility = {} -function TestItemInfo:test_GetItemString() +function TestUtility:test_iCmp() + lu.assertTrue(gw.iCmp("Foo", "FOO")) + lu.assertTrue(gw.iCmp("Foo", "Foo")) + lu.assertFalse(gw.iCmp("Foo", "FOOBAR")) +end + +function TestUtility:test_GlobalName() + lu.assertEquals(gw.GlobalName("Ralff", "EarthenRing"), "Ralff-EarthenRing") + lu.assertEquals(gw.GlobalName("Ralff", "Earthen Ring"), "Ralff-EarthenRing") + lu.assertEquals(gw.GlobalName("Ralff-EarthenRing"), "Ralff-EarthenRing") + lu.assertEquals(gw.GlobalName("Ralff-EarthenRing", "EarthenRing"), "Ralff-EarthenRing") + lu.assertEquals(gw.GlobalName("Ralff"), "Ralff-EarthenRing") + lu.assertNil(gw.GlobalName(nil)) +end + +function TestUtility:test_GetItemString() local single = 'Testing |Hitem:6948::::::::80::::|h in a string.' local multi = 'Testing |Hitem:6948::::::::80::::|h and |Hitem:4388:0:0:0:0:0:0:210677200:80:0:0:0:0|h in a string.' lu.assertEquals(gw.GetItemString(single), 'item:6948::::::::80::::')