Thread Tools Display Modes
01-25-18, 08:22 AM   #1
bamboozle
A Defias Bandit
Join Date: Jan 2018
Posts: 2
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
https://wow.curseforge.com/projects/...ojectID=254432

and edited the RosterInvite.lua to the following.
Code:
-- instantiate a new ace addon
local AddOn = LibStub("AceAddon-3.0"):NewAddon("RosterInvite", "AceConsole-3.0")

-- declare slash commands
SLASH_ROSTERINVITE1 = '/rinv'
SLASH_ROSTERINVITE2 = '/rosterinv'
SLASH_ROSTERINVITE3 = '/rosterinvite'
SLASH_ROSTERINVITE4 = '/rinvite'

-- 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")
    else
        -- 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)
        end
    end

    -- 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
            InviteUnit(name)
            AddOn:Print("Invited: " .. name .. " (" .. string.lower(note) .. ")")
        else
            for _, noteName in pairs(noteNames) do
                if string.lower(note) == string.lower(noteName) then
                    -- invite the player
                    InviteUnit(name)
                    AddOn:Print("Invited: " .. name .. " (" .. noteName .. ")")
                end
            end
        end
    end
    AddOn:Print("Done")
end

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

-- declare ace oninit function
function AddOn:OnInitialize()
    AddOn:Print("Loaded")
end
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
  Reply With Quote
01-25-18, 08:54 AM   #2
briskman3000
A Flamescale Wyrmkin
 
briskman3000's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2009
Posts: 108
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.
__________________
My Addons: Convert Ratings Honor Track
  Reply With Quote
01-25-18, 09:14 AM   #3
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
Wouldn't string.find/strfind() be easier?
  Reply With Quote
01-25-18, 05:21 PM   #4
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
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 https://addon.bool.no, 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].colorStr..name.."|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

Last edited by Kanegasi : 01-25-18 at 05:29 PM.
  Reply With Quote
01-25-18, 07:39 PM   #5
bamboozle
A Defias Bandit
Join Date: Jan 2018
Posts: 2
Thank you Kanegasi and also thanks for showing me addon.bool.no
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Guild Note Group Inviter

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off