Skip to content

Commit

Permalink
Battlenet friends should be more reliably invited to the group when w…
Browse files Browse the repository at this point in the history
…hispered
  • Loading branch information
Numynum committed Dec 4, 2024
1 parent 5dceadb commit f45dce6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 62 deletions.
67 changes: 26 additions & 41 deletions Config.lua
Original file line number Diff line number Diff line change
@@ -1,81 +1,66 @@
-- upvalue the globals
local _G = getfenv(0)
local LibStub = _G.LibStub
local GetAddOnMetadata = _G.GetAddOnMetadata or C_AddOns.GetAddOnMetadata
local coroutine = _G.coroutine

local addonName = ...
local IOW = LibStub("AceAddon-3.0"):GetAddon(addonName);
if not IOW then return end

IOW.Config = IOW.Config or {}
local Config = IOW.Config
---@class (partial) InviteOnWhisper
local IOW = LibStub("AceAddon-3.0"):GetAddon(addonName)
if not IOW then return end

Config.version = GetAddOnMetadata(addonName, "Version") or ""
local Config = {}
IOW.Config = Config

local function getCounter(start, increment)
start = start or 1
increment = increment or 1
return coroutine.wrap(function()
local count = start
while true do
count = count + increment
coroutine.yield(count)
end
end)
end
Config.version = C_AddOns.GetAddOnMetadata(addonName, "Version") or ""
Config.name = "Invite On Whisper";

function Config:GetOptions()
local orderCount = getCounter()
local increment = CreateCounter()
local options = {
type = 'group',
get = function(info) return Config:GetConfig(info[#info]); end,
set = function(info, value) return Config:SetConfig(info[#info], value); end,
get = function(info) return self:GetConfig(info[#info]) end,
set = function(info, value) return self:SetConfig(info[#info], value) end,
args = {
version = {
order = orderCount(),
order = increment(),
type = "description",
name = "Version: " .. self.version
},
confirm = {
order = orderCount(),
order = increment(),
name = "Confirmation",
desc = "Asks for confirmation for group invites",
descStyle = 'inline',
width = "full",
type = "toggle",
},
triggerOutgoingGInv = {
order = orderCount(),
order = increment(),
name = "Trigger on outgoing whispers for Guild invites",
descStyle = 'inline',
width = "full",
type = "toggle",
},
triggerOutgoingInv = {
order = orderCount(),
order = increment(),
name = "Trigger on outgoing whispers for Group invites",
descStyle = 'inline',
width = "full",
type = "toggle",
},
keywordMatchMiddle = {
order = orderCount(),
order = increment(),
name = "Toggle Smart Match",
desc = "Smart Match will search your received whispers for an invite keyword. If any invite keyword is found in the whisper, it will trigger an invite. For example, the 'invite' keyword would then be triggered from \"Invite please?\"",
width = "full",
type = "toggle",
},
addGuildInviteTrigger = {
order = orderCount(),
order = increment(),
type = "input",
name = "Add Guild invite trigger phrase",
set = function(_, phrase)
IOW.DB.ginv[phrase:lower()] = true
end,
},
removeGuildInviteTrigger = {
order = orderCount(),
order = increment(),
type = "select",
style = "dropdown",
name = "Remove Guild invite trigger phrase",
Expand All @@ -88,21 +73,21 @@ function Config:GetOptions()
end
return tempTable
end,
get = function(_, _) return false end,
set = function(_, phrase, ...)
get = function() return false end,
set = function(_, phrase)
IOW.DB.ginv[phrase] = nil
end,
},
addGroupInviteTrigger = {
order = orderCount(),
order = increment(),
type = "input",
name = "Add Group invite trigger phrase",
set = function(_, phrase)
IOW.DB.inv[phrase:lower()] = true
end,
},
removeGroupInviteTrigger = {
order = orderCount(),
order = increment(),
type = "select",
style = "dropdown",
name = "Remove Group invite trigger phrase",
Expand All @@ -115,7 +100,7 @@ function Config:GetOptions()
end
return tempTable
end,
get = function(_, _) return false end,
get = function() return false end,
set = function(_, phrase, ...)
IOW.DB.inv[phrase] = nil
end,
Expand All @@ -128,19 +113,19 @@ end

function Config:Initialize()
self:RegisterOptions()
LibStub("AceConfigDialog-3.0"):AddToBlizOptions("Invite On Whisper", "Invite On Whisper")
LibStub("AceConfigDialog-3.0"):AddToBlizOptions(self.name, self.name)
end

function Config:RegisterOptions()
LibStub("AceConfig-3.0"):RegisterOptionsTable("Invite On Whisper", self:GetOptions())
LibStub("AceConfig-3.0"):RegisterOptionsTable(self.name, self:GetOptions())
end

function Config:OpenConfig()
Settings.OpenToCategory('Invite On Whisper')
Settings.OpenToCategory(self.name)
end

function Config:GetConfig(property)
return IOW.DB[property];
return IOW.DB[property]
end

function Config:SetConfig(property, value)
Expand Down
47 changes: 26 additions & 21 deletions InviteOnWhisper.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
-- upvalue the globals
local _G = getfenv(0)
local LibStub = _G.LibStub
local pairs = _G.pairs
local GuildInvite = _G.C_GuildInfo.Invite or _G.GuildInvite
local InviteUnit = _G.C_PartyInfo.InviteUnit or _G.InviteUnit
local C_BattleNet = _G.C_BattleNet
local StaticPopupDialogs = _G.StaticPopupDialogs
local StaticPopup_Show = _G.StaticPopup_Show

local addonName = ...

local IOW = LibStub('AceAddon-3.0'):NewAddon(addonName, 'AceConsole-3.0', 'AceHook-3.0', 'AceEvent-3.0');
if not IOW then return end
---@class InviteOnWhisper: AceAddon, AceConsole-3.0, AceHook-3.0, AceEvent-3.0
local IOW = LibStub('AceAddon-3.0'):NewAddon(addonName, 'AceConsole-3.0', 'AceHook-3.0', 'AceEvent-3.0')

function IOW:OnInitialize()
IOWDB = IOWDB or {}
Expand Down Expand Up @@ -39,7 +29,7 @@ function IOW:OnInitialize()
button1 = "Yes",
button2 = "No",
OnAccept = function(_, characterName)
GuildInvite(characterName)
C_GuildInfo.Invite(characterName)
end,
OnCancel = function() end,
timeout = 0,
Expand All @@ -52,8 +42,12 @@ function IOW:OnInitialize()
text = "Do you want to invite %s to your party/raid?",
button1 = "Yes",
button2 = "No",
OnAccept = function(_, characterName)
InviteUnit(characterName)
OnAccept = function(_, characterNameOrPresenceID)
if type(characterNameOrPresenceID) == "number" then
BNInviteFriend(characterNameOrPresenceID)
else
C_PartyInfo.InviteUnit(characterNameOrPresenceID)
end
end,
OnCancel = function() end,
timeout = 0,
Expand Down Expand Up @@ -93,21 +87,28 @@ end

function IOW:GetCharacterNameFromPresenceID(presenceID)
local accountInfo = C_BattleNet.GetAccountInfoByID(presenceID);
if(accountInfo.gameAccountInfo and accountInfo.gameAccountInfo.characterName and accountInfo.gameAccountInfo.realmName) then
if(accountInfo and accountInfo.gameAccountInfo and accountInfo.gameAccountInfo.characterName and accountInfo.gameAccountInfo.realmName) then
return accountInfo.gameAccountInfo.characterName .. '-' .. accountInfo.gameAccountInfo.realmName;
end

return nil;
end

---@param message string
---@param outgoing boolean
---@param presenceID number?
function IOW:HandleBnetWhisper(message, presenceID, outgoing)
local characterName = self:GetCharacterNameFromPresenceID(presenceID);
if(characterName) then
self:ProcessMessage(message, characterName, outgoing);
self:ProcessMessage(message, characterName, outgoing, presenceID);
end
end

function IOW:ProcessMessage(message, characterName, outgoing)
---@param message string
---@param characterName string
---@param outgoing boolean
---@param presenceID number?
function IOW:ProcessMessage(message, characterName, outgoing, presenceID)
message = message:lower():trim()
if self.DB.ginv[message] and (not outgoing or self.DB.triggerOutgoingGInv) then
local dialog = StaticPopup_Show("IOWguildinvPopup", characterName)
Expand All @@ -119,11 +120,15 @@ function IOW:ProcessMessage(message, characterName, outgoing)
if(self.DB.confirm) then
local dialog = StaticPopup_Show("IOWgroupinvPopup", characterName)
if (dialog) then
dialog.data = characterName
dialog.data = presenceID or characterName
end
else
self:Print("Trying to invite " .. characterName .. " to your party/raid")
InviteUnit(characterName)
if presenceID then
BNInviteFriend(presenceID)
else
C_PartyInfo.InviteUnit(characterName)
end
end
return
end
Expand All @@ -149,7 +154,7 @@ function IOW:ProcessMessage(message, characterName, outgoing)
local dialog = StaticPopup_Show("IOWgroupinvPopup", characterName)
if (dialog) then
found = true
dialog.data = characterName
dialog.data = presenceID or characterName
end
break
end
Expand Down

0 comments on commit f45dce6

Please sign in to comment.