Skip to content

Commit

Permalink
add a chat command to show other players discovered adherents
Browse files Browse the repository at this point in the history
add a chat command to greet other player adherents
implement validation to blacklist and whitelist inputs
use the wow constant for the faction check rather than a hardcoded string
  • Loading branch information
Road-block committed Mar 3, 2022
1 parent 201f21a commit 047bd24
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 57 deletions.
2 changes: 1 addition & 1 deletion Adherent-BCC.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Author: Roadblock
## Title: Adherent
## Notes: Adherent lets you define rules for auto accepting follow, group join and group invite requests.
## Version: 1.1.0
## Version: 1.1.1
## X-Alpha:
## X-Website: https://github.com/Road-block/Adherent/releases/latest
## OptionalDeps: Ace3
Expand Down
2 changes: 1 addition & 1 deletion Adherent.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Author: Roadblock
## Title: Adherent
## Notes: Adherent lets you define rules for auto accepting follow, group join and group invite requests.
## Version: 1.1.0
## Version: 1.1.1
## X-Alpha:
## X-Website: https://github.com/Road-block/Adherent/releases/latest
## OptionalDeps: Ace3
Expand Down
9 changes: 9 additions & 0 deletions Locales/enUS.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ if not L then return end
L["[Enabled]"] = true
L["Discovered <%s>"] = true
L["Removing <%s> from known"] = true
L["Known"] = true
L["Print discovered Adherents.\nUse a partial name to limit results"] = true
L["Greet"] = true
L["Send a backchannel greeting to a player to discover if they have an Adherent"] = true
L["Not a valid player name: %s"] = true
L["Length"] = true
L["Spaces"] = true
L["Numbers"] = true
L["Double Apostrophes"] = true
L["went AFK"] = true
L["returned from AFK"] = true
L["%s %s at %s"] = true
Expand Down
164 changes: 109 additions & 55 deletions core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,33 @@ local cmd = {
adherent:showOptions()
end,
order = 2,
},
known = {
type = "input",
name = L["Known"],
desc = L["Print discovered Adherents.\nUse a partial name to limit results"],
get = function() end,
set = function(info, val)
local filter = val and #(val:gsub("%s",""))>0 and val or ".+"
for k,v in pairs(adherent.db.profile.adherents) do
if k:find(filter) then
adherent:debugPrint(format("%s v%s",k,v))
end
end
end,
order = 3,
},
greet = {
type = "input",
name = L["Greet"],
desc = L["Send a backchannel greeting to a player to discover if they have an Adherent"],
get = function() end,
set = function(info, val)
local name = adherent:GetSlashCmdTarget(val)
if name and adherent:validName(info, name) then
adherent:ping(name)
end
end,
}
}
}
Expand Down Expand Up @@ -526,23 +553,21 @@ function adherent:options()
order = 25,
get = function(info) return "" end,
set = function(info, val)
adherent:blacklist(val,"follow","+")
end,
validate = function(info, val)
-- check characters >=2<=12
-- check no spaces
-- check no double apostrophes
-- check no numbers
return true
if val~="" then
adherent:blacklist(val,"follow","+")
end
end,
validate = "validName",
}
acceptfollow_args.who.args["blacklistrem"] = {
type = "select",
name = L["Remove from Blacklist"],
desc = L["Remove a player from Blacklist."],
order = 30,
set = function(info, val)
adherent:blacklist(val,"follow","-")
if val~="" then
adherent:blacklist(val,"follow","-")
end
end,
disabled = function(info)
return adherent:table_count(adherent.db.char.follow.blacklist) == 0
Expand All @@ -568,23 +593,21 @@ function adherent:options()
order = 40,
get = function(info) return "" end,
set = function(info, val)
adherent:whitelist(val,"follow","+")
end,
validate = function(info, val)
-- check characters >=2<=12
-- check no spaces
-- check no double apostrophes
-- check no numbers
return true
if val~="" then
adherent:whitelist(val,"follow","+")
end
end,
validate = "validName",
}
acceptfollow_args.who.args["whitelistrem"] = {
type = "select",
name = L["Remove from Whitelist"],
desc = L["Remove a player from Whitelist."],
order = 45,
set = function(info, val)
adherent:whitelist(val,"follow","-")
if val~="" then
adherent:whitelist(val,"follow","-")
end
end,
disabled = function(info)
return adherent:table_count(adherent.db.char.follow.whitelist) == 0
Expand Down Expand Up @@ -689,23 +712,21 @@ function adherent:options()
order = 25,
get = function(info) return "" end,
set = function(info, val)
adherent:blacklist(val,"groupjoin","+")
end,
validate = function(info, val)
-- check characters >=2<=12
-- check no spaces
-- check no double apostrophes
-- check no numbers
return true
if val~="" then
adherent:blacklist(val,"groupjoin","+")
end
end,
validate = "validName",
}
acceptgroup_args.who.args["blacklistrem"] = {
type = "select",
name = L["Remove from Blacklist"],
desc = L["Remove a player from Blacklist."],
order = 30,
set = function(info, val)
adherent:blacklist(val,"groupjoin","-")
if val~="" then
adherent:blacklist(val,"groupjoin","-")
end
end,
disabled = function(info)
return adherent:table_count(adherent.db.char.groupjoin.blacklist) == 0
Expand All @@ -731,23 +752,21 @@ function adherent:options()
order = 40,
get = function(info) return "" end,
set = function(info, val)
adherent:whitelist(val,"groupjoin","+")
end,
validate = function(info, val)
-- check characters >=2<=12
-- check no spaces
-- check no double apostrophes
-- check no numbers
return true
if val~="" then
adherent:whitelist(val,"groupjoin","+")
end
end,
validate = "validName",
}
acceptgroup_args.who.args["whitelistrem"] = {
type = "select",
name = L["Remove from Whitelist"],
desc = L["Remove a player from Whitelist."],
order = 45,
set = function(info, val)
adherent:whitelist(val,"groupjoin","-")
if val~="" then
adherent:whitelist(val,"groupjoin","-")
end
end,
disabled = function(info)
return adherent:table_count(adherent.db.char.groupjoin.whitelist) == 0
Expand Down Expand Up @@ -867,23 +886,21 @@ function adherent:options()
order = 25,
get = function(info) return "" end,
set = function(info, val)
adherent:blacklist(val,"groupsend","+")
end,
validate = function(info, val)
-- check characters >=2<=12
-- check no spaces
-- check no double apostrophes
-- check no numbers
return true
if val~="" then
adherent:blacklist(val,"groupsend","+")
end
end,
validate = "validName",
}
sendgroup_args.who.args["blacklistrem"] = {
type = "select",
name = L["Remove from Blacklist"],
desc = L["Remove a player from Blacklist."],
order = 30,
set = function(info, val)
adherent:blacklist(val,"groupsend","-")
if val~="" then
adherent:blacklist(val,"groupsend","-")
end
end,
disabled = function(info)
return adherent:table_count(adherent.db.char.groupsend.blacklist) == 0
Expand All @@ -909,23 +926,21 @@ function adherent:options()
order = 40,
get = function(info) return "" end,
set = function(info, val)
adherent:whitelist(val,"groupsend","+")
end,
validate = function(info, val)
-- check characters >=2<=12
-- check no spaces
-- check no double apostrophes
-- check no numbers
return true
if val~="" then
adherent:whitelist(val,"groupsend","+")
end
end,
validate = "validName",
}
sendgroup_args.who.args["whitelistrem"] = {
type = "select",
name = L["Remove from Whitelist"],
desc = L["Remove a player from Whitelist."],
order = 45,
set = function(info, val)
adherent:whitelist(val,"groupsend","-")
if val~="" then
adherent:whitelist(val,"groupsend","-")
end
end,
disabled = function(info)
return adherent:table_count(adherent.db.char.groupsend.whitelist) == 0
Expand Down Expand Up @@ -1097,7 +1112,7 @@ function adherent:OnEnable() -- 2. PLAYER_LOGIN
self:ScheduleTimer("deferredInit",5)
end
local faction = UnitFactionGroup("player")
if faction == "Horde" then
if faction == PLAYER_FACTION_GROUP[0] then -- horde
LDB.icon = 666624 -- "Interface\\COMMON\\friendship-FistOrc" -- 666624
else
LDB.icon = 666623 -- "Interface\\COMMON\\friendship-FistHuman" -- 666623
Expand Down Expand Up @@ -1854,6 +1869,45 @@ function adherent:table_val_array(t)
return out
end

function adherent:GetSlashCmdTarget(msg)
msg = msg or ""
local target, server
target = gsub(msg, "(%s*)(.*[^%s]+)(%s*)", "%2", 1)
if ( target == "" ) then
if ( UnitIsPlayer("target") ) then
target = "target"
else
target = nil
end
end
if ( target and (target == "player" or target == "target" or
strfind(target, "^party[1-4]") or
strfind(target, "^raid[0-9]")) ) then
target,server = UnitName(target)
end
return target,server
end

function adherent:validName(info,val)
-- check characters >=2<=12
-- check no spaces
-- check no double apostrophes
-- check no numbers
local len = string.utf8len or string.len
local err_msg = L["Not a valid player name: %s"]
local name_len = len(val)
if name_len == 0 then return true end -- let them exit the input if they clear the text
local valid_len = name_len and name_len > 1 and name_len < 13
if not valid_len then return format(err_msg,L["Length"]) end
local _, num_blanks = val:gsub("%s","")
if num_blanks > 0 then return format(err_msg,L["Spaces"]) end
local _, num_doubleapos = val:gsub("\'\'","")
if num_doubleapos > 0 then return format(err_msg,L["Double Apostrophes"]) end
local _, num_nums = val:gsub("%d","")
if num_nums > 0 then return format(err_msg,L["Numbers"]) end
return true
end

function adherent:Capitalize(word)
return (string.gsub(word,"^[%c%s]*([^%c%s%p%d])([^%c%s%p%d]*)",function(head,tail)
return string.format("%s%s",string.upper(head),string.lower(tail))
Expand Down

0 comments on commit 047bd24

Please sign in to comment.