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.

help tcl welcome

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

help tcl welcome

Post by Arnold_X-P »

This works well tcl only it works in a channel

Code: Select all

set ayuda_chanxp "#tcl" 

set msg_greet($::ayuda_chanxp) {
  "welcome $nick to $chan" 
  "thanks for visit" 
  "for view rules tipe !rules" 
} 

bind join - * chan_greet 

proc chan_greet {nick uhost hand chan} { 
  global botnick ayuda_chanxp msg_greet 
  if {$nick == $botnick} {return 1} 
  if {$chan == $ayuda_chanxp} { 
    set msg_temp $msg_greet($chan) 
    foreach i $msg_temp {puthelp "NOTICE $nick :[subst $i]"} 
    return 1 
  } 
} 
but my question is
You can extend this tcl to operate in several channels?

example:

Code: Select all

set ayuda_chanxp "#tcl #help #mirc"
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

Prueba con esto:

Code: Select all

set ayuda_chanxp "#tcl #help #mirc"

set msg_greet($::ayuda_chanxp) {
  "welcome $nick to $chan"
  "thanks for visit"
  "for view rules tipe !rules"
}

bind join - * chan_greet

proc chan_greet {nick uhost hand chan} {
  global botnick ayuda_chanxp msg_greet
  if {$nick == $botnick} {return 1}
if {[lsearch -exact [string tolower $ayuda_chanxp] [string tolower $chan]] != -1} {
    set msg_temp $msg_greet($chan)
    foreach i $msg_temp {puthelp "NOTICE $nick :[subst $i]"}
    return 1
  } else {
  return 0
  }
} 
No lo he probado, pero debería funcionarte sin problemas.
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

You achieve that with lsearch.

Code: Select all

namespace eval greet {
	set greet(channels) "#tcl #help #mirc"
	set greet(message) "Welcome %nick to %chan, thanks for visit. To view rules type !rules"
	
	bind join - * [namespace current]::doGreet

	proc doGreet {nick uhost hand chan} {
		variable greet
		if {[isbotnick $nick]} return
		if {[lsearch -nocase $greet(channels) $chan] == -1} return
		set message [string map [list %nick $nick %chan $chan] $greet(message)]
		puthelp "NOTICE $nick :$message"
	}
}
Squeezed the 3 lines in just a single one cos are short.

@juanamores: Por que utilizar -exact y la string tolower cuando se puede ir directamente con -nocase?
Once the game is over, the king and the pawn go back in the same box.
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Post by Arnold_X-P »

very good .. thanks caesar :)

No funciono juan pero gracias por la ayuda :P
la tcl de caesar si funciona y esta perfecta :D
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Post by Arnold_X-P »

cesar is possible to change your tcl to work well

Code: Select all

set greet(message) {
"Welcome %nick to %chan, thanks for visit. To view rules type !rules"
"come back soon"
" bye bye... "
}
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

namespace eval greet {
	set greet(channels) "#tcl #help #mirc"
	set greet(messages) {
		"Welcome %nick to %chan, thanks for visit. To view rules type !rules"
		"come back soon"
		" bye bye... "
	}
	
	bind join - * [namespace current]::doGreet

	proc doGreet {nick uhost hand chan} {
		variable greet
		if {[isbotnick $nick]} return
		if {[lsearch $greet(channels) $chan] == -1} return
		foreach line  $greet(messages) {
			set message [string map [list %nick $nick %chan $chan] $line]
			puthelp "NOTICE $nick :$message"
		}
	}
}
Once the game is over, the king and the pawn go back in the same box.
User avatar
Get_A_Fix
Master
Posts: 206
Joined: Sat May 07, 2005 6:11 pm
Location: New Zealand

Post by Get_A_Fix »

I would probably use caesar's code, due to his expertise, but I did make something exactly like this a while back for someone. This uses a setudef (user defined setting), allowing you to enable/disable per channel.
This method allows for you to utilise $nick and $chan like normal, inside your message list.

Code: Select all

# $Id: greeter.tcl,v1.1 18/01/2016 06:20:47am GMT +12 (NZST) IRCSpeed Exp $

## SYNTAX:
# !greet on|off

# Feel free to edit this setting. Change the ! to any character you would like as a trigger.
set greettrig "!"

# Set here what flags you wish to allow to enable/disable this script. (change them to "-|-" for anyone)
set greetflags "ovf|ovf"

# Set here the greetings you wish to send each user that joins.
set mymsgs {
  "Hi, how are you?"
  "Hi $nick!"
  "Hello $nick, welcome to $chan"
  "Hi [$nick], you have to pay $20 to enter here"
}

### DONT EDIT BELOW ###
proc getTrig {} {
  global greettrig
  return $greettrig
}

setudef flag autogreet
 
bind join - * greet:msg
bind pub - ${greettrig}greet greet:pub

proc greet:msg {nick host hand chan} {
  global mymsgs
  if {[validuser [nick2hand $nick]] && ![channel get $chan autogreet]} {return}
  set greetmsg [lindex $mymsgs [rand [llength $mymsgs]]]
  set greetmsg [subst -nocommands $greetmsg]
  putserv "NOTICE $nick :$greetmsg"
}

proc greet:pub {nick uhost hand chan arg} {
  global greetflags
  if {[matchattr [nick2hand $nick] $greetflags $chan]} {
    if {[lindex [split $arg] 0] == ""} {putquick "PRIVMSG $chan :\037ERROR\037: Incorrect Parameters. \037SYNTAX\037: [getTrig]greets on|off"; return}

    if {[lindex [split $arg] 0] == "on"} {
      if {[channel get $chan autogreet]} {putquick "PRIVMSG $chan :\037ERROR\037: This setting is already enabled."; return}
      channel set $chan +autogreet
      puthelp "PRIVMSG $chan :Enabled Onjoin Greeter for $chan"
      savechannels
      return 0
    }

    if {[lindex [split $arg] 0] == "off"} {
      if {![channel get $chan autogreet]} {putquick "PRIVMSG $chan :\037ERROR\037: This setting is already disabled."; return}
      channel set $chan -autogreet
      puthelp "PRIVMSG $chan :Disabled Onjoin Greeter for $chan"
      savechannels
      return 0
    }
  }
}

putlog ".:greeter.tcl,v1.1:. Loaded!"
Last edited by Get_A_Fix on Sat Jul 09, 2016 12:56 pm, edited 1 time in total.
We explore.. and you call us criminals. We seek after knowledge.. and you call us criminals. We exist without skin color, without nationality, without religious bias.. and you call us criminals.
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

Post by juanamores »

caesar wrote: @juanamores: Por que utilizar -exact y la string tolower cuando se puede ir directamente con -nocase?
O sea, el -nocase sirve no sólo para minúsculas, sino también para comparar palabras exactas?
If you do not understand my ideas is because I can not think in English, I help me with Google Translate. I only speak Spanish. Bear with me. Thanks :)
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Si -nocase se especifica, entonces las cadenas se comparan de manera mayúsculas y minúsculas. :)
Once the game is over, the king and the pawn go back in the same box.
User avatar
Arnold_X-P
Master
Posts: 226
Joined: Mon Oct 30, 2006 12:19 am
Location: DALnet - Trinidad - Beni - Bolivia
Contact:

Post by Arnold_X-P »

thanks caesar & Get_A_Fix

your help is appreciated
thanks again......

gracias a ti tambien juanamores por tratar de ayudar, yo tambien hablo español, saludos cuate.

I also worked well

Code: Select all

set ayuda_chanxp "#tcl #help #mirc"

set mymsgs {
 "Welcome $nick to $chan, thanks for visit. To view rules type !rules"
      "come back soon"
      " bye bye... " 
} 

bind join - * greet:msg 
proc greet:msg {nick host hand chan} {
  global mymsgs ayuda_chanxp botnick
  if {(([lsearch -exact [string tolower $ayuda_chanxp] [string tolower $chan]] != -1)  || ($ayuda_chanxp == "")) && ($nick != $botnick)} {
foreach i $mymsgs {
	puthelp "NOTICE $nick :[subst $i]"
} } }
I also worked well

Code: Select all

set ayuda_chanxp "#tcl #help #mirc"

set mymsgs {
"Welcome %nick to %chan, thanks for visit. To view rules type !rules"
 "come back soon"
 " bye bye... " 
} 

bind join - * greet:msg 
proc greet:msg {nick host hand chan} {
  global mymsgs ayuda_chanxp botnick
 if {(([lsearch -exact [string tolower $ayuda_chanxp] [string tolower $chan]] != -1)  || ($ayuda_chanxp == "")) && ($nick != $botnick)} {
foreach line $mymsgs {
         set message [string map [list %nick $nick %chan $chan] $line]
         puthelp "NOTICE $nick :$message" 
		 } } }
Thanks again for the help
.:an ideal world:. www.geocities.ws/chateo/yo.htm
my programming place /server ix.scay.net:7005
Post Reply