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.

Nick specific onjoin greetings.

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Nick specific onjoin greetings.

Post by SpiKe^^ »

This script is in reply to a script request from 2 days ago.

That request was deleted, but not before the script was almost done:)

Code: Select all

###################################################################
## SayGreet  ver. 0.1  by SpiKe^^           www.mytclscripts.com ##
###################################################################

##################################################### 06/01/2019 ##
#                                                                 #
# onjoin greeting script, with nick and/or chan specific greets.  #
#                                                                 #
# You Must create the file with all available greeting messages!  #
# Each greeting message goes on its own file line.                #
# The order of the lines doesn't matter. Blank lines are ignored. #
# If the script finds multiple valid greets, picks one randomly.  #
#                                                                 #
# -Example- adding 2 script default greeting messages.            #
#  Welcome to %c% : Stay & Play some Trivia with us.              #
#  Welcome to %c% : Use .triv to start the Trivia game.           #
#                                                                 #
# You can also set Nick and/or Chan Specific greeting messages.   #
# -Example- adding 2 nick specific greetings (both same nick).    #
#  Houdini :: Welcome back %n% : Behave yourself:)                #
#  houdini :: The king has returned. Welcome back %n%             #
# -Example- adding 2 channel specific default greetings.          #
#  #lamechat :: [%n%] Don't be Lame. Say something witty.         #
#  #lameChat :: Welcome to %c% %n% : Don't be Lame:)              #
# -Example- adding 2 nick and channel specific greetings.         #
#  houdini@#trivial :: The king has returned. Top trivia champ!   #
#  houdini@#Trivial :: Welcome back %n% : 99583 Points Last week! #
#                                                                 #
###################################################################

namespace eval saygreet { variable greet
#######################################################
## - Begin Script Settings - Begin Script Settings - ##
#######################################################

#  Set the channel(s) to run this script in.  #
set greet(chans) ""   ;#   ("" = all channels)  #

#  Set the route/file.name to the greetings file.  #
set greet(file) "scripts/greets.txt"

#  Set the file line divider between nick/chan and the message.  #
#  Use any string that will Never be in a greeting message.  #
set greet(fdiv) "::"

#  1 = Send greets by message  #  2 = Send greets by notice  #
set greet(how) "1"

#  1 = Send greets to channel  #  2 = Send greets to nick  #
set greet(who) "1"

#  Prefix all greetings with the users nick??  (1+=yes 0=no)  #
#  1 = Prefix all greetings with users nick.  #
#  2 = Add users nick Only if no %n% in the greet message.  #
set greet(unick) "2"


#######################################################
#### - End Script Settings - End Script Settings - ####
#######################################################

bind join - * [namespace current]::saygreet

set greet(chans) [string trim $greet(chans)]
if {$greet(chans) eq "" || $greet(chans) eq "*"} { set greet(_chans) ""
} else {  set greet(_chans) [split [string tolower $greet(chans)]]  }

if {$greet(how) ne "2"} {  set greet(how) 1  }
if {$greet(who) ne "2"} {  set greet(who) 1  }
if {$greet(unick) ni {0 1}} {  set greet(unick) 2  }

proc saygreet {nk uh hn ch} {  variable greet
  set que "puthelp"
  set nklo [string tolower $nk]  ;  set chlo [string tolower $ch]

  if {$greet(_chans) ne "" && [lsearch -exact $greet(_chans) $chlo]<0} {
    return 0
  }
  if {[isbotnick $nk] || ![file exists $greet(file)]} {  return 0  }

  set open [open $greet(file) r]
  set greets [split [string trim [read $open]] \n]
  close $open
  set defls "" ;  set cdefls "" ;  set sayls "" ;  set csayls ""
  set divider $greet(fdiv)

  foreach gr $greets {  set gr [string trim $gr]
    if {$gr eq ""} {  continue  }
    set rest [join [lassign [split $gr] nkch div]]
    set nkch [string tolower $nkch]
    if {$div eq $divider} {
      if {$nkch eq "!def" || $nkch eq "!default"} {
        lappend defls $rest
      } elseif {[string match "*,${nklo}@${chlo},*" ",${nkch},"]} {
        lappend csayls $rest
      } elseif {[string match "*,${nklo},*" ",${nkch},"]} {
        lappend sayls $rest
      } elseif {[string match "*,${chlo},*" ",${nkch},"]} {
        lappend cdefls $rest
      } elseif {[string match "*,@${chlo},*" ",${nkch},"]} {
        lappend cdefls $rest
      }
    } elseif {$nkch eq $divider} {
      lappend defls "$div $rest"
    } else {  lappend defls $gr  }
  }

  if {$csayls ne ""} {  set gotls $csayls
  } elseif {$sayls ne ""} {  set gotls $sayls
  } elseif {$cdefls ne ""} {  set gotls $cdefls
  } elseif {$defls ne ""} {  set gotls $defls
  } else {  set gotls ""  }
  if {$gotls eq ""} {  return 0  }

  set got [lindex $gotls [rand [llength $gotls]]]
  set say [string map [list %n% $nk %c% $ch] $got]
  if {$greet(unick)==2 && ![string match "*%n%*" $got]} {
    set say "$nk : $say"
  } elseif {$greet(unick)==1} {  set say "$nk : $say"  }

  if {$greet(how)==2} { set how "NOTICE" } else { set how "PRIVMSG" }
  if {$greet(who)==2} {  set who $nk  } else {  set who $ch  }

  $que "$how $who :$say"
}

putlog "SayGreet ver. 0.1 Loaded."
} ;## - End namespace eval - ##

SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
m4s
Halfop
Posts: 97
Joined: Mon Jan 30, 2017 3:24 pm

Re: Nick specific onjoin greetings.

Post by m4s »

SpiKe^^ wrote:This script is in reply to a script request from 2 days ago.

That request was deleted, but not before the script was almost done:)
Hello!

Thanks the script works! :)

May I have a request?
I would like to see the names (%n%) and channels (%c%) to be bold in the greetings.

Example:
Configuration in the file: Houdini :: Welcome back %n% : Behave yourself:)
Bot says: Welcome back Houdini : Behave yourself:)

Thank You! :)
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Try replace this line...

Code: Select all

set say [string map [list %n% $nk %c% $ch] $got]
with this edited line...

Code: Select all

set say [string map [list %n% \002$nk\002 %c% \002$ch\002] $got]
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
User avatar
m4s
Halfop
Posts: 97
Joined: Mon Jan 30, 2017 3:24 pm

Post by m4s »

Hello SpiKe^^!

Thanks, it's super! Everything works! :) Have a nice day! :)
Post Reply