match.tcl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ###################################################################
  2. #
  3. # match.tcl
  4. #
  5. # This script was originally created to save clan matches in a file,
  6. # to show all the saved matches and to be able to remove them from
  7. # the file again.
  8. #
  9. # HOW TO USE THIS SCRIPT:
  10. #
  11. # !add_match is used to add matches to the file/list.
  12. # !show_matches is used to show the saved matches.
  13. # !del_match is used to remove a match from the file/list.
  14. # You have to use the match number as an argument.
  15. # If you delte a match and there are more matches
  16. # after it in the list, all the remaining matches'
  17. # numbers will be decreased by 1.
  18. #
  19. # Of course, all those commands can be changed in the config
  20. # section below.
  21. #
  22. # CONFIG:
  23. #
  24. # Here you can change some global variables. You can change the
  25. # name and/or path of the file you want to store the matches in
  26. # and its backup file.
  27. set match_filename "matches.lst" ;#channel name will be appended to file
  28. set match_filenamebak "matches.lst.bak"
  29. set match_channels "#example #test" ;#USE LOWER CASE!
  30. # Here you can change the command names to something you like more.
  31. set match_addcommand "!addmatch"
  32. set match_delcommand "!delmatch"
  33. set match_showcommand "!searchmatch"
  34. # END OF CONFIG
  35. ####################################################################
  36. global match_filename
  37. global match_filenamebak
  38. global match_channels
  39. # this procedure shows the saved matches:
  40. proc show_matches {nick host hand chan arg} {
  41. global match_filename
  42. global match_channels
  43. if { [lsearch $match_channels [string tolower $chan]] != -1 } {
  44. set file ${chan}.${match_filename}
  45. if {[file exists $file]} {
  46. if {[file size $file] > 0} {
  47. if ![catch {open $file r} input] {
  48. while {[gets $input line] >= 0} {
  49. lappend matches $line
  50. }
  51. close $input
  52. putserv "PRIVMSG $chan :*** MatchList ***"
  53. for { set i 0 } { $i < [llength $matches] } { incr i } {
  54. putserv "PRIVMSG $chan :([expr $i +1]) [lindex $matches $i]"
  55. # putlog "match.tcl: $nick@$chan attempted to view match list"
  56. }
  57. putserv "PRIVMSG $chan :*** End of MatchList ***"
  58. } else { putserv "PRIVMSG $nick :Error opening file: $input" }
  59. } else { putserv "PRIVMSG $chan :No matches have been added yet..."}
  60. } else { putserv "PRIVMSG $chan :No matches have been added yet..."}
  61. }
  62. }
  63. # this procedure deletes saved matches:
  64. proc del_match {nick host hand chan arg} {
  65. global match_filename
  66. global match_filenamebak
  67. global match_channels
  68. if { [lsearch $match_channels [string tolower $chan]] != -1 } {
  69. set file ${chan}.${match_filename}
  70. set filebak ${chan}.${match_filenamebak}
  71. if {[file exists $file]} {
  72. if {[file size $file] > 0} {
  73. if ![catch {open $file r} input] {
  74. while {[gets $input line] >= 0} {
  75. lappend matches $line
  76. }
  77. close $input
  78. file copy -force $file $filebak
  79. if ![catch {open $file w} output] {
  80. for { set i 0 } { $i < [llength $matches] } { incr i } {
  81. if {[expr $i +1] != $arg} { puts $output "[lindex $matches $i]" }
  82. }
  83. close $output
  84. putserv "NOTICE $nick :Match number $arg is now deleted."
  85. putlog "match.tcl: $nick@$chan attempted to delete match number $arg."
  86. } else { putserv "PRIVMSG $nick :Error opening file: $input" }
  87. } else { putserv "PRIVMSG $nick :Error opening file: $input" }
  88. } else { putserv "PRIVMSG $nick :Can't delete matches that don't exist..." }
  89. } else { putserv "PRIVMSG $nick :Can't delete matches that don't exist..." }
  90. }
  91. }
  92. # this procedure adds matches to the list:
  93. proc add_match {nick host hand chan arg} {
  94. global match_filename
  95. global match_channels
  96. if { [lsearch $match_channels [string tolower $chan]] != -1 } {
  97. set file ${chan}.${match_filename}
  98. if ![catch {open $file a} output] {
  99. puts $output "$nick: $arg"
  100. close $output
  101. putserv "NOTICE $nick :Congrats, your Match has been added."
  102. putlog "match.tcl: $nick@$chan attempted to add a match to the list"
  103. } else { putserv "PRIVMSG $nick :Error opening file: $input" }
  104. }
  105. }
  106. # binds to call the procedures:
  107. bind pub - $match_showcommand show_matches
  108. bind pub - $match_addcommand add_match
  109. bind pub o|o $match_delcommand del_match