This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

doubt of code

Help for those learning Tcl or writing their own scripts.
Post Reply
b
bwkzb
Voice
Posts: 16
Joined: Sun Mar 12, 2017 4:26 am

doubt of code

Post by bwkzb »

Code: Select all

set spy(home) "#canal1"
set spy(chan) "#canal2"
set words { *banned* }

bind KICK   -|- "$spy(chan) *"   spychan:kick
proc spychan:kick { nickname hostname handle channel target reason } {
	global spy
	if {[string equal -nocase $channel $spy(chan)]} {
	putserv "PRIVMSG $spy(home) :$channel * $target was kicked from 
$spy(chan) by $nickname $reason"
}
} else {
if {[string match "*" [string tolower $reason]]} {
     set results 0
     foreach x $::words {
     if {[string match -nocase *$x* $reason]} {
     incr results
     }
     }
     if {$results > 0} { putquick "SAJOIN $target #expulsed" }
}
how it could be transformed or added to this code that reads the kicks of users and bots with a certain reason.
For example, read the reason of the kick ("banned") and read that reason and send them back with a SAJOIN to a channel #expulsed
Last edited by bwkzb on Tue Apr 09, 2019 5:21 pm, edited 2 times in total.
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Let me see if I understood your question right:
You'd like to inspect all kick-reasons for certain keywords; if found, the target should be SAJOIN'd to some channel #expulsed?

In that case, most of the bits are already there; just some cleanup and proper syntax needed:
  • Your brackets, {}, are misaligned causing your proc to end before the "} else {" section. This would most likely throw an error when you try to load the script.
  • Testing the kick-reason against "*" will always be true, which is pointless. Just send the PRIVMSG. Also, the PRIVMSG has a newline in it, which cannot be sent correctly.
  • Since you are only interrested in finding a match, not the total number of matches, there's no point in iterating through the list of patterns once a match has been found. Do the SAJOIN here and then break

Code: Select all

set spy(home) "#canal1" 
set spy(chan) "#canal2" 
set words { *banned* }

bind KICK -|- "$spy(chan) *" spychan:kick

proc spychan:kick {nickname hostname handle channel target reason} {
  putserv "PRIVMSG $spy(home) :$channel * $target was kicked from $spy(chan) by $nickname $reason"
  foreach x $::words {
    if {[string match -nocase "*$x*" "$reason"]} {
      putquick "SAJOIN $target #expulsed"
      break
    }
  }
}
NML_375
b
bwkzb
Voice
Posts: 16
Joined: Sun Mar 12, 2017 4:26 am

Post by bwkzb »

Thank you very much for responding and sorry for the delay.

and the variable so that the code reads the badwords of the reasons for the kicks in a .txt file as it would be

Code: Select all

set spy(home) "#canal1" 
set spy(chan) "#canal2" 
set words "scripts/bd/bdreason.txt" 

bind KICK -|- "$spy(chan) *" spychan:kick 

proc spychan:kick {nickname hostname handle channel target reason} { 
 global spy
 putserv "PRIVMSG $spy(home) :$channel * $target was kicked from $spy(chan) by $nickname $reason" 
  foreach bdreason $::words { 
    if {[string match -nocase "*$bdreason*" "$reason"]} { 
      putquick "SAJOIN $target #expulsed" 
      break 
    } 
  } 
}
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Well, there are a few ways we can go here...
  • Read the textfile to memory on startup
  • Read the textfile everytime the kick-binding triggers
  • A mix of the two... (advanced stuff)
In the first two cases, the code is pretty much the same; just a matter when to call it:

Code: Select all

set fd [open "scripts/bd/bdreason.txt" "r"]
set ::words [split [read $fd] "\n"]
close $fd
This would add each line in bdreason.txt as a separate item in the _::words_ variable. This code could either be included inside the spychan:kick proc, or at the start of the script (in place of the current set words "scripts...").
NML_375
Post Reply