/
------------------------------------------------------------------------ |
-- NoGuild |
-- Block guild solicitations. |
------------------------------------------------------------------------ |
--[[-------------------------------------------------------------------- |
NoGuild |
Blocks guild solicitations in whispers and public chat channels. |
Written by Phanx <addons@phanx.net> |
This is free and unencumbered software released into the public domain. |
See the accompanying README and UNLICENSE files for more information. |
http://www.wowinterface.com/downloads/info-NoGuild.html |
http://www.curse.com/addons/wow/noguild/ |
----------------------------------------------------------------------]] |
-- Almost all guild spam has at least one of these words. |
local L1 = { |
------------------------------------------------------------------------ |
local db, myName, myRealm |
local last, result |
local blockedThisSession, filterMessages, filterCount, replying = {}, {}, 0 |
local format, strfind, strjoin, strlower, strmatch, tinsert, tostring, tremove, type |
= format, strfind, strjoin, strlower, strmatch, tinsert, tostring, tremove, type |
local BNGetFriendToonInfo, BNGetNumFriends, BNGetNumFriendToons, CanComplainChat, GetAutoDeclineGuildInvites, IsInGuild, UnitInParty, UnitInRaid, UnitIsInMyGuild |
= BNGetFriendToonInfo, BNGetNumFriends, BNGetNumFriendToons, CanComplainChat, GetAutoDeclineGuildInvites, IsInGuild, UnitInParty, UnitInRaid, UnitIsInMyGuild |
local format, strfind, strjoin, strlower, strmatch, tinsert, tostring, tremove, type |
= format, strfind, strjoin, strlower, strmatch, tinsert, tostring, tremove, type |
= BNGetFriendToonInfo, BNGetNumFriends, BNGetNumFriendToons, CanComplainChat, GetAutoDeclineGuildInvites, IsInGuild, UnitInParty, UnitInRaid, UnitIsInMyGuild |
local L = setmetatable({}, { __index = function(t, k) |
if k == nil then return "" end |
local v = tostring(k) |
rawset(t, k, v) |
return v |
end }) |
local function print(str, ...) |
local function debug(lvl, str, ...) |
if str then |
if (...) then |
if type(str) == "string" and strmatch(str, "%%[dfqsx%d%.]") then |
end |
end |
local function debug(lvl, str, ...) |
if str and lvl <= 5 then |
if (...) then |
if type(str) == "string" and strmatch(str, "%%[dfqsx%d%.]") then |
DEFAULT_CHAT_FRAME:AddMessage("|cffffff77[NoGuild]|r " .. format(str, ...)) |
else |
DEFAULT_CHAT_FRAME:AddMessage("|cffffff77[NoGuild]|r " .. strjoin(" ", tostringall(str, ...))) |
end |
else |
DEFAULT_CHAT_FRAME:AddMessage("|cffffff77[NoGuild]|r " .. tostring(str)) |
end |
end |
end |
------------------------------------------------------------------------ |
local function FilterSystemMessage(self, event, message) |
if filterMessages[message] then |
debug(1, "CHAT_MSG_SYSTEM", message) |
filterMessages[message] = nil |
filterCount = filterCount - 1 |
if filterCount == 0 then |
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SYSTEM", FilterSystemMessage) |
end |
return true |
end |
end |
local last, result |
local function FilterOutgoingWhisper(self, event, message) |
if message == db.reply then |
debug(1, "CHAT_MSG_WHISPER_INFORM", message) |
ChatFrame_RemoveMessageEventFilter("CHAT_MSG_WHISPER_INFORM", FilterOutgoingWhisper) |
return true |
end |
end |
------------------------------------------------------------------------ |
local function FilterIncoming(self, event, message, sender, _, _, _, flag, _, _, _, _, line, guid) |
if line == last then |
return result |
last, result = line, nil |
if GetAutoDeclineGuildInvites() == 0 and not IsInGuild() then |
return --debug(1, "ALLOWED [GetAutoDeclineGuildInvites]", tostring(GetAutoDeclineGuildInvites()), "[IsInGuild]", tostring(IsInGuild())) |
return -- debug("ALLOWED [GetAutoDeclineGuildInvites]", tostring(GetAutoDeclineGuildInvites()), "[IsInGuild]", tostring(IsInGuild())) |
end |
--debug(2, "[flag]", tostring(flag), "[line]", tostring(line), "[CanComplainChat]", tostring(CanComplainChat(line))) |
-- debug("[flag]", tostring(flag), "[line]", tostring(line), "[CanComplainChat]", tostring(CanComplainChat(line))) |
if flag == "GM" or flag == "DEV" then |
return --debug(1, "ALLOWED [flag]", flag) |
return -- debug("ALLOWED [flag]", flag) |
end |
if event == "CHAT_MSG_CHANNEL" and (channelId == 0 or type(channelId) ~= "number") then |
end |
if not CanComplainChat(line) or UnitIsInMyGuild(sender) or UnitInRaid(sender) or UnitInParty(sender) then |
return debug(1, "ALLOWED [CanComplainChat]", tostring(CanComplainChat(line) or "nil"), |
return --[[ debug("ALLOWED", |
"[CanComplainChat]", tostring(CanComplainChat(line) or "nil"), |
"[UnitIsInMyGuild]", tostring(UnitIsInMyGuild(sender) or "nil"), |
"[UnitInRaid]", tostring(UnitInRaid(sender) or "nil"), |
"[UnitInParty]", tostring(UnitInParty(sender) or "nil")) |
"[UnitInRaid]", tostring(UnitInRaid(sender) or "nil"), |
"[UnitInParty]", tostring(UnitInParty(sender) or "nil")) ]] |
end |
if event == "CHAT_MSG_WHISPER" then |
for i = 1, select(2, BNGetNumFriends()) do |
local _, numBnetFriends = BNGetNumFriends() |
for i = 1, numBnetFriends do |
for j = 1, BNGetNumFriendToons(i) do |
local _, name, game = BNGetFriendToonInfo(i, j) |
if name == sender and game == "WoW" then |
return debug(1, "ALLOWED [BNGetFriendToonInfo]", i, j, name, game) |
return -- debug("ALLOWED [BNGetFriendToonInfo]", i, j, name, game) |
end |
end |
end |
end |
end |
if score > 1 then |
if score > db.threshold then |
tinsert(NoGuildMessages[myRealm], format("[%d] %s: %s", score, sender, message)) |
if db.debug then |
print(L["Blocked message with score %d from |Hplayer:%s:%d|h%s|h:"], score, sender, line, sender) |
print(" ", message) |
end |
if event == "CHAT_MSG_WHISPER" and db.reply then |
-- ### NODEBUG |
-- ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", FilterOutgoingWhisper) |
-- SendChatMessage(db.reply, "WHISPER", nil, sender) |
end |
local n = 1 + (blockedThisSession[sender] or 0) |
if n > db.ignore then |
if db.debug then |
print(L["Ignoring |Hplayer:%s:%d|h%s|h for sending more than %d guild ads this session."], sender, line, sender, db.ignore) |
end |
ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", FilterSystemMessage) |
local ignores = GetNumIgnores() |
while ignores > 45 do |
local oldest = tremove(db.history, 1) |
if not oldest then break end |
filterCount = filterCount + 1 |
filterMessages[format(ERR_IGNORE_REMOVED_S, oldest)] = true |
-- ### DEBUG |
debug(1, "%d ignores, removing %s", ignores, oldest) |
DelIgnore(oldest) |
ignores = GetNumIgnores() |
end |
filterCount = filterCount + 1 |
filterMessages[format(ERR_IGNORE_ADDED_S, sender)] = true |
-- ### DEBUG |
debug(1, "AddIgnore", sender) |
AddIgnore(sender) |
table.insert(db.history, sender) |
end |
blockedThisSession[sender] = n |
result = true |
return true |
if score > db.threshold then |
-- debug("Blocked message with score %d from |Hplayer:%s:%d|h%s|h:", score, sender, line, sender) |
-- debug(" ", message) |
tinsert(db.history, format("[%d] %s: %s", score, sender, message)) |
while #db.history > 100 do |
tremove(db.history, 1) |
end |
if db.debug then |
-- ### DEBUG |
debug(1, L["Allowed message with score %d from |Hplayer:%s|h%s|h."], score, sender, sender) |
end |
result = true |
return true |
end |
result = nil |
local addon = CreateFrame("Frame") |
addon:RegisterEvent("PLAYER_LOGIN") |
addon:SetScript("OnEvent", function() |
local default = { |
debug = true, |
history = {}, |
ignore = 0, |
reply = "[NoGuild] Your message was blocked because it looks like a guild solicitation, and I'm not looking for a guild right now.", |
threshold = 3, |
} |
NoGuildDB = NoGuildDB or {} |
db = NoGuildDB |
for k, v in pairs(default) do |
for k, v in pairs({ |
history = {}, |
threshold = 3, |
}) do |
if db[k] == nil then |
db[k] = v |
end |
end |
myName = UnitName("player") |
myRealm = GetRealmName() |
tinsert(L1, myName) -- never seen a legit whisper that includes my character name, it's always spam of some kind |
NoGuildMessages = NoGuildMessages or {} |
NoGuildMessages[myRealm] = NoGuildMessages[myRealm] or {} |
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", FilterIncoming) |
ChatFrame_AddMessageEventFilter("CHAT_MSG_CHANNEL", FilterIncoming) |
end) |
------------------------------------------------------------------------ |
local panel = CreateFrame("Frame", nil, InterfaceOptionsFramePanelContainer) |
panel.name = "NoGuild" |
panel:Hide() |
panel:SetScript("OnShow", function(self) |
if not panel.title then |
-- setup |
end |
-- refresh |
end) |
------------------------------------------------------------------------ |
SLASH_NOGUILD1 = "/noguild" |
SLASH_NOGUILD2 = "/nog" |
SlashCmdList["NOGUILD"] = function(cmd) |
cmd = cmd:trim() |
if cmd:lower() == "noreply" then |
db.reply = false |
print(L["Reply now disabled."]) |
elseif cmd:len() > 0 then |
db.reply = "[NoGuild] " .. cmd |
print(L["Reply now set to:"], cmd) |
else |
print(L["Enter a new reply message, or use 'noreply' to disable replies."]) |
if db.reply then |
print(L["Reply currently set to:"], db.reply:sub(11)) |
else |
print(L["Reply currently disabled."]) |
end |
end |
end |
This is free and unencumbered software released into the public domain. |
Anyone is free to copy, modify, publish, use, compile, sell, or |
distribute this software, either in source code form or as a compiled |
binary, for any purpose, commercial or non-commercial, and by any |
means. |
In jurisdictions that recognize copyright laws, the author or authors |
of this software dedicate any and all copyright interest in the |
software to the public domain. We make this dedication for the benefit |
of the public at large and to the detriment of our heirs and |
successors. We intend this dedication to be an overt act of |
relinquishment in perpetuity of all present and future rights to this |
software under copyright law. |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
OTHER DEALINGS IN THE SOFTWARE. |
For more information, please refer to <http://unlicense.org/> |
## Interface: 50400 |
## Version: 5.4.1.wowi:revision |
## Title: NoGuild |
## Notes: Block guild solicitations in whispers and public chat channels. |
## Notes-esES: Bloquear los anuncios de hermandades en susurros y los canales públicos. |
## Notes-esMX: Bloquear los anuncios de hermandades en susurros y los canales públicos. |
## SavedVariables: NoGuildDB, NoGuildMessages |
## Author: Phanx |
## X-Email: addons@phanx.net |
## X-License: Public Domain |
## X-CompatibleLocales: deDE, enUS, esES, esMX, frFR, itIT, ptBR, koKR, ruRU, zhCN, zhTW |
## X-Website: http://www.wowinterface.com/downloads/info-NoGuild.html |
## X-Curse-Project-Name: noguild |
## X-WoWI-ID: |
## SavedVariables: NoGuildMessages |
NoGuild.lua |
NoGuild |
============ |
* Written by Phanx <addons@phanx.net> |
* http://www.wowinterface.com/downloads/info-NoGuild.html |
* http://www.curse.com/addons/wow/noguild |
Description |
---------------- |
Blocks guild solicitations in whispers and public chat channels. |
Localization |
----------------- |
Compatible with all locales. Does not require translations. |
Feedback |
------------- |
Bugs, errors, or other problems: |
Please use the ticket system on either download page. |
Feature requests or other suggestions: |
Please use the ticket system on either download page. |
General questions or comments: |
Post a comment on either download page. |
If you need to contact me privately for a reason **other** than those |
listed above, you can send a PM to Phanx on either download site, or |
email me at <addons@phanx.net>. |