Thread Tools Display Modes
08-22-24, 07:00 PM   #1
Walkerbo
A Frostmaul Preserver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 271
Remove player from guild on their right-click menu

Hi all

I have created a button and submenu on the right-click menu on a player.

I want to be able to invite/add a player to the guild I am in.

Inviting works perfectly but the uninvite does not work.

Here is my code;
Lua Code:
  1. local function nameString(targetName, targetRealm)
  2.        if targetRealm == nil then
  3.               targetNameString = targetName
  4.        else
  5.               targetNameString = (targetName .. "-" .. targetRealm)
  6.        end
  7.        return targetNameString
  8. end
  9.  
  10. local menuButton1 = Menu.ModifyMenu("MENU_UNIT_PLAYER", function(_, menuButton)
  11.        menuButton:CreateDivider()
  12.        submenu = menuButton:CreateButton("Guild Up")
  13.  
  14.        targetGuildName = GetGuildInfo("target")
  15.        targetGuid = UnitGUID("target")
  16.        playerGuildName = GetGuildInfo("player")
  17.        playerIsInGuild = IsInGuild()
  18.        playerCanInviteToGuild = CanGuildInvite()
  19.        playerCanRemoveFromGuild = CanGuildRemove()
  20.        targetName, targetRealm = UnitFullName("target")
  21.  
  22.        if playerIsInGuild and playerCanInviteToGuild then
  23.               if targetGuildName == nil then
  24.                      submenu:CreateButton(ColourList.greenText.."Invite Player To Guild", function(self)
  25.                             C_GuildInfo.Invite(nameString(targetName, targetRealm))
  26.                      end)
  27.        elseif playerCanRemoveFromGuild and playerGuildName == targetGuildName then
  28.                      submenu:CreateButton(ColourList.greenText.."Remove Player From Guild", function(self)
  29.                             print(UnitName("target") .. " is in a guild " .. targetGuildName, playerGuildName) -- debug --
  30.                             C_GuildInfo.RemoveFromGuild(targetGuid)-- debug --
  31.                      end)
  32.               end
  33.        end
It seems that removal from a guild is a secure action.

Is there a way to add a secure template to the button, or any other way to make this work?
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
08-24-24, 02:31 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,358
The slash command is registered under the token GUILD_UNINVITE. You can try to use a SecureActionButtonTemplate to run the following macrotext. Omitting the player name argument defaults to your current target.
Lua Code:
  1. local SecureActionButton=CreateFrame("Button",nil,"SecureActionButtonTempalte");
  2. SecureActionButton:SetAttribute("type","macro");
  3. SecureActionButton:SetAttribute("macrotext",SLASH_GUILD_UNINVITE1);

You can swap SLASH_GUILD_UNINVITE1 with SLASH_GUILD_INVITE1 to effectively toggle between kick and invite.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 08-24-24 at 02:34 AM.
  Reply With Quote
08-27-24, 05:36 PM   #3
Walkerbo
A Frostmaul Preserver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 271
Hi SDPhantom

Sorry for the delayed response.

I have added a button to the right click drop-down of a targeted player.
I have added a submenu buttonto that button.

The issue is that the submenu:CreateButton doesn't seem able to add a template.

I have tried adding a hidden button with a secure button template and then using the submenu button to perform a button click but that just seems to break everything.

I am just stumped at this point.
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
08-27-24, 10:03 PM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,358
Looking at the code, the functions in submenu are pulled from MenuUtilPrivate.Inserters and MenuUtilPrivate.Utilities. Note MenuUtilPrivate is a local table.

There appears to be a sister function to submenu:CreateButton() called submenu:CreateTemplate(). This might be something to look into.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 08-27-24 at 10:05 PM.
  Reply With Quote
09-03-24, 06:47 PM   #5
Walkerbo
A Frostmaul Preserver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 271
Hi SDPhantom

Sorry for taking so long to reply.

Thanks for the links, however, I still have not cracked this nut, no matter what I tried.

Any further help would be greatly appreciated.
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
09-03-24, 08:49 PM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,974
As far as I got, there doesn't seem to be any way to create a menu item based on a template (the use of template in the menu system is not referring to XML templates). While this may be a oversight, my guessing is probably not so as to avoid the unwary spreading taint into their lovely new menu system.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
09-05-24, 07:03 PM   #7
Walkerbo
A Frostmaul Preserver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 271
Hi Fizzlemizz

So there currently is no way to get this working, and as such I need to wait until Blizz implements a way to apply templates to the menu buttons.

Is there a way to raise such issues with Blizz?
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
09-06-24, 10:35 AM   #8
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,974
Feedback through the in-game system or or possibly the bug tracker.

I didn't get to the bottom of the rabbit hole so I might have missed something and as I said, it might be a deliberate omission that will never see the light of day.

Maybe your menu function could open a seperate frame with the required bits and buttons?
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
09-06-24, 11:21 PM   #9
Walkerbo
A Frostmaul Preserver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 271
Hi Fizzlemizz

I will submit a bug report, but I like your suggestion to use a button that activates when I click the menu button.

I have a very basic hidden secure button using code from SDPhantom;
Lua Code:
  1. local hiddenRemovePlayerFromGuildButton = CreateFrame("Button", nil, "SecureActionButtonTemplate")
  2. hiddenRemovePlayerFromGuildButton:SetAttribute("type", "macro")
  3. hiddenRemovePlayerFromGuildButton:SetAttribute("macrotext", "/kiss")

I trigger the button using;
Lua Code:
  1. hiddenRemovePlayerFromGuildButton:Click()

But I get an error;
Lua Code:
  1. 1x BuddyUp/BuddyUp.lua:119: attempt to index global 'hiddenRemovePlayerFromGuildButton' (a nil value)
  2. [string "@BuddyUp/BuddyUp.lua"]:119: in function <BuddyUp/BuddyUp.lua:116>
  3. [string "=(tail call)"]: ?
  4. [string "=[C]"]: in function `securecallfunction'
  5. [string "@Blizzard_Menu/Menu.lua"]:868: in function `Pick'
  6. [string "@Blizzard_Menu/MenuTemplates.lua"]:74: in function <Blizzard_Menu/MenuTemplates.lua:68>

What am I doing wrong here?
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
09-06-24, 11:32 PM   #10
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,974
The error says it all, the click cant "see" the hiddenRemovePlayerFromGuildButton because it is out of scope. First step woujld be to remove the local in front of hiddenRemovePlayerFromGuildButton (or maybe the function is declared after the click code??)

Beyond that, I couldn't tell without seeing the code.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
09-06-24, 11:50 PM   #11
Walkerbo
A Frostmaul Preserver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 271
Hi Fizzlemizz

Thanks for the speedy reply.

Yea, once again I know I should display all of my code it just feels like spamming;
Lua Code:
  1. -- ===========================         metrics, lists & variables          ===========================
  2.  
  3. local addonName = 'Buddy Up'
  4. local versionNumber = '1.0.100200'
  5.  
  6. local stringInvite, stringRemove, stringIgnore, stringUnignore = "Invite Player To Guild", "Remove Player From Guild", "Add Player To Ignore List", "Remove Player From Ignore List"
  7.  
  8. local localLanguage = GetLocale()
  9. if localLanguage == deDE then -- German
  10.        stringInvite = "Spieler zur Gilde einladen"
  11.        stringRemove = "Spieler aus der Gilde entfernen"
  12.        stringIgnore = "Spieler zur Ignorierliste hinzufügen"
  13.        stringUnignore = "Spieler aus der Ignorierliste entfernen"
  14. elseif localLanguage == esES then -- Spanish (Spain)
  15.        stringInvite = "Spieler zur Gilde einladen"
  16.        stringRemove = "Eliminar jugador del gremio"
  17.        stringIgnore = "Agregar jugador a la lista de ignorados"
  18.        stringUnignore = "Eliminar jugador de la lista de ignorados"
  19. elseif localLanguage == esMX then -- Spanish (Latin America)
  20.        stringInvite = "Spieler zur Gilde einladen"
  21.        stringRemove = "Eliminar jugador del gremio"
  22.        stringIgnore = "Agregar jugador a la lista de ignorados"
  23.        stringUnignore = "Eliminar jugador de la lista de ignorados"
  24. elseif localLanguage == frFR then -- French
  25.        stringInvite = "Inviter un joueur à la guilde"
  26.        stringRemove = "Supprimer un joueur de la guilde"
  27.        stringIgnore = "Ajouter un joueur à la liste des ignorés"
  28.        stringUnignore = "Supprimer le joueur de la liste des ignorés"
  29. elseif localLanguage == itIT then -- Italian
  30.        stringInvite = "Invita il giocatore alla gilda"
  31.        stringRemove = "Rimuovi giocatore dalla gilda"
  32.        stringIgnore = "Aggiungi giocatore all'elenco degli ignorati"
  33.        stringUnignore = "Rimuovi il giocatore dall'elenco ignorati"
  34. elseif localLanguage == koKR then -- Korean
  35.        stringInvite = "플레이어를 길드에 초대"
  36.        stringRemove = "길드에서 플레이어 제거"
  37.        stringIgnore = "무시 목록에 플레이어 추가"
  38.        stringUnignore = "무시 목록에서 플레이어 제거"
  39. elseif localLanguage == ptBR then -- Brazilian Portuguese
  40.        stringInvite = "Convidar jogador para guilda"
  41.        stringRemove = "Remover jogador da guilda"
  42.        stringIgnore = "Adicionar jogador à lista de ignorados"
  43.        stringUnignore = "Remover jogador da lista de ignorados"
  44. elseif localLanguage == ruRU then -- Russian
  45.        stringInvite = "Пригласить игрока в гильдию"
  46.        stringRemove = "Удалить игрока из гильдии"
  47.        stringIgnore = "Добавить игрока в список игнорируемых"
  48.        stringUnignore = "Удалить игрока из списка игнорируемых"
  49. elseif localLanguage == zhCN then -- Simplified Chinese
  50.        stringInvite = "邀请玩家加入公会"
  51.        stringRemove = "将玩家从公会中移除"
  52.        stringIgnore = "将玩家添加到忽略列表"
  53.        stringUnignore = "从忽略列表中删除玩家"
  54. elseif localLanguage == zhTW then -- Traditional Chinese
  55.        stringInvite = "邀請玩家加入公會"
  56.        stringRemove = "從公會刪除玩家"
  57.        stringIgnore = "將玩家加入忽略列表"
  58.        stringUnignore = "從忽略清單中刪除玩家"
  59. end
  60.  
  61. local ColourList = {
  62.        greenText = "|cff40ff40", -- rgb(64, 255, 64),
  63.        pinkText = "|cffff80ff", -- rgb( 255, 128, 255),
  64. }
  65.  
  66. -- ===========================         functions          ===========================
  67.  
  68. local function nameString(targetName, targetRealm)
  69.        if targetRealm == nil then
  70.               targetNameString = targetName
  71.        else
  72.               targetNameString = (targetName .. "-" .. targetRealm)
  73.        end
  74.        return targetNameString
  75. end
  76.  
  77. -- ===========================         context menu buttons          ===========================
  78.  
  79. local menuButton1 = Menu.ModifyMenu("MENU_UNIT_PLAYER", function(_, menuButton)
  80.        menuButton:CreateDivider()
  81.        submenu = menuButton:CreateButton("Guild Up")
  82.  
  83.        targetGuildName = GetGuildInfo("target")
  84.        targetGuid = UnitGUID("target")
  85.        playerGuildName = GetGuildInfo("player")
  86.        guildInvitesEnabled = GetAutoDeclineGuildInvites() -- debug --
  87.        playerIsInGuild = IsInGuild()
  88.        playerCanInviteToGuild = CanGuildInvite()
  89.        playerCanRemoveFromGuild = CanGuildRemove()
  90.        targetName, targetRealm = UnitFullName("target")
  91.  
  92.        if playerIsInGuild and playerCanInviteToGuild then
  93.               if targetGuildName == nil then
  94.                      submenu:CreateButton(ColourList.greenText .. stringInvite, function(self)
  95.                             C_GuildInfo.Invite(nameString(targetName, targetRealm))
  96.                      end)
  97.        elseif playerCanRemoveFromGuild and playerGuildName == targetGuildName then
  98.                      submenu:CreateButton(ColourList.greenText .. stringRemove, function(self)
  99.                             print(UnitName("target") .. " is in a guild " .. targetGuildName, playerGuildName) -- debug --
  100. --                          C_GuildInfo.RemoveFromGuild(targetGuid)-- debug --
  101.                             hiddenRemovePlayerFromGuildButton:Click() -- debug --
  102.                      end)
  103.               end
  104.        end
  105.  
  106.        if C_FriendList.IsIgnored("target") then
  107.               submenu:CreateButton(ColourList.pinkText .. stringUnignore, function(self)
  108.                      C_FriendList.AddOrDelIgnore(nameString(targetName, targetRealm))
  109.               end)
  110.        else
  111.               submenu:CreateButton(ColourList.pinkText .. stringIgnore, function(self)
  112.                      C_FriendList.AddOrDelIgnore(nameString(targetName, targetRealm))
  113.               end)
  114.        end
  115. end)
  116.  
  117. -- ===========================         button          ===========================
  118.  
  119. hiddenRemovePlayerFromGuildButton = CreateFrame("Button", "hiddenRemovePlayerFromGuildButton", UIParent, "SecureActionButtonTemplate")
  120. hiddenRemovePlayerFromGuildButton:SetAttribute("type", "macro")
  121. hiddenRemovePlayerFromGuildButton:SetAttribute("macrotext", "/kiss")
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
09-07-24, 09:30 AM   #12
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,974
You're declaring hiddenRemovePlayerFromGuildButton after the menu function so as a local
Code:
local hiddenRemovePlayerFromGuildButton = CreateFrame("Button", "hiddenRemovePlayerFromGuildButton", UIParent, "SecureActionButtonTemplate")
The menu function wouldn't be able to "see" it.

Move the button code above the menu:
Code:
 
local hiddenRemovePlayerFromGuildButton = CreateFrame("Button", "hiddenRemovePlayerFromGuildButton", UIParent, "SecureActionButtonTemplate")
hiddenRemovePlayerFromGuildButton:SetAttribute("type", "macro")
hiddenRemovePlayerFromGuildButton:SetAttribute("macrotext", "/kiss")

local menuButton1 = Menu.ModifyMenu("MENU_UNIT_PLAYER", function(_, menuButton)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-07-24 at 09:32 AM.
  Reply With Quote
09-07-24, 09:50 AM   #13
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,974
Instead of hiddenRemovePlayerFromGuildButton, have you tried something like:
Lua Code:
  1. local function RemovePlayerFromGuild(playername, playerguid)
  2.     if playername and playerguid then
  3.         local data = { name = playername, guid = playerguid, };
  4.         StaticPopup_Show("REMOVE_GUILDMEMBER", nil, nil, data);
  5.     end
  6. end

and your menu function to remove from guild would call:

Lua Code:
  1. RemovePlayerFromGuild(targetName, targetGuid)

I don't have a guild member to remove so just a thought


... the RemovePlayerFromGuild code would still be above
Code:
local menuButton1 = Menu.ModifyMenu("MENU_UNIT_PLAYER", function(_, menuButton)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-07-24 at 09:52 AM.
  Reply With Quote
09-07-24, 07:49 PM   #14
Walkerbo
A Frostmaul Preserver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 271
Hi Fizzlemizz

Thanks for your explanation and code, it makes sense that the button should be placed above the code calling it.

However, moving the button did not result in the remove from guild function firing.

Your second code block does open the remove from guild button frame which is perfect, however when I click the remove button I get the "blocked from action only available to the Bizzard UI" frame giving me the option to disable or ignore frame.
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
09-07-24, 07:50 PM   #15
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,974
That's what I was afraid of but had no way of testing.

You wouldn't be able to button:Click() to remove a player from the guild. The user would have to click the button with the mouse as with the popup.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 09-07-24 at 07:53 PM.
  Reply With Quote
09-07-24, 09:31 PM   #16
Walkerbo
A Frostmaul Preserver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 271
Hi Fizzlemizz

Yes, when the confirmation to remove button frame shows I do click the remove button with a physical mouse click, that's why it is strange that the click brings up the disable/ignore frame.
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
09-08-24, 01:43 AM   #17
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,974
Originally Posted by Walkerbo View Post
it is strange that the click brings up the disable/ignore frame.
Does the error say the function is only available from the Blizzard UI? That would indicate it's not something we can use even in secure code.

I remember when they first nobbled guild kick it required a hardware event. Maybe it's been completely protected since then?
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
09-08-24, 06:33 PM   #18
Walkerbo
A Frostmaul Preserver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 271
Hi Fizzlemizz

The menu button leads to the confirm gkick frame;


Clicking yes takes me to the disable/ignore frame;
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote
09-08-24, 07:14 PM   #19
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,358
This is what taint does. In the case of calling :click(), your addon is directly executing code that eventually tries to call a protected function. When otherwise secure code accesses a value you set, it inherits its taint and is blocked from calling future protected functions along with spreading your addon's taint to anything it writes to.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 09-08-24 at 07:16 PM.
  Reply With Quote
09-09-24, 06:41 PM   #20
Walkerbo
A Frostmaul Preserver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 271
Hi SDPhantom and Fizzlemizz

So this may not ever work unless Blizz steps in, damn.
I have submitted a suggestion with the faint hope that they look at this scenario and create a secure way to achieve my goal.
Yeah, I won't hold my breath.

Thanks to you both for your help and explanations.

Cheers
__________________
"As someone once told me, frames are just special types of tables, and tables are special types of pointers."
Fizzlemizz
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Remove player from guild on their right-click menu


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