I thought this would be a lot simpler to implement, but then I was reminded about cross-realm and all the issues that brings. I wrote something up that might work:
lua Code:
-- Add SHARPARAM_GROUP_WHISPER to SavedVariables to persist the settings
SHARPARAM_GROUP_WHISPER = SHARPARAM_GROUP_WHISPER or {}
local opt = SHARPARAM_GROUP_WHISPER
opt.enabled = true
op*****ssage = op*****ssage or "Welcome to the group!"
local members = {}
local PARTY_UNITS = {
"party1",
"party2",
"party3",
"party4",
"party5"
}
-- Helper function to get a list of group members
local function getGroupMembers()
local result = {}
if IsInRaid() then
for i = 1, GetNumGroupMembers() do
local name = GetRaidRosterInfo(i)
if not name:match("%w+-%w+") then
-- Try to get realm from UnitName func
local _, realm = UnitName(name)
-- Fall back to using player realm
if not realm then realm = GetRealmName() end
name = ("%s-%s"):format(name, realm)
end
result[#result + 1] = name
end
else
for _, unit in pairs(PARTY_UNITS) do
local name, realm = UnitName(unit)
if not realm then realm = GetRealmName() end
result[#result + 1] = ("%s-%s"):format(name, realm)
end
end
return result
end
-- Loop through members and message anyone new to the group
local function updateMembers()
if not opt.enabled or not IsInGroup() or not UnitIsGroupLeader("player") then
wipe(members)
return
end
for _, v in pairs(getGroupMembers()) do
-- New member? Great! Let's message them
if not members[name] then
sendMessage(name)
-- Add them to list so they don't get messaged again
members[name] = true
end
end
end
-- Gets the full player name string (name-realm) of the current player
local function getFullPlayerName()
local name, realm = UnitName("player")
if not realm then realm = GetRealmName() end
return ("%s-%s"):format(name, realm)
end
local function sendMessage(name, realm) -- realm param currently unused
realm = realm or GetRealmName()
if not name:match("%w+-%w+") then
name = ("%s-%s"):format(name:match("%w+"), realm)
end
if name == getFullPlayerName() then return end
SendChatMessage(op*****ssage, "WHISPER", nil, name)
end
local frame = CreateFrame("Frame")
frame:SetScript("OnEvent", function(self, event, ...)
updateMembers()
end)
frame:RegisterEvent("GROUP_JOINED")
frame:RegisterEvent("GROUP_ROSTER_UPDATE")
frame:RegisterEvent("INSTANCE_GROUP_SIZE_CHANGED")
frame:RegisterEvent("PARTY_MEMBERS_CHANGED")
frame:RegisterEvent("RAID_ROSTER_UPDATE")
SLASH_SHARPARAMGROUPWHISPER1 = "/sharpgw"
SlashCmdList["SHARPARAMGROUPWHISPER"] = function(e, msg)
local cmd, arg = msg:match("(%w)%w*(.*)")
if cmd == "t" then -- toggle
opt.enabled = not opt.enabled
print("Group whisper is now " .. (opt.enabled and "enabled" or "disabled"))
elseif cmd == "m" then -- set message
-- dirty workaround to skip the first space
op*****ssage = arg:gsub("^ ", "")
print("Update group whisper message!")
end
end
PLEASE NOTE: I am not sure if this code will work with player names using unicode characters.