mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2018
Posts: 23
R
Ryntovy Offline OP
Ameglian cow
OP Offline
Ameglian cow
R
Joined: Jan 2018
Posts: 23
Hello,

I need some help with creating aliases for each individual letter of the alphabet. The reason behind this is because I am making a blacklist for Twitch chat but people keep finding ways to bypass the banned words.

For example, the word "test" is banned but they use "tést" instead. And there are thousands of combinations they can keep trying. I currently have 5000 banned combinations and it's getting a bit too much.

So what I want to do now is keep the script that I have now and apply the aliases.
Like this:
N = {'N', 'ⓝ', 'n', '𝖓', 'И', ... etc } but I have no idea how to do that.

This is the script I am using to blacklist words:
Code:
on $*:text:*bannedword*:#channel:{
  msg $chan .ban $nick
}


So when someone types "bánnédword" the aliases will replace the "á" with "a" and "é" with "e" and then /ban the user.

I hope you understand what I am trying to explain. Sorry about the bad english, it's not my first language.

Thank you in advance,
Ry

Last edited by Ryntovy; 20/01/18 09:36 PM.
Joined: Jul 2006
Posts: 4,172
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,172
Hello, you'll want to use regular expression for that.

First, the best way to do such a badword script in mIRC is to use an hash table with regex and the R switch of $hfind.

So let's take the letter 'e', and suppose you want to account for different variation of it

In regular expression, [abc] matches either a, b, or c, so you would define letter with that in mind. We'll assume lowercase/uppercase are the same.

e = [eéèêEÉÊ] (you would complete these lists.)

Code:
alias regvar_E return [eéèêEÉÊ]
alias regvar_A return [aààA]


Now, here is a quick example of an hash table usage with $hfind

Code:
/hmake table
/hadd table firstbadword test
/hadd table secondbadword duck
/hadd table thirdbadword raccoon

now given the sentence "wow look a raccoon":
$hfind(table,wow look a raccoon,1,R).data would return thirdbadword, inside an on text event you would just check $hfind(table,$1-,1,R).data

Now when you add an item to the table with /hadd, you would use an alias which would use all the defined variation for any character you defined:

Code:
alias addbadword hadd table $calc($hget(table,0).item + 1) $regsubex($1-,/(*UTF8)(.)/g,$iif($isalias(regvar_\1),$($+($,regvar_\1),2),\1)
This alias is usinsg $regsubex which is nothing less than a while loop on each character of the text passed to the alias
"/addbadword testa" would end up doing "/hadd table 1 t[eéèêEÉÊ]st[aààA]" which would account for the variation you want.

Regular expression are powerful because you can tell it match very precise string.

This should help.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2018
Posts: 23
R
Ryntovy Offline OP
Ameglian cow
OP Offline
Ameglian cow
R
Joined: Jan 2018
Posts: 23
Hello Wims,

Thank you for helping me out, I really appriciate it!

I understand what you're saying but I don't seem to get it to work. I am deffinetly doing something wrong.
Can you post a small example of how you would ban the word "test" with
Code:
on $*:text:*test*:#channel:{
  msg $chan .ban $nick
}
and the code you explained to ban "tést" aswell without making a new
Code:
on $*:text:*tést*:#channel:{
  msg $chan .ban $nick
}
?

I'd be thankful forever. I am super noob at this.

Again thank you very very much ^^

Last edited by Ryntovy; 21/01/18 01:22 AM.
Joined: Jul 2006
Posts: 4,172
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,172
Yep sorry I wrote that very quickly, it was all good except for a missing ) on the $regsubex and you need to actually add (*UTF8) to each pattern as well, here is something that I tested:

Code:
on *:text:*:#:{
  if ($hfind(antibadword,$strip($1-),1,R).data) {
    ban -k $chan $nick 2 antibadword ( base word: $v1 )
  }
}
;/addbadword refword expression
;example /addbadword test test
alias addbadword hadd -m antibadword $1 (*UTF8) $+ $regsubex($2-,/(*UTF8)(.)/g,$iif($isalias(regvar_\1),$($+($,regvar_\1),2),\1))

alias regvar_E return [eéèêEÉÊ]
Just type /addbadword test test.

Now here is where regex becomes even more useful, you can use "/addbadword weed \b(weed|smoking pot)\b" and the \b means word boundaries, so it will only match if the full word is "weed" or if the two words "smoking pot" are said in a sentence, of course it also triggers for wééd, etc.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
The solution to your problem is much simpler than you realize.

Just take every sentence spoken that contain characters outside of standard ASCII (/[^\x20-\x7F]/u) and then use a comprehensive $replace() function to convert letter-like characters into their corresponding ASCII letters. Once you have done this, then process the string through your standard ASCII swear filter as you normally would.

Code:
var %string = $1-
if ($regex(%string,/[^\x20-\x7F]/u)) {
  var %string = $replacexcs(%string, $&
  À,A,Á,A,Â,A,Ã,A,Ä,A,Å,A,Æ,A,Ç,C,È,E,É,E,Ê,E,Ë,E,Ì,I,Í,I,Î,I,Ï,I, $&
  Ð,D,Ñ,N,Ò,O,Ó,O,Ô,O,Õ,O,Ö,O,×,x,Ø,O,Ù,U,Ú,U,Û,U,Ü,U,Ý,Y,Þ,P,ß,B, $&
  à,a,á,a,â,a,ã,a,ä,a,å,a,æ,a,ç,c,è,e,é,e,ê,e,ë,e,ì,i,í,i,î,i,ï,i, $&
  ð,o,ñ,n,ò,o,ó,o,ô,o,õ,o,ö,o,ø,o,ù,u,ú,u,û,u,ü,u,ý,y,þ,p)
} ; by Raccoon 2018 (untested)

Is it short pretty code? No. Is it fast? Yes.

_________________________
/hadd table thirdbadword raccoon

Joined: Jul 2006
Posts: 4,172
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,172
I don't have any problem, just helping OP.

I was mainly showing how to use $hfind to efficiently do a badwords system which works for expression in general and not just words, which is not limited, for example if he wants to specifically ban the word "tést" without banning "tèst" he can very easily to that by just adding directly "tést" to the table without using /addbadword

Your solution is very limited in that aspect, if you start replacing, then it is impossible to ban specific word like tést.

Also, in this context of twitch chat, people talk from everywhere on the planet, you'll extremely often have characters outside ascii appearing, yet you'll often not have any replacement to make, but your code is going to parse that $replacex everytime nonetheless, for nothing, you call it fast but it would be much faster to include what you want to replace directly in the pattern, and maintaining such a script by hardcoding stuff, well it's possible, theorically faster but in practice it's a pain, especially to know what you have already for which letter, especially for a beginner.

And if you want to handle specific expressions prior replacing then you're doing some kind of combination of two methods, maybe that's not best/faster.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
Sorry Ouims, I meant to address the original poster.

And sorry too, nobody cares about French swear words using funny looking letters wearing squiggly little hats. American English vulgarity is king.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Jan 2018
Posts: 23
R
Ryntovy Offline OP
Ameglian cow
OP Offline
Ameglian cow
R
Joined: Jan 2018
Posts: 23
Okay so I used this code:

Code:
on *:text:*test*:#:{
  if ($hfind(antibadword,$strip($1-),1,R).data) {
    ban -k $chan $nick 2 antibadword ( base word: $v1 )
  }
}
;/addbadword refword expression
;example /addbadword test test
alias addbadword hadd -m antibadword $1 (*UTF8) $+ $regsubex($2-,/(*UTF8)(.)/g,$iif($isalias(regvar_\1),$($+($,regvar_\1),2),\1))

alias regvar_E return [eéèêEÉÊ]


I put in "test" on this part:
Code:
on *:text:*test*:#:


But it doesn't ban the user who types test or tést.
I am so confused. I am connected and mirc is working fine with my original script so I am doing it wrong (again)
Do I have to replace the words "antibadword" and "addbadword" if so, with what do I replace it?

With kind regards,
Ry

Joined: Jul 2006
Posts: 4,172
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,172
You don't have to touch anything in the code, the event is using * to allow any sentence to trigger and then use $1- inside $hfind to find badwords, re-read my posts, the point is to pass the sentence of the user to $hfind, you don't specify "test" in the event, you add it to the hash table, this addition is eased by the usage of the /addbadword alias, which you have to call to add a badword.

I'd have told you if you needed to edit anything, instead I clearly said:
Quote:
Just type /addbadword test test.

Last edited by Wims; 21/01/18 06:12 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2018
Posts: 23
R
Ryntovy Offline OP
Ameglian cow
OP Offline
Ameglian cow
R
Joined: Jan 2018
Posts: 23
Where do I type /addbadword ?

Joined: Jan 2018
Posts: 23
R
Ryntovy Offline OP
Ameglian cow
OP Offline
Ameglian cow
R
Joined: Jan 2018
Posts: 23
So this is how to use it?

Code:
on *:text:*:#:{
  if ($hfind(antibadword,$strip($1-),1,R).data) {
    ban -k $chan $nick 2 antibadword ( base word: $v1 )
  }
}
;/addbadword refword expression
;example /addbadword test test
alias addbadword hadd -m antibadword $1 (*UTF8) $+ $regsubex($2-,/(*UTF8)(.)/g,$iif($isalias(regvar_\1),$($+($,regvar_\1),2),\1))

alias regvar_E return [eéèêEÉÊ]

on *:text:*test*:#:{
  msg $chan .ban $nick
}

Last edited by Ryntovy; 21/01/18 06:34 PM.
Joined: Jul 2006
Posts: 4,172
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,172
Yes this is how you use it, you don't have to use the on text event on *test* at the end, you can delete that.
You type "/addbadword test test" in any mIRC editbox, that will call the alias, this alias is just an easy way for you to add badwords.
For example, you would also type "/addbadword bannedword bannedword" etc


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2018
Posts: 23
R
Ryntovy Offline OP
Ameglian cow
OP Offline
Ameglian cow
R
Joined: Jan 2018
Posts: 23
I think it's almost working! awesome!
I typed /addbadword test test


And now I get this message in mIRC when I type "tést" in twitch chat:
* /ban: must be an op on #mychannelname (line 3, test.ini)

And my last question, how do I check what words I added and how to I remove / edit those words? smile

Thank you very much for helping me out, and for your patience. I know I am kind of annoying how stupid I am.

Joined: Jul 2006
Posts: 4,172
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,172
You would need to loop over each item in the hash table, how would you like this list to be displayed? To delete a word, type "/hdel badword <refword>" refword is the first word you pass in /addbadword, which can be different from the actual word you want to find. Feel free to join the channel in my signature for more direct help wink


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2018
Posts: 23
R
Ryntovy Offline OP
Ameglian cow
OP Offline
Ameglian cow
R
Joined: Jan 2018
Posts: 23
Is there no way to apply the alias to the words that I already have made?
Because otherwise I have to copy+paste 5000 words frown

Joined: Jul 2006
Posts: 4,172
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,172
No, there's no way, but you do realize that if you have on text events for *test*, *tést* and *tèst* etc, that's only one word to add: test, and then you edit the list of letter in the regvar_E alias, right?
So if your 5000 words are really 100 same-family word (as in test/tést/tèst), that's only 50 words to add.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2006
Posts: 4,172
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,172
See my previous post with the weed example, refword is a reference for the expression.
This is not related to your tést/test case but it's just great:
Let's say you want to ban some fruits name, but you want to kick-ban with a kick message that says 'you triggered my fruit badword, please don't use fruit name'

You would do "/addbadword fruit apple|banana|strawberry", and in my code, the kick message would show (ref word: fruit), you would also delete with "/hdel antibadword fruit".

My code is simple and was meant as a quick example you can learn/start from, the hash table is loaded in memory, it is not saved to disk, /hload is not relevant there.

For /ban to work you need to be an operator on the channel, if you want to ban with a different command you can always change /ban in the code

Last edited by Wims; 21/01/18 09:39 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard