Fix guild chat invites.

Scott Yeskie [05-19-14 - 23:33]
Fix guild chat invites.

Sending invites to "@Account" doesn't work so add a lookup function to scan the guild roster until the character name is found.
Filename
AutoInvite.lua
AutoInvite.txt
diff --git a/AutoInvite.lua b/AutoInvite.lua
index e4f85fc..8ac44fa 100644
--- a/AutoInvite.lua
+++ b/AutoInvite.lua
@@ -1,12 +1,6 @@
 --[[
   * AutoInvite
   * Author: Sasky
-  GetGuildId(luaindex index)
-  GetNumGuilds()
-  GetNumGuildMembers(integer guildId)
-  SetGuildMemberNote(integer guildId, luaindex memberIndex, string note)
-  GetGuildMemberInfo
-	playerStatus: 1 online, 4 offline
 ]]--

 local AutoInvite = {}
@@ -42,6 +36,11 @@ AutoInvite.callback = function(eventCode, messageType, from, message)
 	end

 	if string.lower(message) == AutoInvite.watch and from ~= nil and from ~= "" then
+		if (messageType >= CHAT_CHANNEL_GUILD_1 and messageType <= CHAT_CHANNEL_OFFICER_5) then
+			from = AutoInvite.guildLookup(messageType, from)
+			if from == "" then return end
+		end
+
 		from = from:gsub("%^.+", "")
 		d("Sending invite to " .. from)
 		GroupInvite(from)
@@ -51,6 +50,32 @@ AutoInvite.callback = function(eventCode, messageType, from, message)
 	--d("Checking message '" .. string.lower(message) .."' ?= '" .. AutoInvite.watch .."'")
 end

+AutoInvite.guildLookup = function(channel, acctName)
+	local guildId = 0
+	if channel == CHAT_CHANNEL_GUILD_1 or channel == CHAT_CHANNEL_OFFICER_1 then guildId = GetGuildId(1) end
+	if channel == CHAT_CHANNEL_GUILD_2 or channel == CHAT_CHANNEL_OFFICER_2 then guildId = GetGuildId(2) end
+	if channel == CHAT_CHANNEL_GUILD_3 or channel == CHAT_CHANNEL_OFFICER_3 then guildId = GetGuildId(3) end
+	if channel == CHAT_CHANNEL_GUILD_4 or channel == CHAT_CHANNEL_OFFICER_4 then guildId = GetGuildId(4) end
+	if channel == CHAT_CHANNEL_GUILD_5 or channel == CHAT_CHANNEL_OFFICER_5 then guildId = GetGuildId(5) end
+
+	if guildId == 0 then d("Error - couldn't invite on channel: " .. channel) end
+
+	local aName
+	for i=1,GetNumGuildMembers(guildId) do
+		aName = GetGuildMemberInfo(guildId,i)
+		if aName == acctName then
+			hasChar, charName, zone = GetGuildMemberCharacterInfo(guildId,i)
+			-- Might use zone check to NOT auto-invite people outside current zone if leader in Cyrodiil
+			if hasChar then
+				return charName:gsub("%^.+", "")
+			else
+				d("Could not find player name for " .. acctName .. ". Please manually invite.")
+				return ""
+			end
+		end
+	end
+end
+
 --Stop listening
 AutoInvite.disable = function()
 	AutoInvite.watch = ""
diff --git a/AutoInvite.txt b/AutoInvite.txt
index 179971a..9dab0d2 100644
--- a/AutoInvite.txt
+++ b/AutoInvite.txt
@@ -1,6 +1,6 @@
 ## APIVersion: 100003
 ## Title: AutoInvite
-## Version: 1.0
+## Version: 1.1
 ## Author: Sasky

 AutoInvite.lua