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.

BIND PUB and BIND MSGM args

Help for those learning Tcl or writing their own scripts.
Post Reply
j
juanamores
Master
Posts: 317
Joined: Sun Mar 15, 2015 9:59 am

BIND PUB and BIND MSGM args

Post by juanamores »

I have a code that lists the help commands the bot.
To execute the command channel (for full list commands) is:
!commands
To execute the command channel (for full particular command) is:
!commands <command>
For private messages is (for full list commands) :
commands
But, not works for messages:
commands <command>


How do you, for boT interpret the event MSGM arguments after the command text?
Just accept me the command without arguments, that is, the command that displays a list of available commands of the bot, but does not allow me to show support for a particular command, running the SWITCH command .

Example of part code (the commands list is very long to put it all):

Code: Select all

##default prefix !, You can replace it##
set prefix "!"
set canal_radio #chann1 
set canal_djs #chann2
set canal_admin #chann3

bind pub oa|n [string trim $prefix]commands pub:help
bind msgm oa|n commands pub:help

proc pub:help {nick uhost hand chan args} {
	global botnick prefix canal_admin canal_djs
	set args [split [cleanarg $args]]
	if {(![matchattr $nick a|n]) && ([matchattr $nick +o])} {
	if {[llength $args]<1} {
putmsg $nick "Commands list for Administrators"
putmsg $nick [encoding convertfrom utf-8 " - [string trim $prefix]comm1 - task xxx perform "]
putmsg $nick [encoding convertfrom utf-8 " - [string trim $prefix]comm2 - task xxx perform "]
putmsg $nick [encoding convertfrom utf-8 " - [string trim $prefix]comm3 - task xxx perform "]
### ....More help command.............###
} else {
if {[string index $args 0] == "$prefix"} { set args [string trimleft $args $prefix] }
set lines [comm1 comm2 comm3]
if {([lsearch -exact [string tolower $lines] $args] == -1)} { putmsg $chan "$nick Sorry I have no help for that command. \002$args.";return } 	
	switch [lindex $args 0] {
	"comm1" {
putmsg $nick "\002\0036<===--- !comm1 ---===>\0036\002"
putmsg $nick "Usage: [string trim $prefix]comm1 <nick Dj>"
putmsg $nick "Usage channels: $canal_admin and $canal_djs"
putmsg $nick [encoding convertfrom utf-8 "Function: xxxxxxx"]
putmsg $nick "\002\0036<===--- End help comannd !comm1 ---===>\0036\002"
	}
"comm2" {
putmsg $nick "\002\0036<===--- !comm2 ---===>\0036\002"
putmsg $nick "Usage: [string trim $prefix]comm2 <#channel>"
putmsg $nick "Usage channels: $canal_admin and $canal_djs"
putmsg $nick [encoding convertfrom utf-8 "Function: xxxxxxx"]
putmsg $nick "\002\0036<===--- End help comannd !comm2 ---===>\0036\002"
	}
"comm3" {
putmsg $nick "\002\0036<===--- !comm3 ---===>\0036\002"
putmsg $nick "Usage: [string trim $prefix]comm3 <nick>"
putmsg $nick "Usage channels: $canal_admin and"
putmsg $nick [encoding convertfrom utf-8 "Function: xxxxxxx"]
putmsg $nick "\002\0036<===--- End help comannd !comm3 ---===>\0036\002"
	}
}
}
} else {
if {[llength $args]<1} {
putmsg $nick "Commands list for Roots"
putmsg $nick [encoding convertfrom utf-8 " - [string trim $prefix]comm1 - task xxx perform "]
putmsg $nick [encoding convertfrom utf-8 " - [string trim $prefix]comm2 - task xxx perform "]
putmsg $nick [encoding convertfrom utf-8 " - [string trim $prefix]comm3 - task xxx perform "]
### ....More help command.............###
} else {
if {[string index $args 0] == "$prefix"} { set args [string trimleft $args $prefix] }
set lines [comm1 comm2 comm3]
if {([lsearch -exact [string tolower $lines] $args] == -1)} { putmsg $chan "$nick Sorry I have no help for that command. \002$args.";return } 	
	switch [lindex $args 0] {
	"comm1" {
putmsg $nick "\002\0036<===--- !comm1 ---===>\0036\002"
putmsg $nick "Usage: [string trim $prefix]comm1 <nick Dj>"
putmsg $nick "Usage channels: $canal_admin and $canal_djs"
putmsg $nick [encoding convertfrom utf-8 "Function: xxxxxxx"]
putmsg $nick "\002\0036<===--- End help comannd !comm1 ---===>\0036\002"
	}
"comm2" {
putmsg $nick "\002\0036<===--- !comm2 ---===>\0036\002"
putmsg $nick "Usage: [string trim $prefix]comm2 <#channel>"
putmsg $nick "Usage channels: $canal_admin and $canal_djs"
putmsg $nick [encoding convertfrom utf-8 "Function: xxxxxxx"]
putmsg $nick "\002\0036<===--- End help comannd !comm2 ---===>\0036\002"
	}
"comm3" {
putmsg $nick "\002\0036<===--- !comm3 ---===>\0036\002"
putmsg $nick "Usage: [string trim $prefix]comm3 <nick>"
putmsg $nick "Usage channels: $canal_admin and"
putmsg $nick [encoding convertfrom utf-8 "Function: xxxxxxx"]
putmsg $nick "\002\0036<===--- End help comannd !comm3 ---===>\0036\002"
	}
}
}

}
}

proc cleanarg {arg} {
 set temp ""
	for {set i 0} {$i < [string length $arg]} {incr i} {
  set char [string index $arg $i]
  if {($char != "\12") && ($char != "\15")} {
   append temp $char
  }
 }

 set temp [string trimright $temp "\}"]

 set temp [string trimleft $temp "\{"]
	return $temp
}
EDIT: Add to end processes that I forgot to put code before.
EDIT2: Translate variable name 'prefijo' to English 'prefix'.
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 :)
Post Reply