funwar.tcl 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #!/usr/bin/tclsh
  2. # funwar script
  3. # have fun ;)
  4. package require sql
  5. # sql stuff:
  6. set funwar_sql_server "server.ip.add.ress"
  7. set funwar_sql_user "username"
  8. set funwar_sql_password "password"
  9. set funwar_sql_dbname_et "name of database"
  10. set funwar_sql_dbname_rtcw "name of database"
  11. set funwar_sql_tblname_et "name of table"
  12. set funwar_sql_tblname_rtcw "name of table"
  13. # where the bot should post funwars automatically:
  14. set funwar_channels_auto "#example #test"
  15. # how often should funwars be posted in the above specified channels?
  16. # bind time - "MIN HOUR DAY MONTH YEAR" funwar_auto
  17. # for example:
  18. # bind time - "20 * * * *" funwar auto
  19. # bind time - "50 * * * *" funwar auto
  20. # (posts at 20 and 50 minutes every hour/day/month/year)
  21. bind time - "20 * * * *" funwar_auto
  22. bind time - "50 * * * *" funwar_auto
  23. # which triggers should be used?
  24. set funwar_trigger_et "!et"
  25. set funwar_trigger_rtcw "!rtcw"
  26. set funwar_trigger_both "!funwars"
  27. # what should the output look like?
  28. set funwar_output_header "*** Funwars: ***"
  29. set funwar_output_header2 "Game: Date/Time: XonX: Clantag: IRC:"
  30. set funwar_output_footer "*** end of funwars list ***"
  31. #<don´t change>
  32. proc funwar_post {game id date time xonx clantag irc www server org chan } {
  33. #</don´t change>
  34. set funwar_output_body "$game $date $xonx $clantag $irc"
  35. #<don´t change>
  36. puthelp "PRIVMSG $chan :$funwar_output_body"
  37. }
  38. #</don´t change>
  39. # you shouldn´t change anything below except your really want to modify something!!!
  40. global funwar_sql_server
  41. global funwar_sql_user
  42. global funwar_sql_passwd
  43. global funwar_sql_dbname_et
  44. global funwar_sql_dbname_rtcw
  45. global funwar_sql_tblname_et
  46. global funwar_sql_tblname_rtcw
  47. global funwar_output_header
  48. global funwar_output_header2
  49. global funwar_output_footer
  50. global funwar_channels_auto
  51. proc funwar_sql_parsedb { server user password dbname tblname order chan game limit command} {
  52. global funwar_output_header
  53. global funwar_output_header2
  54. global funwar_output_footer
  55. set counter "1"
  56. set conn [ sql connect $server $user $password ]
  57. set res [ catch { sql selectdb $conn $dbname } msg ]
  58. if { $res != 0 } {
  59. puthelp "PRIVMSG $chan :Sorry, could not select the database '$dbname': $msg"
  60. }
  61. set res [ sql query $conn "select id,date,time,xonx,clantag,irc,www,server,org from $tblname order by $order desc" ]
  62. if { $res != 0 } {
  63. if { $command != "noheader" } {
  64. if { [llength $chan] == 1 } {
  65. puthelp "PRIVMSG $chan :$funwar_output_header"
  66. puthelp "PRIVMSG $chan :$funwar_output_header2"
  67. } else {
  68. foreach channel $chan {
  69. puthelp "PRIVMSG $channel :$funwar_output_header"
  70. puthelp "PRIVMSG $channel :$funwar_output_header2"
  71. }
  72. }
  73. }
  74. while { [ set row [ sql fetchrow $conn ] ] != "" } {
  75. set id [lindex $row 0]
  76. set date [lindex $row 1]
  77. set time [lindex $row 2]
  78. set xonx [lindex $row 3]
  79. set clantag [lindex $row 4]
  80. set irc [lindex $row 5]
  81. set www [lindex $row 6]
  82. set server [lindex $row 7]
  83. set org [lindex $row 8]
  84. if { $counter <= $limit } {
  85. if { [llength $chan] == 1 } {
  86. funwar_post $game $id $date $time $xonx $clantag $irc $www $server $org $chan
  87. } else {
  88. foreach channel $chan {
  89. funwar_post $game $id $date $time $xonx $clantag $irc $www $server $org $channel
  90. }
  91. }
  92. }
  93. incr counter
  94. }
  95. if { $command != "nofooter" } {
  96. if { [llength $chan] == 1 } {
  97. puthelp "PRIVMSG $chan :$funwar_output_footer"
  98. } else {
  99. foreach channel $chan {
  100. puthelp "PRIVMSG $channel :$funwar_output_footer"
  101. }
  102. }
  103. }
  104. }
  105. sql endquery $conn
  106. sql disconnect $conn
  107. }
  108. proc funwar_rtcw { nick host hand chan arg } {
  109. global funwar_sql_server
  110. global funwar_sql_user
  111. global funwar_sql_password
  112. global funwar_sql_dbname_rtcw
  113. global funwar_sql_tblname_rtcw
  114. set order "id"
  115. set game "RTCW"
  116. set limit "10"
  117. set command ""
  118. funwar_sql_parsedb $funwar_sql_server $funwar_sql_user $funwar_sql_password $funwar_sql_dbname_rtcw $funwar_sql_tblname_rtcw $order $chan $game $limit $command
  119. }
  120. proc funwar_et { nick host hand chan arg } {
  121. global funwar_sql_server
  122. global funwar_sql_user
  123. global funwar_sql_password
  124. global funwar_sql_dbname_et
  125. global funwar_sql_tblname_et
  126. set order "id"
  127. set game "ET"
  128. set limit "10"
  129. set command ""
  130. funwar_sql_parsedb $funwar_sql_server $funwar_sql_user $funwar_sql_password $funwar_sql_dbname_et $funwar_sql_tblname_et $order $chan $game $limit $command
  131. }
  132. proc funwar_both { nick host hand chan arg } {
  133. global funwar_sql_server
  134. global funwar_sql_user
  135. global funwar_sql_password
  136. global funwar_sql_dbname_rtcw
  137. global funwar_sql_tblname_rtcw
  138. global funwar_sql_dbname_et
  139. global funwar_sql_tblname_et
  140. set order "id"
  141. set game "RTCW"
  142. set limit "3"
  143. set command "nofooter"
  144. funwar_sql_parsedb $funwar_sql_server $funwar_sql_user $funwar_sql_password $funwar_sql_dbname_rtcw $funwar_sql_tblname_rtcw $order $chan $game $limit $command
  145. set game "ET"
  146. set command "noheader"
  147. funwar_sql_parsedb $funwar_sql_server $funwar_sql_user $funwar_sql_password $funwar_sql_dbname_et $funwar_sql_tblname_et $order $chan $game $limit $command
  148. }
  149. proc funwar_auto { min hour day month year } {
  150. global funwar_channels_auto
  151. global funwar_sql_server
  152. global funwar_sql_user
  153. global funwar_sql_password
  154. global funwar_sql_dbname_rtcw
  155. global funwar_sql_tblname_rtcw
  156. global funwar_sql_dbname_et
  157. global funwar_sql_tblname_et
  158. global funwar_channels_auto
  159. set order "id"
  160. set game "RTCW"
  161. set limit "3"
  162. set command "nofooter"
  163. funwar_sql_parsedb $funwar_sql_server $funwar_sql_user $funwar_sql_password $funwar_sql_dbname_rtcw $funwar_sql_tblname_rtcw $order $funwar_channels_auto $game $limit $command
  164. set game "ET"
  165. set command "noheader"
  166. funwar_sql_parsedb $funwar_sql_server $funwar_sql_user $funwar_sql_password $funwar_sql_dbname_et $funwar_sql_tblname_et $order $funwar_channels_auto $game $limit $command
  167. }
  168. bind pub - $funwar_trigger_et funwar_et
  169. bind pub - $funwar_trigger_rtcw funwar_rtcw
  170. bind pub - $funwar_trigger_both funwar_both
  171. putlog "Loaded funwars.tcl"