Răsfoiți Sursa

add tcl scripts

Add a couple of tcl scripts.

Signed-off-by: hwipl <33433250+hwipl@users.noreply.github.com>
hwipl 6 ani în urmă
părinte
comite
b4169f29a3
7 a modificat fișierele cu 248 adăugiri și 0 ștergeri
  1. 11 0
      beer.tcl
  2. 16 0
      date.tcl
  3. 10 0
      greetings.tcl
  4. 8 0
      host.tcl
  5. 25 0
      insult.tcl
  6. 61 0
      maketiny.tcl
  7. 117 0
      match.tcl

+ 11 - 0
beer.tcl

@@ -0,0 +1,11 @@
+# beer.tcl
+
+proc give_beer { nick host hand chan arg } {
+	if { $arg == "" } {
+	puthelp "PRIVMSG $chan :\001ACTION gives $nick an ice cold beer."
+	} else {
+	puthelp "PRIVMSG $chan :\001ACTION gives [lindex $arg 0] an ice cold beer."
+	}
+}
+
+bind pub - !beer give_beer

+ 16 - 0
date.tcl

@@ -0,0 +1,16 @@
+# date.tcl
+#set date "/usr/bin/date"
+
+#global date
+
+#proc show_date { nick host hand chan arg } {
+#	puthelp "PRIVMSG $chan :[clock format [clock seconds]]"
+#}
+#bind pub - !date show_date
+
+
+proc show_date { nick host hand chan arg } {
+	set date_format "%a %b %d %H:%M:%S %Z %Y"
+	puthelp "PRIVMSG $chan :[clock format [clock seconds] -format $date_format]"
+}
+bind pub - !date show_date

+ 10 - 0
greetings.tcl

@@ -0,0 +1,10 @@
+# greetings tcl
+
+bind join - * join_greeting
+
+proc join_greeting { nick host hand chan } {
+	set $greetInChannel ""
+	if { [lsearch $greetInChannel $chan] != "-1" } {
+	puthelp "NOTICE $nick :Hi ${nick}!"
+	}
+}

+ 8 - 0
host.tcl

@@ -0,0 +1,8 @@
+# host.tcl
+
+proc host_lookup { nick host hand chan arg } {
+	set output [exec host [lindex $arg 0]]
+	puthelp "PRIVMSG $chan :[lrange $output 0 end]"
+}
+
+bind pub - !host host_lookup

+ 25 - 0
insult.tcl

@@ -0,0 +1,25 @@
+#!/usr/bin/tcl
+#
+# insult script, connects to insulthost.colorado.edu:1695
+# and gets an insult
+#
+#
+# set hostname or IP and port:
+proc pub_insult { nick host hand chan arg } {
+
+set insulthost "insulthost.colorado.edu"
+set insultport "1695"
+set insultnick [lindex $arg 0]
+
+# open socket, get insult message, close socket and
+# output the message::
+
+set s [socket -async $insulthost $insultport]
+set insult [gets $s]
+puthelp "PRIVMSG $chan :$insultnick: $insult"
+#after 500
+close $s
+
+}
+
+bind pub - !insult pub_insult

+ 61 - 0
maketiny.tcl

@@ -0,0 +1,61 @@
+# cheap tinyurl script to convert ling urls into short urls
+# using http://tinyurl.com´s service
+
+proc tinyurl_convert {nick host hand chan argv} {
+
+# set variables
+
+set url [lindex $argv 0]
+set command "|wget --quiet --output-document=- http://tinyurl.com/create.php?url=$url"
+
+# check if there are enough arguments
+
+if { [llength $argv] == 0 } {
+	puthelp "PRIVMSG $nick :Usage: !tinyurl <url>  || Example: !tinyurl http://www.google.com"
+} else {
+
+# open command to create tinyurl and retrieve the html document returned by tinyurl
+
+if ![catch {open $command r} input] {
+	while {[gets $input line] >= 0} {
+		
+		# regexp to extract the right part of the html file and the get the tiny url
+		# output tiny url
+		
+		if [regexp {<input type=hidden name=tinyurl value=\"(.*)\">} $line match tinyurl] {
+				puthelp "PRIVMSG $chan :$tinyurl"
+		}
+		
+	}
+	close $input
+}
+}
+}
+proc tinyurl_tinylast {nick host hand chan argv} {
+	set urlhistory "url_history_$chan"
+	if ![catch {open $urlhistory r} input] {
+		while {[gets $input line] >= 0} {
+			set url $line
+		}
+		close $input
+		tinyurl_convert $nick $host $hand $chan $url
+	}
+}
+
+proc tinyurl_urlhistory {nick host hand chan argv} {
+	set urlhistory "url_history_$chan"
+	
+	if {[regexp {(http://\S*)} $argv match url] != 0} {
+		if ![catch {open $urlhistory w} output] {
+			puts $output $url
+			close $output
+		}
+	}
+}
+
+
+# bind channel command
+
+bind pub - !tinyurl tinyurl_convert
+bind pub - !tinylast tinyurl_tinylast
+bind pubm - * tinyurl_urlhistory

+ 117 - 0
match.tcl

@@ -0,0 +1,117 @@
+###################################################################
+#
+# match.tcl
+#
+# This script was originally created to save clan matches in a file,
+# to show all the saved matches and to be able to remove them from
+# the file again.
+#
+# HOW TO USE THIS SCRIPT:
+#
+# !add_match      is used to add matches to the file/list.
+# !show_matches   is used to show the saved matches.
+# !del_match      is used to remove a match from the file/list.
+#                 You have to use the match number as an argument.
+#                 If you delte a match and there are more matches
+#                 after it in the list, all the remaining matches'
+#                 numbers will be decreased by 1.
+#
+# Of course, all those commands can be changed in the config
+# section below.
+#
+# CONFIG:
+#
+# Here you can change some global variables. You can change the
+# name and/or path of the file you want to store the matches in
+# and its backup file.
+
+set match_filename "matches.lst" ;#channel name will be appended to file
+set match_filenamebak "matches.lst.bak"
+set match_channels "#example #test" ;#USE LOWER CASE!
+# Here you can change the command names to something you like more.
+
+set match_addcommand "!addmatch"
+set match_delcommand "!delmatch"
+set match_showcommand "!searchmatch"
+
+# END OF CONFIG
+####################################################################
+
+global match_filename
+global match_filenamebak
+global match_channels
+
+# this procedure shows the saved matches:
+proc show_matches {nick host hand chan arg} {
+	global match_filename
+	global match_channels
+	if { [lsearch $match_channels [string tolower $chan]] != -1 } {
+	set file ${chan}.${match_filename}
+	if {[file exists $file]} {
+	if {[file size $file] > 0} {
+	if ![catch {open $file r} input] {
+	while {[gets $input line] >= 0} {
+		lappend matches $line
+	}
+	close $input
+	putserv "PRIVMSG $chan :*** MatchList ***"
+	for { set i 0 } { $i < [llength $matches] } { incr i } {
+	putserv "PRIVMSG $chan :([expr $i +1])  [lindex $matches $i]"
+#	putlog "match.tcl: $nick@$chan attempted to view match list"
+	}
+	putserv "PRIVMSG $chan :*** End of MatchList ***"
+	} else { putserv "PRIVMSG $nick :Error opening file: $input" }
+	} else { putserv "PRIVMSG $chan :No matches have been added yet..."}
+	} else { putserv "PRIVMSG $chan :No matches have been added yet..."}
+	}
+}
+
+# this procedure deletes saved matches:
+proc del_match {nick host hand chan arg} {
+	global match_filename
+	global match_filenamebak
+	global match_channels
+	if { [lsearch $match_channels [string tolower $chan]] != -1 } {
+	set file ${chan}.${match_filename}
+	set filebak ${chan}.${match_filenamebak}
+	if {[file exists $file]} {
+	if {[file size $file] > 0} {
+	if ![catch {open $file r} input] {
+	while {[gets $input line] >= 0} {
+		lappend matches $line
+	}
+	close $input
+	file copy -force $file $filebak
+	if ![catch {open $file w} output] {
+	for { set i 0 } { $i < [llength $matches] } { incr i } {
+	if {[expr $i +1] != $arg} { puts $output "[lindex $matches $i]" }
+	}
+	close $output
+	putserv "NOTICE $nick :Match number $arg is now deleted."
+	putlog "match.tcl: $nick@$chan attempted to delete match number $arg."
+	} else { putserv "PRIVMSG $nick :Error opening file: $input" }
+	} else { putserv "PRIVMSG $nick :Error opening file: $input" }
+	} else { putserv "PRIVMSG $nick :Can't delete matches that don't exist..." }
+	} else { putserv "PRIVMSG $nick :Can't delete matches that don't exist..." }
+	}
+}
+
+# this procedure adds matches to the list:
+proc add_match {nick host hand chan arg} {
+	global match_filename
+	global match_channels
+	if { [lsearch $match_channels [string tolower $chan]] != -1 } {
+	set file ${chan}.${match_filename}
+	if ![catch {open $file a} output] {
+	puts $output "$nick:  $arg"
+	close $output
+	putserv "NOTICE $nick :Congrats, your Match has been added."
+	putlog "match.tcl: $nick@$chan attempted to add a match to the list"
+	} else { putserv "PRIVMSG $nick :Error opening file: $input" }
+	}
+}
+
+# binds to call the procedures:
+bind pub - $match_showcommand show_matches
+bind pub - $match_addcommand add_match
+bind pub o|o $match_delcommand del_match