Split disable and stop listening. Add restart support

Sasky [06-12-14 - 05:47]
Split disable and stop listening. Add restart support
Make cyrodiil check look at settings
Filename
AutoInvite.lua
diff --git a/AutoInvite.lua b/AutoInvite.lua
index 25ecd46..88bac28 100644
--- a/AutoInvite.lua
+++ b/AutoInvite.lua
@@ -43,12 +43,14 @@ AutoInvite.guildLookup = function(channel, acctName)

             charName = charName:gsub("%^.+", "")

-            d("In Cyrodiil? " .. b(AutoInvite.isCyrodiil()) .. " / Zone: " .. zone)
-
-            if AutoInvite.isCyrodiil() and zone ~= "Cyrodiil" then
-                d("Player " .. charName .. " is not in Cyrodiil but in " .. zone)
-                d("Blocking invite to prevent crashes.")
-                return ""
+            if AutoInvite.cfg.cyrCheck then
+                d("In Cyrodiil? " .. b(AutoInvite.isCyrodiil()) .. " / Zone: " .. zone)
+
+                if AutoInvite.isCyrodiil() and zone ~= "Cyrodiil" then
+                    d("Player " .. charName .. " is not in Cyrodiil but in " .. zone)
+                    d("Blocking invite to prevent crashes.")
+                    return ""
+                end
             end

             return charName
@@ -63,10 +65,11 @@ AutoInvite.callback = function(_, messageType, from, message)
 	if not AutoInvite.enabled or not AutoInvite.listening then
 		return
 	end
-
+
+    --TODO: Switch to queue-based with timeouts so don't send out too many invites
 	if GetGroupSize() >= AutoInvite.cfg.maxSize then
 		d("Group full. Disabling AutoInvite")
-		AutoInvite.disable()
+        AutoInvite.stopListening()
 	end

 	if string.lower(message) == AutoInvite.cfg.watchStr and from ~= nil and from ~= "" then
@@ -86,17 +89,26 @@ AutoInvite.callback = function(_, messageType, from, message)
 	--d("Checking message '" .. string.lower(message) .."' ?= '" .. AutoInvite.cfg.watchStr .."'")
 end

+AutoInvite.playerLeave = function()
+    if AutoInvite.enabled and AutoInvite.cfg.restart and GetGroupSize() < AutoInvite.cfg.maxSize then
+        AutoInvite.startListening()
+    end
+end
+
 ------------------------------------------------
 --- Main interface
 ------------------------------------------------
 AutoInvite.disable = function()
-	AutoInvite.cfg.watchStr = ""
-	EVENT_MANAGER:UnregisterForEvent(AutoInvite.AddonId, EVENT_CHAT_MESSAGE_CHANNEL)
 	AutoInvite.enabled = false
+    AutoInvite.stopListening()
+end
+
+AutoInvite.stopListening = function()
+    EVENT_MANAGER:UnregisterForEvent(AutoInvite.AddonId, EVENT_CHAT_MESSAGE_CHANNEL)
     AutoInvite.listening = false
 end

-AutoInvite.enable = function()
+AutoInvite.startListening = function()
     AutoInvite.enabled = true
 	if not AutoInvite.listening and GetGroupSize() < AutoInvite.cfg.maxSize then
 		--Add handler
@@ -130,7 +142,7 @@ SLASH_COMMANDS["/ai"] = function(str)
         return
     end
     AutoInvite.cfg.watchStr = string.lower(str)
-    AutoInvite.enable()
+    AutoInvite.startListening()
 end