WoWInterface SVN NoGuild

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 3 to Rev 2
    Reverse comparison

Rev 3 → Rev 2

trunk/UNLICENSE.txt File deleted \ No newline at end of file
trunk/README.txt File deleted \ No newline at end of file
trunk/NoGuild.toc
1,5 → 1,4
## Interface: 50400
## Version: 5.4.1.wowi:revision
 
## Title: NoGuild
## Notes: Block guild solicitations in whispers and public chat channels.
7,14 → 6,6
## 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.
 
## 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: NoGuildDB, NoGuildMessages
 
## SavedVariables: NoGuildMessages
 
NoGuild.lua
\ No newline at end of file
trunk/NoGuild.lua
1,12 → 1,7
--[[--------------------------------------------------------------------
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/
----------------------------------------------------------------------]]
------------------------------------------------------------------------
-- NoGuild
-- Block guild solicitations.
------------------------------------------------------------------------
 
-- Almost all guild spam has at least one of these words.
local L1 = {
51,13 → 46,23
 
------------------------------------------------------------------------
 
local format, strfind, strjoin, strlower, strmatch, tinsert, tostring, tremove, type
= format, strfind, strjoin, strlower, strmatch, tinsert, tostring, tremove, type
local db, myName, myRealm
local last, result
local blockedThisSession, filterMessages, filterCount, replying = {}, {}, 0
 
local BNGetFriendToonInfo, BNGetNumFriends, BNGetNumFriendToons, CanComplainChat, GetAutoDeclineGuildInvites, IsInGuild, UnitInParty, UnitInRaid, UnitIsInMyGuild
= 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
 
local function debug(lvl, str, ...)
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, ...)
if str then
if (...) then
if type(str) == "string" and strmatch(str, "%%[dfqsx%d%.]") then
71,10 → 76,44
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 last, result
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 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
82,13 → 121,13
last, result = line, nil
 
if GetAutoDeclineGuildInvites() == 0 and not IsInGuild() then
return -- debug("ALLOWED [GetAutoDeclineGuildInvites]", tostring(GetAutoDeclineGuildInvites()), "[IsInGuild]", tostring(IsInGuild()))
return --debug(1, "ALLOWED [GetAutoDeclineGuildInvites]", tostring(GetAutoDeclineGuildInvites()), "[IsInGuild]", tostring(IsInGuild()))
end
 
-- debug("[flag]", tostring(flag), "[line]", tostring(line), "[CanComplainChat]", tostring(CanComplainChat(line)))
--debug(2, "[flag]", tostring(flag), "[line]", tostring(line), "[CanComplainChat]", tostring(CanComplainChat(line)))
 
if flag == "GM" or flag == "DEV" then
return -- debug("ALLOWED [flag]", flag)
return --debug(1, "ALLOWED [flag]", flag)
end
 
if event == "CHAT_MSG_CHANNEL" and (channelId == 0 or type(channelId) ~= "number") then
97,20 → 136,18
end
 
if not CanComplainChat(line) or UnitIsInMyGuild(sender) or UnitInRaid(sender) or UnitInParty(sender) then
return --[[ debug("ALLOWED",
"[CanComplainChat]", tostring(CanComplainChat(line) or "nil"),
return debug(1, "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
local _, numBnetFriends = BNGetNumFriends()
for i = 1, numBnetFriends do
for i = 1, select(2, BNGetNumFriends()) do
for j = 1, BNGetNumFriendToons(i) do
local _, name, game = BNGetFriendToonInfo(i, j)
if name == sender and game == "WoW" then
return -- debug("ALLOWED [BNGetFriendToonInfo]", i, j, name, game)
return debug(1, "ALLOWED [BNGetFriendToonInfo]", i, j, name, game)
end
end
end
134,15 → 171,58
end
end
 
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)
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
end
result = true
return true
 
if db.debug then
-- ### DEBUG
debug(1, L["Allowed message with score %d from |Hplayer:%s|h%s|h."], score, sender, sender)
end
end
 
result = nil
153,18 → 233,65
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({
history = {},
threshold = 3,
}) do
for k, v in pairs(default) 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)
ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER", FilterIncoming)
end)
\ No newline at end of file +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 \ No newline at end of file