• Dear Guest,

    You're browsing our forum as a Guest meaning you can only see a portion of the forum in read-only mode.
    To view all forum nodes and be able to create threads/posts please register or log-in with your existing account.

    TwinStar team

help with making an addon

Cr0wL0ck

New Member
Joined
Aug 23, 2014
Likes
161
#1
Greeting's

i am trying to make a troll filter addon, the idea is that it by default disables repeated spam but when typing in a command it removes anything with the listed troll words from chat after it has been used
"in short it mutes most if not all troll sentences".

here's the .lua code, in this example it should mute all sentences containing "test" or "troll" when typing in /run TestFilter.

Code:
ChatFilter_ChatFrame_OnEvent = ChatFrame_OnEventChatFilter_Timer = GetTime()
ChatFilter_Messages = {{},{},{},{},{},{},{},{},{}}


function ChatFrame_OnEvent(event)




SLASH_CF1 = "/Run TestFilter";


  SlashCmdList["CF"] = function(msg)
      ZSM_SlashCommandHandler(msg);


    if ( strsub(event, 1, 8) == "CHAT_MSG" ) then
        if arg2 then
            if TestFilter and string.find(string.lower(arg1),"Test", "troll") then
                return
            end
            local type = strsub(event, 10);
            if ( string.sub(type,1,7) == "CHANNEL" or type == "WHISPER" or type == "GUILD" or type == "YELL" or type == "SAY" or type == "EMOTE" or type == "RAID" ) then
                while ChatFilter_Timer < GetTime() do
                    ChatFilter_Timer = ChatFilter_Timer + 1
                    for i = 0,7 do
                        ChatFilter_Messages[9-i] = ChatFilter_Messages[9-i-1]
                    end
                    ChatFilter_Messages[1] = {}
                end
                for i = 1,5 do
                    for j = 1, table.getn(ChatFilter_Messages[i]) do
                        if ChatFilter_Messages[i][j] == arg2..arg1 then
                            return
                        end
                    end
                end
                table.insert(ChatFilter_Messages[1],arg2..arg1)
            end
        end
    end
    ChatFilter_ChatFrame_OnEvent(event)
end




function ColorPrint(msg,r,g,b)
    DEFAULT_CHAT_FRAME:AddMessage(msg, r, g, b)
end
function Print(msg)
    ColorPrint(msg, 1, 1, 0)
end
i cannot see where i went wrong but i cannot get the command part to work, it mutes spam perfectly and only shows the first time but
 

Cr0wL0ck

New Member
Joined
Aug 23, 2014
Likes
161
#3
May I ask you whats exactly your problem, its not clear to me when i read your thread here. Maybe i can help you.
the current code automatically "mutes" whenever someone repeats a word so you only see it the first time.

for example you or another repeats "lol" 5 time's but you will only see the first in your chat log and the rest is muted as long as they match the exact word.

what i want to add is the function above that is supposed to search for sentences containing the word's "test" and "troll". this is only as an example/test but it should then mute the sentences similar to the automatic function when you use the command "Run TestFilter", i wouldnt mind if it was on by default either like the original command but i am trying to make an addon that filter's all chat channels for sentences who contain troll word's to remove/reduce trolling ☺

note: currently when i type in "/run testfilter" it does nothing and i am rather sure i made more than one mistake in that part of the code since i am new to .lua but i want to make addons for 1.12.1 since there are so few already but i cannot find the original book from then so i try as good as i can to learn by reverse engineering.
 
Last edited:
Joined
Aug 9, 2014
Likes
117
Location
Germany
#4
Ill test a few things myself in the next 2-3 days and inform you if it works^^ Right now im a bit busy, but its an interesting project, so id like to keep helping :)
 

Cr0wL0ck

New Member
Joined
Aug 23, 2014
Likes
161
#5
Ill test a few things myself in the next 2-3 days and inform you if it works^^ Right now im a bit busy, but its an interesting project, so id like to keep helping :)
thanks a lot ^^
i am rather new to .lua coding and only started since i considered it a shame that addons wherent fixed or updated, but this addon in particular has me interrested ☺

i currently got 2 major projects that would change global/world chat a lot.

1: this troll filter
2: adding a wts/wtb function to "calltoarms" that works alongside the LFG but in another tab
(so far i only improved the filters to sort out random chat)
 
Joined
Aug 9, 2014
Likes
117
Location
Germany
#6
Im sorry, but i didnt find time to have a look on your code and test it due much work that has to be done before everything else, so im not sure wether ill find time the next few days but ill definitly have a look on the weekend atleast.
 

Cr0wL0ck

New Member
Joined
Aug 23, 2014
Likes
161
#7
thank you, i am still trying to learn more .lua code so i can fix this addon since it would improve world/global chat spam a lot to have the most common trolls removed :biggrin:

i am also working on "calltoarms" and trying to make an addon that replaces resistance tooltip's with an accurate percentage of resist according to vanilla so you can see how high the chance is to fully and partly resist depending on resistance, sadly i am not a pro but i do the best i can whenever i find time and i hope you will help me in fixing, improving and making addons for Kronos :)
 

Cr0wL0ck

New Member
Joined
Aug 23, 2014
Likes
161
#8
i am trying a different approach while thinking of a way to fix the one listed above.
this is the current error i get on line 5: Error: attempt to call global `strsplit' (a nil value)

The idea is to write /Filter <Word> <Replacement> the addon then exchanges words with what you wrote, i would then copy the wtf file with 3 different strengths of filter where words are replaced with **** or simply removed from the sentence, but to be honest i would prefer having the first idea since it can mute the sentence.

Code:
SLASH_WORDFILTER1 = '/filter'SLASH_WORDUNFILTER1 = '/unfilter'


local function PWFSlash1(args, editbox)
    local arg1, arg2 = strsplit(" ", args)
    if arg1 ~= "" and not strfind(arg2 or "<snip>", arg1) then -- Filter a word to be replaced with itself, and you get an infinite loop. So don't.
        if arg2 then
            WordFilterDB[arg1] = arg2
        else
            WordFilterDB[arg1] = "<snip>"
        end
        print("\"" .. arg1 .. "\" is now filtered.")
    else
        print("Can't let you filter that, there will be problems.")
    end
end


local function PWFSlash2(args, editbox)
    local arg = strsplit(" ", args)
    if arg then
        WordFilterDB[arg] = nil
        print("\"" .. arg .. "\" is no longer filtered.")
    end
end


SlashCmdList["WORDFILTER"] = PWFSlash1
SlashCmdList["WORDUNFILTER"] = PWFSlash2




local scm = SendChatMessage
SendChatMessage = function(msg)
    local rmsg = msg -- Message to resend
    local tmsg = strlower(msg) -- Temporary message; to prevent length issues
    for k,v in pairs(WordFilterDB) do
        local start, stop = strfind(tmsg, strlower(k))
        while start do
            rmsg = strsub(rmsg, 1, start-1) .. v .. strsub(rmsg, stop+1)
            tmsg = strsub(tmsg, 1, start-1) .. strlower(v) .. strsub(tmsg, stop+1)
            start, stop = strfind(tmsg, strlower(k))
        end
    end
    scm(rmsg)
end


local function onEvent(self, event)
    if not WordFilterDB then WordFilterDB = {} end
end


local eventFrame = CreateFrame("Frame")
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:SetScript("OnEvent", onEvent)
note: it also disables writing in channels for some reason, even if it seems like you are in a channel it writes everything in /s which i cannot explain either :(

i really need a hand with making/fixing addons :( i want to have some good ready to use when kronos comes but as said i am no pro so i often get stuck.... S.O.S need help fixing/making addons to have addons that can live up to kronos quality :)
 
Last edited:

Psojed

Authorized
Joined
Jan 13, 2009
Likes
485
#9
The result is always "say" message, because you didn't add the argument for another type of channel.
http://wowpedia.org/API_SendChatMessage

The error you get is because strsplit was added with TBC expansion. See the API history starts in 2007
http://wowpedia.org/index.php?title=API_strsplit&action=history

I think using SendChatMessage would make sense if you wanted to filter outgoing messages, in other words filter stuff that YOU write to others, but I thought you only want to filter incoming spam messages.
 
Last edited:

Cr0wL0ck

New Member
Joined
Aug 23, 2014
Likes
161
#10
ah XD

thanks a lot :biggrin:, and yeah thats true i guess ill search for another way to filter so it doesnt filter outgoing as well XD
 

Psojed

Authorized
Joined
Jan 13, 2009
Likes
485
#11
Well I meant the output from the addon. SendChatMessage is used as if you normally typed into wow chat. Let's say a Troll is spamming "troll" word and you use your addon.
Using SendChatMessage it would actually look like this:

Troll says: troll
* your addon does the work*
You say: troll
 
Top Bottom