WoWInterface (
-   Lua/XML Help (
-   -   Guild Note Group Inviter (

bamboozle 01-25-18 08:22 AM

Guild Note Group Inviter
I know nothing about lua and was wondering if someone can help me fix some issue I'm having.

So the addon is supposed to invite people that match the phrase in the command to their guild note
E.I... '/rinv weekday' will invite anyone with weekday in their guild note.

So first off I took this addon

and edited the RosterInvite.lua to the following.

-- instantiate a new ace addon
local AddOn = LibStub("AceAddon-3.0"):NewAddon("RosterInvite", "AceConsole-3.0")

-- declare slash commands
SLASH_ROSTERINVITE2 = '/rosterinv'
SLASH_ROSTERINVITE3 = '/rosterinvite'

-- declare handler for slash commands
local function Handler(msg, editbox)
    -- check for arguments
    local inviteAll = false
    --local rankName = msg
    local noteNames = {}
    if msg == "" then
        -- no arguments mean we should invite everyone
        inviteAll = true
        AddOn:Print("Inviting all guild members")
        -- an argument means we should invite all players with that rank
        inviteAll = false
        local notes = string.lower(msg)
        AddOn:Print("Inviting guild members with notes: " .. notes)
        for note in string.gmatch(notes, "[^ ]+") do
            table.insert(noteNames, note)

    -- invite players
    numTotalMembers, numOnlineMaxLevelMembers, numOnlineMembers = GetNumGuildMembers()
    for i=1,numOnlineMembers,1 do
        -- get player info
        name, rank, rankIndex, level, class, zone, note,
            officernote, online, status, classFileName,
            achievementPoints, achievementRank, isMobile,
            isSoREligible, standingID = GetGuildRosterInfo(i);
        -- check player info
        if inviteAll then
            -- invite the player
            AddOn:Print("Invited: " .. name .. " (" .. string.lower(note) .. ")")
            for _, noteName in pairs(noteNames) do
                if string.lower(note) == string.lower(noteName) then
                    -- invite the player
                    AddOn:Print("Invited: " .. name .. " (" .. noteName .. ")")

-- register slash command handler
SlashCmdList["ROSTERINVITE"] = Handler;

-- declare ace oninit function
function AddOn:OnInitialize()

Now this works, however, it will not invite people if they have more stuff in their note. So normally I would have someone note be "Weekday Raider 950 Feral" or "Weekend Raider 955 Prot pally". I would like to keep that but with the quick edit I made to the addon above, it doesn't work if I do keep that extra stuff. another issue, that is minor, is it being case sensitive, the addon will not work with capitals.

Once again any help will be great!

~ Cheers Bamboozle

briskman3000 01-25-18 08:54 AM

So from the way you are saying it functions you need to make two changes.

1. You need to pattern match the extra stuff out of the variable that is created when looking at guild notes. For example, below is how I grab multiple inputs from the slash command. It puts the first word in "command", and then the rest into "rest". You can most likely use something similar when scanning guild notes. So if you have them put "weekday" or "weekend" as always the first word in their guild note, you can probably work from that.

Lua Code:
  1. local command, rest = msg:match("^(%S*)%s*(.-)$");

2. After grabbing the first word from their note and storing it in its own variable, run a string.lower() on the variable and it will remove the capitals and make it work.

Ammako 01-25-18 09:14 AM

Wouldn't string.find/strfind() be easier?

Kanegasi 01-25-18 05:21 PM

I have similar code for both slash command argument matching and guild member iteration, so I threw together something that does what you want, case insensitive. You can invite anyone matching one or more arguments, so if you have people organized as "member", "trial", "weekday", "weekend", and so on, you can do /gnoteinv weekend member and it'll invite everyone with "weekend" or "member" in their notes. If you want to invite everyone, use /gnoteinv all. Nothing happens if there's no arguments and the code will tell you if no one matched your arguments as well. I even added some flair with class colored names.

You can change the slash command in the top line.

Go to, paste the code below into the big box, name this whatever you want in the top box, then download and install like any other addon. You can drop the other addon altogether or reinstall it to default for its original rank invite function.

As a final note, the way this is implemented, you must have the notes spaced, which I assumed isn't an issue. "Weekend raider 939" will match weekend, but "Weekendraider939" will not.

Lua Code:
  1. SLASH_GUILDNOTEINVITE1="/gnoteinv" -- change this to whatever you like
  2. SlashCmdList["GUILDNOTEINVITE"]=function(input)
  3.     if input=="all" then
  4.         print("Inviting EVERYONE!")
  5.     elseif input~="" then
  6.         print("Inviting guild members matching: "..input)
  7.     elseif input=="" then
  8.         return
  9.     end
  10.     local indexargs,keyargs,sentall,sent={strsplit(" ",input)},{}
  11.     for k,v in next,indexargs do
  12.         keyargs[strlower(v)]=true
  13.     end
  14.     for i=1,(GetNumGuildMembers()) do
  15.         local name,_,_,_,_,_,note,_,online,_,class=GetGuildRosterInfo(i)
  16.         if online then
  17.             if input=="all" then
  18.                 InviteUnit(name)
  19.                 sentall=true
  20.             else
  21.                 local noteparts={strsplit(" ",note)}
  22.                 for k,v in next,noteparts do
  23.                     if keyargs[strlower(v)] then
  24.                         InviteUnit(name)
  25.                         sent=true
  26.                         print("Invited |c"..RAID_CLASS_COLORS[class]"|r"..": "..v)
  27.                     end
  28.                 end
  29.             end
  30.         end
  31.     end
  32.     print((sent or sentall) and "Invites sent!" or "No members matched arguments!")
  33. end

bamboozle 01-25-18 07:39 PM

Thank you Kanegasi and also thanks for showing me

All times are GMT -6. The time now is 12:11 AM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI