mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2004
Posts: 59
L
Babel fish
OP Offline
Babel fish
L
Joined: Jul 2004
Posts: 59
I am trying to get a swear system to work using a msqlite database, So far things seem to be working ok but I am having problems when It comes to setting the var %request No matter if the word is or isnt in the text the system will not $replace the offensive text. and send to the Database. If I take out the else stament the text is added and the word masked, but if I leave it in no matter if the word is there or not no mask. Thank you for any help anyone can give.

/*
** Trigger /prayer add nick This is the text I need to check and mask if offensive word is in it.
*/
alias prayer {
; Make sure we are connected to db
if (!%prayer_db) {
echo 4 -a Error: Not connected to prayer.db
return
}

var %cmd = $1
if (%cmd != add && %cmd != del && %cmd != list && %cmd != find) {
echo 4 -a Error: Unknown action.
return
}

; Do action
if (%cmd == add) {
/unset %badword*
; Add greet
var %ID = $calc(%prayer_numb + 1)
var %date = $fulldate
var %nick = $2
var %safe_words = $replace($sqlite_escape_string(%words),*,%,?,_)
var %sql = SELECT * FROM badwords
var %request1 = $sqlite_query(%prayer_db, %sql)
if (!%request1) {
echo 4 -a Error: %sqlite_errstr
return
}
/* this is the problem Area */

while ($sqlite_fetch_row(%request1, row)) {
if ($hget(row, word) isin $3-) {
set %badword_len $len($hget(row, word))
badword_len
set %request $replace($3-,$hget(row, word),%badword_mask)
}
else { echo -a else set %request $3- }

}
if ( !%nick || !%request1) {
echo 4 -a Error: Invalid arguments.

return
}
; Escape nick and request and then execute query
var %safe_nick = $sqlite_escape_string(%nick), %safe_request = $sqlite_escape_string(%request)
sqlite_exec %prayer_db REPLACE INTO prayers (ID, date, nick, request) VALUES (' $+ %ID $+ ', ' $+ %date $+ ', ' $+ %safe_nick $+ ', ' $+ %safe_request $+ ')
inc %prayer_numb 1
}
}

/* Retrive Lenth of offensive word and set mask with correct # of *'s
*/
alias badword_len {
set %badword_toc 0
while %badword_toc < %badword_len {
set %badword_mask $chr(42) $+ %badword_mask
inc %badword_toc 1
}
}

Last edited by LittleJohn; 20/04/08 10:39 PM.
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Your code has bracket misalignment. Your ELSE is within your IF, rather than after it.

-genius_at_work

Last edited by genius_at_work; 20/04/08 10:12 PM.
Joined: Jul 2004
Posts: 59
L
Babel fish
OP Offline
Babel fish
L
Joined: Jul 2004
Posts: 59
Hello I changed the Bracket but still no luck the test still has the bad word

Example;

/prayer add LittleJohn This has a badword in it
/prayer add LittleJohn But this isnt

Reply from Data base

This has a badword in it
But this isnt

The badword should be *******


Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Code:

while ($sqlite_fetch_row(%request1, row)) {
  if ($hget(row, word) isin $3-) {
    set %badword_len $len($hget(row, word)) 
    badword_len 
    set %request $replace($3-,$hget(row, word),%badword_mask)
  } 
  else { echo -a else set %request $3- }
}



The if/else part shouldn't be necessary at all.

Code:

while ($sqlite_fetch_row(%request1, row)) {
    set %badword_len $len($hget(row, word)) 
    badword_len 
    set %request $replace($3-,$hget(row, word),%badword_mask)
}



$replace won't replace words that aren't there, so you don't need to test that the word isin the text.

Also, you don't need an alias to create a string of *'s.

Code:

while ($sqlite_fetch_row(%request1, row)) {
    set %request $replace($3-,$hget(row,word),$str(*,$len($hget(row,word))))
}



/help $str

-genius_at_work

Last edited by genius_at_work; 21/04/08 12:22 AM.

Link Copied to Clipboard