moxquizz update (german)


/ Published in: TCL
Save to your folder(s)

here is a little update for the popular moxquizz script for eggdrop i wrote

you can download the script here: http://moxquiz.bplaced.net/homepage/?seite=download

an also see a list of the new features there


Copy this code and paste it in your HTML
  1. ##
  2. ### moxquizz.tcl -- quizzbot for eggdrop 1.6.9+
  3. ##
  4. ### Author: Moxon <[email protected]> (AKA Sascha Lüdecke)
  5. ##
  6. ### Credits:
  7. ## - Artwork was done with heavy support of Michee <[email protected]>
  8. ## - Julika loved to discuss and suggested many things.
  9. ## - Imran Ghory provided more than 600 english questions.
  10. ## - Questions have been edited by Michee, Julika, Tobac, Imran and
  11. ## Klinikai_Eset
  12. ## - ManInBlack for supplemental scripting
  13. ## - numerous others, see the README for a more complete list.
  14. ## If you are missing, please tell me!
  15. ##
  16. ### Copyright (C) 2000 Moxon AKA Sascha Lüdecke
  17. ##
  18. ## This program is free software; you can redistribute it and/or modify
  19. ## it under the terms of the GNU General Public License as published by
  20. ## the Free Software Foundation; either version 2 of the License, or
  21. ## (at your option) any later version.
  22. ##
  23. ## This program is distributed in the hope that it will be useful,
  24. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. ## GNU General Public License for more details.
  27. ##
  28. ## You should have received a copy of the GNU General Public License
  29. ## along with this program; if not, write to the Free Software
  30. ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  31. ##
  32. ###
  33. ## $Id: moxquizz.tcl,v 1.175 2002/07/05 19:21:26 chat Exp $
  34.  
  35.  
  36. ###########################################################################
  37. ###########################################################################
  38. ###########################################################################
  39.  
  40. ########################
  41. ### typ's mod config ###
  42. ########################
  43.  
  44. #Wieviel Sekunden sollen Schätzfragen offen sein?
  45. set schaetztime 15
  46.  
  47. #Soll !vok erlaubt sein? (1=ja,2=nein)
  48. set allow_vok 1
  49.  
  50. #Soll !halt erlaubt sein? (1=ja,2=nein)
  51. set allow_halt 1
  52.  
  53. #Soll das Anti-Highlighting aktiviert sein? (1=ja,2=nein)
  54. set allow_antihl 1
  55.  
  56. #Soll das gelbe Design aktiviert sein? (1=ja,2=nein)
  57. set go_yellow 0
  58.  
  59. #Sollen statistische Daten im Web veröffentlicht werden? (1=ja,2=nein)
  60. set allow_web 1
  61.  
  62. #Sollen Zeitrekorde gespeichert werden? (1=ja,2=nein)
  63. set allow_rec 1
  64.  
  65. #Soll der Bot jeden Tag einmal neu starten? (1=ja,2=nein)
  66. set daily_restart 0
  67.  
  68. ########################
  69. ### typ's mod info ###
  70. ########################
  71.  
  72. # 1. Schätzfragen
  73. # Schätzfragen müssen als Kategorie "Category: Schätzfragen" haben, ansonsten werden sie wie normale Quizfragen behandelt.
  74. # Die Antworten dürfen lediglich aus arabischen Zahlen (ohne Trennpunkte) sein.
  75.  
  76. # 2. Ratefragen
  77. # Ratefragen müssen als Kategorie "Category: Ratefragen" haben, ansonsten werden sie wie normale Quizfragen behandelt.
  78. # Die Antworten müssen folgendes Format haben: Antwort1*Antwort2*Antwort3
  79. # Das Ratefragen-Script basiert auf dem KAOS-Script von Mark A. Day.
  80.  
  81. # 3. A/M
  82. # A/M steht für Anschläge pro Minute
  83.  
  84. # 4. Web-Statistiken
  85. # Soweit von Dir erlaubt, sendet der QuizBot informationen an http://moxquiz.bplaced.net/homepage/
  86.  
  87. # 5. Support
  88. # Support gibt es im MoxQuizz-Forum unter http://www.moxquizz.de/forum oder im #quiz.de @ irc.gamesurge.net
  89.  
  90.  
  91. ########################
  92. ### new commands ###
  93. ########################
  94.  
  95. #!vok - Zeigt die Antwort ohne Vokale
  96. #!halt - Hält den Bot an
  97.  
  98. #!alltimes - Zeigt die ewige Rangliste an
  99.  
  100. #!server - Zeigt den Server, zu dem der Bot verbunden ist
  101. #!time - Zeigt Deine Spieldauer
  102.  
  103. #!rehash - OPs only
  104. #!restart - OPs only
  105.  
  106.  
  107. ###########################################################################
  108. ###########################################################################
  109. ###########################################################################
  110.  
  111.  
  112. ## Version:
  113. set version_moxquizz "0.8.1 {type:mod von http://moxquiz.bplaced.net/homepage/}"
  114.  
  115. package require msgcat
  116. package require http
  117.  
  118. namespace import -force msgcat::*
  119.  
  120. ###########################################################################
  121. ##
  122. ## ATTENTION:
  123. ##
  124. ## Defaults for bot configuration. Don't edit here, edit the file
  125. ## moxquizz.rc instead!
  126. ##
  127. ###########################################################################
  128.  
  129.  
  130. # system stuff
  131. variable quizbasedir moxquizz
  132. variable datadir $quizbasedir/quizdata
  133. variable configfile $quizbasedir/moxquizz.rc
  134. variable intldir $quizbasedir/intl
  135.  
  136. variable rankfile $datadir/rank.data
  137. variable allstarsfile $datadir/rankallstars.data
  138. variable statsfile $datadir/stats.data
  139. variable userqfile $datadir/questions.user.new
  140. variable commentsfile $datadir/comments.txt
  141.  
  142. variable quizhelp
  143.  
  144. # these will be searched in $intldir/$quizconf(language)
  145. variable channeltipfile channeltips.txt
  146. variable channelrulesfile channelrules.txt
  147. variable pricesfile prices.txt
  148. variable helpfile help.txt
  149.  
  150.  
  151. #
  152. # Configuration map
  153. #
  154. variable quizconf
  155.  
  156. set quizconf(quizchannel) "#quiz"
  157. set quizconf(quizloglevel) 1
  158.  
  159. # several global numbers
  160. set quizconf(maxranklines) 100
  161. set quizconf(tipcycle) 5
  162. set quizconf(useractivetime) 240
  163. set quizconf(userqbufferlength) 20
  164. set quizconf(winscore) 30
  165. set quizconf(overrunlimit) 29
  166.  
  167. # timer delays in seconds
  168. set quizconf(askdelay) 12
  169. set quizconf(tipdelay) 14
  170.  
  171. # safety features and other configs
  172. set quizconf(lastwinner_restriction) no
  173. set quizconf(lastwinner_max_games) 4
  174. set quizconf(overrun_protection) no
  175. set quizconf(colorize) yes
  176. set quizconf(monthly_allstars) no
  177. set quizconf(channeltips) yes
  178. set quizconf(pausemoderated) no
  179. set quizconf(userquestions) yes
  180. set quizconf(msgwhisper) no
  181. set quizconf(channelrules) yes
  182. set quizconf(prices) yes
  183. set quizconf(stripumlauts) no
  184. set quizconf(statslog) no
  185. set quizconf(aftergameaction) newgame
  186.  
  187. set quizconf(language) de
  188.  
  189.  
  190. ##
  191. ###########################################################################
  192.  
  193. ##
  194. ## stuff for the game state
  195. ##
  196.  
  197. #typ
  198. set ctcp-version "MoxQuizz für #Quiz.de @ irc.GameSurge.net"
  199. variable answerarray
  200. variable schaetzarray
  201.  
  202. variable schaetzend ""
  203. variable schaetzwert ""
  204. variable timetypasked [clock clicks -milliseconds]
  205.  
  206. variable subexp ""
  207. variable bestscore 0
  208.  
  209. # values = stopped, paused, asked, waittoask, halted
  210. variable quizstate "halted"
  211. variable statepaused ""
  212. variable statemoderated ""
  213. variable usergame 0
  214. variable timeasked [unixtime]
  215. variable revoltmax 0
  216. # values = newgame, stop, halt, exit
  217. variable aftergame $quizconf(aftergameaction)
  218. variable channeltips ""
  219. variable channelrules ""
  220. variable prices ""
  221.  
  222. #
  223. # variables for the ranks and user handling
  224. #
  225. variable timerankreset [unixtime]
  226. variable userlist
  227. variable allstarsarray
  228. variable revoltlist ""
  229. variable lastsolver ""
  230. variable lastsolvercount 0
  231. variable lastwinner ""
  232. variable lastwinnercount 0
  233. variable allstars_starttime 0
  234. variable ignore_for_userquest ""
  235.  
  236. #
  237. # stuff for the question
  238. #
  239. variable tiplist ""
  240. variable theq
  241. variable qnumber 0
  242. variable qnum_thisgame 0
  243. variable userqnumber 0
  244. variable tipno 0
  245. variable qlist ""
  246. variable qlistorder ""
  247. variable userqlist ""
  248.  
  249. #
  250. # doesn't fit elsewhere
  251. #
  252. variable whisperprefix "NOTICE"
  253. variable statsfilefd "closed"
  254.  
  255. ##################################################
  256. ## bindings
  257.  
  258. # bot running status
  259. bind dcc P !init moxquiz_init
  260. bind dcc P !stop moxquiz_stop
  261. bind dcc P !halt moxquiz_halt
  262. bind dcc P !pause moxquiz_pause
  263. bind dcc P !cont moxquiz_cont
  264. bind dcc P !reset moxquiz_reset
  265. bind dcc m !exit moxquiz_exit
  266. bind dcc m !aftergame moxquiz_aftergame
  267.  
  268. # bot speaking and hopping stuff
  269. bind dcc P !say moxquiz_say
  270. bind dcc P !act moxquiz_action
  271. bind dcc m !allsay moxquiz_say_everywhere
  272. bind dcc m !allact moxquiz_action_everywhere
  273. bind dcc Q !join moxquiz_join
  274. bind dcc Q !part moxquiz_part
  275. bind dcc Q !quizto moxquiz_quizto
  276. bind dcc Q !quizleave moxquiz_quizleave
  277.  
  278. # commands for the questions
  279. bind dcc P !solve moxquiz_solve
  280. bind dcc P !tip moxquiz_tip
  281. bind dcc P !skipuserquest moxquiz_skipuserquest
  282. bind dcc Q !setscore moxquiz_set_score
  283.  
  284. bind dcc m !qsave moxquiz_saveuserquests
  285. bind dcc Q !reload moxquiz_reload
  286.  
  287.  
  288. # status and configuration
  289. bind dcc P !status moxquiz_status
  290. bind dcc m !load moxquiz_config_load
  291. bind dcc m !save moxquiz_config_save
  292. bind dcc m !set moxquiz_config_set
  293.  
  294. # userquest and other user (public) commands
  295. bind pubm - * moxquiz_pubm
  296. bind pub - !ask moxquiz_ask
  297. bind pub - .ask moxquiz_ask
  298. bind pub - !quiz moxquiz_ask
  299. bind pub - .quiz moxquiz_ask
  300. bind pub - !start moxquiz_ask
  301. bind pub - .start moxquiz_ask
  302.  
  303. bind pub - !revolt moxquiz_user_revolt
  304. bind pub - !end moxquiz_user_revolt
  305.  
  306. bind msg - !userquest moxquiz_userquest
  307. bind msg - !usercancel moxquiz_usercancel
  308. bind msg - !usertip moxquiz_usertip
  309. bind msg - !usersolve moxquiz_usersolve
  310. bind pub P !nuq moxquiz_userquest_ignore
  311. bind pub P !uq moxquiz_userquest_unignore
  312. bind pub P !listnuq moxquiz_userquest_listignores
  313. bind pub P !clearnuq moxquiz_userquest_clearignores
  314.  
  315. bind msg - !qhelp moxquiz_help
  316. bind pub - !qhelp moxquiz_pub_help
  317. bind pub - !score moxquiz_pub_score
  318. bind pub - !rank moxquiz_pub_rank
  319. bind pub - !allstars moxquiz_pub_allstars
  320. bind pub - !comment moxquiz_pub_comment
  321. bind pub - !fehler moxquiz_pub_comment
  322. bind dcc - !comment moxquiz_dcc_comment
  323. bind msg - !rules moxquiz_rules
  324. bind pub - !rules moxquiz_pub_rules
  325. bind msg - !version moxquiz_version
  326. bind pub - !version moxquiz_pub_version
  327.  
  328. # mini funstuff
  329. bind pub - !hi moxquiz_pub_hi
  330. #bind ctcp - action moxquiz_purr
  331.  
  332. # commands to manage players and rank
  333. bind dcc P !allstars moxquiz_allstars
  334. bind dcc m !allstarssend moxquiz_allstars_send
  335. bind dcc m !allstarsload moxquiz_allstars_load
  336. bind dcc P !rank moxquiz_rank
  337. bind dcc Q !rankdelete moxquiz_rank_delete
  338. bind dcc m !rankload moxquiz_rank_load
  339. bind dcc m !ranksave moxquiz_rank_save
  340. bind dcc Q !rankreset moxquiz_rank_reset
  341. bind dcc Q !rankset moxquiz_rank_set
  342.  
  343.  
  344. # Some events the bot reacts on
  345. bind nick - * moxquiz_on_nickchanged
  346. bind join - * moxquiz_on_joined
  347. bind mode - "*m" moxquiz_on_moderated
  348. bind evnt - prerehash mx_event
  349. bind evnt - rehash mx_event
  350.  
  351. ## DEBUG
  352. bind dcc n !colors moxquiz_colors
  353.  
  354. ###########################################################################
  355. #
  356. # bot running commands
  357. #
  358. ###########################################################################
  359.  
  360. ## reset game
  361. proc moxquiz_reset {handle idx arg} {
  362. global quizstate
  363. moxquiz_stop $handle $idx $arg
  364. moxquiz_rank_reset $handle $idx $arg
  365. moxquiz_init $handle $idx $arg
  366. }
  367.  
  368. ## initialize
  369. proc moxquiz_init {handle idx arg} {
  370. global qlist version_moxquizz banner bannerspace quizstate
  371. global quizconf aftergame
  372.  
  373. set quizstate "halted"
  374. set aftergame $quizconf(aftergameaction)
  375. if {$quizconf(quizchannel) != ""} {
  376. mxirc_say $quizconf(quizchannel) [mc "%sHello! I am a MoxQuizz version %s and ready to squeeze your brain!" "[banner] [botcolor txt]" "[col bold]$version_moxquizz[col bold][botcolor txt]"]
  377. mxirc_say $quizconf(quizchannel) [mc "%s%d questions in database, just %s!ask%s. Report bugs and suggestions to [email protected]" "[bannerspace] [botcolor txt]" [llength $qlist] [col bold] "[col bold][botcolor txt]"]
  378. mx_log "--- Game initialized"
  379. } else {
  380. mxirc_dcc $idx "ERROR: quizchannel is set to an empty string, use .!quizto to set one."
  381. }
  382. return 1
  383. }
  384.  
  385. ## stop
  386. ## stop everything and kill all timers
  387. proc moxquiz_stop {handle idx arg} {
  388. global quizstate banner bannerspace
  389. global quizconf
  390. variable t
  391. variable prefix [banner]
  392.  
  393.  
  394.   ## called directly?
  395. if {[info level] != 1} {
  396. set prefix [bannerspace]
  397. } else {
  398. set prefix [banner]
  399. }
  400.  
  401. set quizstate "stopped"
  402.  
  403.   ## kill timers
  404. foreach t [utimers] {
  405. if {[lindex $t 1] == "mx_timer_ask" || [lindex $t 1] == "mx_timer_tip"} {
  406. killutimer [lindex $t 2]
  407. }
  408. }
  409.  
  410. mx_log "--- Game stopped."
  411. mxirc_say $quizconf(quizchannel) [mc "%s %sQuiz stopped." $prefix [botcolor boldtxt]]
  412. return 1
  413. }
  414.  
  415.  
  416. ## halt
  417. ## halt everything and kill all timers
  418. proc moxquiz_halt {handle idx arg} {
  419. global quizstate banner bannerspace
  420. global quizconf
  421.  
  422. variable t
  423. variable prefix [banner]
  424.  
  425.   ## called directly?
  426. if {[info level] != 1} {
  427. set prefix [bannerspace]
  428. } else {
  429. set prefix [banner]
  430. }
  431.  
  432. set quizstate "halted"
  433.  
  434.   ## kill timers
  435. foreach t [utimers] {
  436. if {[lindex $t 1] == "mx_timer_ask" || [lindex $t 1] == "mx_timer_tip"} {
  437. killutimer [lindex $t 2]
  438. }
  439. }
  440.  
  441. mx_log "--- Game halted."
  442. mxirc_say $quizconf(quizchannel) [mc "%s %sQuiz halted. Say !ask for new questions." $prefix [botcolor boldtxt]]
  443. utimer 5 mx_restart
  444. return 1
  445. }
  446.  
  447.  
  448. ## reload questions
  449. proc moxquiz_reload {handle idx arg} {
  450. global qlist quizconf
  451. global datadir
  452.  
  453. variable alist ""
  454. variable banks
  455. variable suffix
  456.  
  457. set arg [string trim $arg]
  458. if {$arg == ""} {
  459. # get question files
  460. set alist [glob -nocomplain "$datadir/questions.*"]
  461.  
  462. # get suffixes
  463. foreach file $alist {
  464. regexp "^.*\\.(\[^\\.\]+)$" $file foo suffix
  465. set banks($suffix) 1
  466. }
  467.  
  468. # report them
  469. mxirc_dcc $idx "There are the following question banks available (current: $quizconf(questionset)): [lsort [array names banks]]"
  470. } else {
  471. if {[mx_read_questions $arg] != 0} {
  472. mxirc_dcc $idx "There was an error reading files for $arg."
  473. mxirc_dcc $idx "There are [llength $qlist] questions available."
  474. } else {
  475. mxirc_dcc $idx "Reloaded database, [llength $qlist] questions."
  476. set quizconf(questionset) $arg
  477. }
  478. }
  479.  
  480. return 1
  481. }
  482.  
  483. ## pause
  484. proc moxquiz_pause {handle idx arg} {
  485. global quizstate statepaused banner timeasked
  486. global quizconf
  487.  
  488. variable qwasopen "."
  489.  
  490. if {[regexp "(halted|paused)" $quizstate]} {
  491. mxirc_dcc $idx "Quiz state is $quizstate. Command ignored."
  492. } else {
  493. if {$quizstate == "asked"} {
  494. foreach t [utimers] {
  495. if {[lindex $t 1] == "mx_timer_tip"} {
  496. killutimer [lindex $t 2]
  497. }
  498. }
  499. set qwasopen [mc " after %s." [mx_duration $timeasked]]
  500. } elseif {$quizstate == "waittoask"} {
  501. foreach t [utimers] {
  502. if {[lindex $t 1] == "mx_timer_ask"} {
  503. killutimer [lindex $t 2]
  504. }
  505. }
  506. }
  507. set statepaused $quizstate
  508. set quizstate "paused"
  509. mx_log "--- Game paused$qwasopen Quiz state was: $statepaused"
  510. mxirc_say $quizconf(quizchannel) [mc "%sQuiz paused%s" "[banner] [botcolor boldtxt]" $qwasopen]
  511. }
  512. return 1
  513. }
  514.  
  515.  
  516. ## continue
  517. proc moxquiz_cont {handle idx arg} {
  518. global quizstate banner bannerspace timeasked
  519. global theq statepaused usergame statemoderated
  520. global quizconf
  521.  
  522. if {$quizstate != "paused"} {
  523. mxirc_dcc $idx "Game not paused, command ignored."
  524. } else {
  525. if {$statepaused == "asked"} {
  526. if {$usergame == 1} {
  527. set txt [mc "%sQuiz continued. The user question open since %s, worth %d point(s):" "[banner] [botcolor boldtxt]" [mx_duration $timeasked] $theq(Score)]
  528. } else {
  529. set txt [mc "%sQuiz continued. The question open since %s, worth %d point(s):" "[banner] [botcolor boldtxt]" [mx_duration $timeasked] $theq(Score)]
  530. }
  531. mxirc_say $quizconf(quizchannel) $txt
  532. mxirc_say $quizconf(quizchannel) "[bannerspace] [botcolor question]$theq(Question)"
  533. utimer $quizconf(tipdelay) mx_timer_tip
  534. } else {
  535. mxirc_say $quizconf(quizchannel) [mc "%sQuiz continued. Since there is no open question, a new one will be asked." "[banner] [botcolor boldtxt]"]
  536. utimer 3 mx_timer_ask
  537. }
  538. set quizstate $statepaused
  539. set statepaused ""
  540. set statemoderated ""
  541. mx_log "--- Game continued."
  542. }
  543. return 1
  544. }
  545.  
  546. ## show module status
  547. proc moxquiz_status {handle idx arg} {
  548. global quizstate statepaused qlist banner version_moxquizz userlist
  549. global timeasked uptime
  550. global usergame userqlist theq qnumber
  551. global qnum_thisgame aftergame
  552.  
  553. global quizconf
  554.  
  555. variable askleft 0 rankleft 0 tipleft 0
  556. variable txt
  557. variable chansjoined ""
  558.  
  559.   ## banner and where I am
  560. set txt "I am [mx_strip_colors [banner]] version $version_moxquizz, up for [mx_duration $uptime]"
  561. if {$quizconf(quizchannel) == ""} {
  562. set txt "$txt, not quizzing on any channel."
  563. } else {
  564. set txt "$txt, quizzing on channel \"$quizconf(quizchannel)\"."
  565. }
  566. mxirc_dcc $idx $txt
  567.  
  568. mxirc_dcc $idx "I know the channels [channels]."
  569.  
  570. foreach chan [channels] {
  571. if {[botonchan $chan]} {
  572. set chansjoined "$chansjoined $chan"
  573. }
  574. }
  575. if {$chansjoined == ""} {
  576. set chansjoined " none"
  577. }
  578. mxirc_dcc $idx "I currently joined:$chansjoined."
  579.  
  580. if {$quizstate == "asked" || $statepaused == "asked"} {
  581. ## Game running? User game?
  582. set txt "There is a"
  583. if {$usergame == 1} {
  584. set txt "$txt user"
  585. }
  586. set txt "$txt game running."
  587. if {[mx_userquests_available]} {
  588. set txt "$txt [mx_userquests_available] user quests scheduled."
  589. } else {
  590. set txt "$txt No user quest is scheduled."
  591. }
  592. set txt "$txt Quiz state is: $quizstate."
  593. mxirc_dcc $idx $txt
  594.  
  595. ## Open question? Quiz state?
  596. set txt "The"
  597. if {[info exists theq(Level)]} {
  598. set txt "$txt level $theq(Level)"
  599. }
  600. set txt "$txt question no. $qnum_thisgame is:"
  601. if {[info exists theq(Category)]} {
  602. set txt "$txt ($theq(Category))"
  603. }
  604. mxirc_dcc $idx "$txt \"$theq(Question)\" open for [mx_duration $timeasked], worth $theq(Score) points."
  605. } else {
  606. ## no open question, no game running
  607. set txt "There is no question open."
  608. set txt "$txt Quiz state is: $quizstate."
  609. if {[mx_userquests_available]} {
  610. set txt "$txt [mx_userquests_available] user quests scheduled."
  611. } else {
  612. set txt "$txt No user quest is scheduled."
  613. }
  614. mxirc_dcc $idx $txt
  615. }
  616.  
  617. mxirc_dcc $idx "Action after game won: $aftergame"
  618.  
  619. foreach t [utimers] {
  620. if {[lindex $t 1] == "mx_timer_ask"} {
  621. set askleft [lindex $t 0]
  622. }
  623. if {[lindex $t 1] == "mx_timer_tip"} {
  624. set tipleft [lindex $t 0]
  625. }
  626. }
  627.  
  628. mxirc_dcc $idx "Tipdelay: $quizconf(tipdelay) ($tipleft) Askdelay: $quizconf(askdelay) ($askleft) Tipcycle: $quizconf(tipcycle)"
  629. mxirc_dcc $idx "I know about [llength $qlist] normal and [llength $userqlist] user questions. Question number is $qnumber."
  630. mxirc_dcc $idx "There are [llength [array names userlist]] known people, winscore is $quizconf(winscore)."
  631. mxirc_dcc $idx "Game row restriction: $quizconf(lastwinner_restriction), row length: $quizconf(lastwinner_max_games)"
  632. return 1
  633. }
  634.  
  635.  
  636. ## exit -- finish da thing and logoff
  637. proc moxquiz_exit {handle idx arg} {
  638. global rankfile uptime botnick statsfilefd
  639. global quizconf
  640. mx_log "--- EXIT requested."
  641. mxirc_say $quizconf(quizchannel) [mc "%sI am leaving now, after running for %s." "[banner] [botcolor boldtxt]" [mx_duration $uptime]]
  642. if {$arg != ""} {
  643. mxirc_say $quizconf(quizchannel) "[bannerspace] $arg"
  644. }
  645. # moxquiz_quizleave $handle $idx $arg
  646. moxquiz_rank_save $handle $idx {}
  647. moxquiz_saveuserquests $handle $idx "all"
  648. moxquiz_config_save $handle $idx {}
  649. if {$statsfilefd != "closed"} { close $statsfilefd }
  650. mxirc_dcc $idx "$botnick now exits."
  651. mx_log "--- $botnick exited"
  652. mx_log "**********************************************************************"
  653.  
  654. utimer 10 die
  655. }
  656.  
  657. ## aftergame -- what to do if the game is over (won or desert detection)
  658. proc moxquiz_aftergame {handle idx arg} {
  659. global aftergame quizstate
  660.  
  661. variable thisnext "this"
  662.  
  663. if {$quizstate == "stopped" || $quizstate == "halted"} {
  664. set thisnext "next"
  665. }
  666.  
  667. if {$arg == ""} {
  668. mxirc_dcc $idx "After $thisnext game I am planning to: \"$aftergame\"."
  669. mxirc_dcc $idx "Possible values are: exit, halt, stop, newgame."
  670. } else {
  671. switch -regexp $arg {
  672. "(exit|halt|stop|newgame)" {
  673. set aftergame $arg
  674. mxirc_dcc $idx "After $thisnext game I now will: \"$aftergame\"."
  675. }
  676. default {
  677. mxirc_dcc $idx "Invalid action. Chosse from: exit, halt, stop and newgame."
  678. }
  679. }
  680. }
  681. return 1
  682. }
  683.  
  684. ####################
  685. # bot control stuff
  686. ####################
  687.  
  688. ## echo a text send by /msg
  689. proc moxquiz_say {handle idx arg} {
  690. global funstuff_enabled botnick
  691. global quizconf
  692.  
  693. variable channel
  694.  
  695. set arg [string trim $arg]
  696. if {[regexp -nocase "^(#\[^ \]+)( +.*)?" $arg foo channel arg]} {
  697. ## check if on channel $channel
  698. if {[validchan $channel] && ![botonchan $channel]} {
  699. mxirc_dcc $idx "Sorry, I'm not on channel \"$channel\"."
  700. return
  701. }
  702. } else {
  703. set channel $quizconf(quizchannel)
  704. }
  705. set arg [string trim $arg]
  706.  
  707. mxirc_say $channel "$arg"
  708. variable unused "" cmd "" rest ""
  709.  
  710.   # if it was a fun command, execute it with some delay
  711. if {$funstuff_enabled &&
  712. [regexp "^(!\[^ \]+)(( *)(.*))?" $arg unused cmd waste spaces rest] &&
  713. [llength [bind pub - $cmd]] != 0} {
  714. if {$rest == ""} {
  715. set rest "{}"
  716. } else {
  717. set rest "{$rest}"
  718. }
  719. eval "[bind pub - $cmd] {$botnick} {} {} {$channel} $rest"
  720. }
  721. }
  722.  
  723.  
  724. ## say something on al channels
  725. proc moxquiz_say_everywhere {handle idx arg} {
  726. if {$arg != ""} {
  727. mxirc_say_everywhere $arg
  728. } else {
  729. mxirc_dcc $idx "What shall I say on every channel?"
  730. }
  731. }
  732.  
  733.  
  734. ## act as sent by /msg
  735. proc moxquiz_action {handle idx arg} {
  736. global quizconf
  737. variable channel
  738.  
  739. set arg [string trim $arg]
  740. if {[regexp -nocase "^(#\[^ \]+)( +.*)?" $arg foo channel arg]} {
  741. ## check if on channel $channel
  742. if {[validchan $channel] && ![botonchan $channel]} {
  743. mxirc_dc $idx "Sorry, I'm not on channel \"$channel\"."
  744. return
  745. }
  746. } else {
  747. set channel $quizconf(quizchannel)
  748. }
  749. set arg [string trim $arg]
  750.  
  751. mxirc_action $channel "$arg"
  752. }
  753.  
  754.  
  755. ## say something on al channels
  756. proc moxquiz_action_everywhere {handle idx arg} {
  757. if {$arg != ""} {
  758. mxirc_action_everywhere $arg
  759. } else {
  760. mxirc_dcc $idx "What shall act like on every channel?"
  761. }
  762. }
  763.  
  764.  
  765. ## hop to another channel
  766. proc moxquiz_join {handle idx arg} {
  767. global quizconf
  768. if {[regexp -nocase "^(#\[^ \]+)( +.*)?" $arg foo channel arg]} {
  769. set channel [string tolower $channel]
  770. if {[validchan $channel] && [botonchan $channel]} {
  771. set txt "I am already on $channel."
  772. if {$channel == $quizconf(quizchannel)} {
  773. set txt "$txt It's the quizchannel."
  774. }
  775. mxirc_dcc $idx $txt
  776. } else {
  777. channel add $channel
  778. channel set $channel -inactive
  779. mxirc_dcc $idx "Joined channel $channel."
  780. }
  781. } else {
  782. mxirc_dcc $idx "Please specify channel I shall join. \"$arg\" not recognized."
  783. }
  784. }
  785.  
  786.  
  787. ## part an channel
  788. proc moxquiz_part {handle idx arg} {
  789. global quizconf
  790. if {[regexp -nocase "^(#\[^ \]+)( +.*)?" $arg foo channel arg]} {
  791. set channel [string tolower $channel]
  792. if {[validchan $channel]} {
  793. if {$channel == $quizconf(quizchannel)} {
  794. mxirc_dcc $idx "Cannot leave quizchannel via part. User !quizleave or !quizto to do this."
  795. } else {
  796. channel set $channel +inactive
  797. mxirc_dcc $idx "Left channel $channel."
  798. }
  799. } else {
  800. mxirc_dcc $idx "I am not on $channel."
  801. }
  802. } else {
  803. mxirc_dcc $idx "Please specify channel I shall part. \"$arg\" not recognized."
  804. }
  805. }
  806.  
  807. ## quiz to another channel
  808. proc moxquiz_quizto {handle idx arg} {
  809. global quizconf
  810. if {[regexp "^#.*" $arg] == 0} {
  811. mxirc_dcc $idx "$arg not a valid channel."
  812. } else {
  813. if {$quizconf(quizchannel) != ""} {
  814. # channel set $quizconf(quizchannel) +inactive
  815. mxirc_say $quizconf(quizchannel) [mc "Quiz is leaving to %s. Goodbye!" $arg]
  816. }
  817. set quizconf(quizchannel) [string tolower $arg]
  818. channel add $quizconf(quizchannel)
  819. channel set $quizconf(quizchannel) -inactive
  820. mxirc_say $quizconf(quizchannel) [mc "Quiz is now on this channel. Hello!"]
  821. mxirc_dcc $idx "quiz to channel $quizconf(quizchannel)."
  822. mx_log "--- quizto channel $quizconf(quizchannel)"
  823. }
  824. return 1
  825. }
  826.  
  827.  
  828. ## quiz leave a channel
  829. proc moxquiz_quizleave {handle idx arg} {
  830. global quizconf banner
  831. if {$arg == ""} {
  832. mxirc_say $quizconf(quizchannel) [mc "%s Goodbye." [banner]]
  833. } else {
  834. mxirc_say $quizconf(quizchannel) "[banner] $arg"
  835. }
  836. if {$quizconf(quizchannel) != ""} {
  837. channel set $quizconf(quizchannel) +inactive
  838. mx_log "--- quizleave channel $quizconf(quizchannel)"
  839. mxirc_dcc $idx "quiz left channel $quizconf(quizchannel)"
  840. set quizconf(quizchannel) ""
  841. } else {
  842. mxirc_dcc $idx "I'm not quizzing on any channel."
  843. }
  844. return 1
  845. }
  846.  
  847.  
  848. ###########################################################################
  849. #
  850. # commands for the questions
  851. #
  852. ###########################################################################
  853.  
  854. ## something was said. Solution?
  855. proc moxquiz_pubm {nick host handle channel text} {
  856. global quizstate banner bannerspace
  857. global timeasked theq aftergame
  858. global usergame revoltlist
  859. global lastsolver lastsolvercount
  860. global lastwinner lastwinnercount
  861. global botnick bestscore
  862. global userlist channeltips prices
  863. global quizconf
  864.  
  865. variable bestscore 0 lastbestscore 0 lastbest ""
  866. variable userarray
  867. variable authorsolved 0 waitforrank 0 gameend 0
  868.  
  869.   ## only accept chatter on quizchannel
  870. if {![mx_str_ieq $channel $quizconf(quizchannel)]} {
  871. return
  872. }
  873.  
  874.   ## record that the $nick spoke and create entries for unknown people
  875. mx_getcreate_userentry $nick $host
  876. array set userarray $userlist($nick)
  877. set hostmask $userarray(mask)
  878.  
  879.   ## not in asking state?
  880. if {$quizstate != "asked"} {
  881. return
  882. }
  883.  
  884.   # nick has revolted
  885. #if {[lsearch -exact $revoltlist $hostmask] != -1} {
  886.   # return
  887. #}
  888.  
  889.   # tweak umlauts in input
  890. set text [mx_tweak_umlauts $text]
  891.  
  892.  
  893. global answerarray
  894. set regohneleerzeichen $theq(Regexp)
  895. regsub -all " " $regohneleerzeichen "" regohneleerzeichen
  896.  
  897. if {[regexp -nocase -- $theq(Regexp) $text] || [regexp -nocase -- $regohneleerzeichen $text]} {
  898.  
  899.  
  900. foreach name [array names answerarray] {
  901. unset answerarray($name)
  902. }
  903.  
  904.  
  905.   ## ignore games_max in a row winner
  906. if {[mx_str_ieq [maskhost $host] $lastwinner]
  907. && $lastwinnercount >= $quizconf(lastwinner_max_games)
  908. && $quizconf(lastwinner_restriction) == "yes"} {
  909. mxirc_notc $nick [mc "No, you've won the last %d games." $quizconf(lastwinner_max_games)]
  910. return
  911. }
  912.  
  913.   # nick is author of userquest
  914. #if {([info exists theq(Author)] && [mx_str_ieq $nick $theq(Author)])
  915. #|| ([info exists theq(Hostmask)] && [mx_str_ieq [maskhost $host] $theq(Hostmask)])} {
  916.   # set authorsolved 1
  917. #}
  918.  
  919.   ## return if overrunprotection set and limit reached
  920. #if {$quizconf(overrun_protection) == "yes"
  921. # && $userarray(score) == 0
  922. # && [mx_users_in_rank] > 2
  923. # && [mx_overrun_limit_reached]} {
  924.   # # [pending] TRANSLATE!
  925. # mxirc_notc $nick [mc "Sorry, overrun protection enabled. Wait till end of game."]
  926. # return
  927. #}
  928.  
  929. ## reset quiz state related stuff (and save userquestions)
  930. mx_answered
  931. set duration [mx_duration $timeasked]
  932.  
  933. set recdiff ""
  934.  
  935. global timetypasked schaetzend allow_rec
  936.  
  937. if {$schaetzend != "" && $schaetzend > 0} {
  938. set typdur $schaetzend
  939. set schaetzend ""
  940. } else {
  941. set typdur [expr ([clock clicks -milliseconds] - $timetypasked) * 0.001]
  942.  
  943. if {$typdur < "10.000" &&$allow_rec} {
  944.  
  945. set record [mx_read_record $text]
  946.  
  947. if {$record == ""} {
  948. mx_save_record $nick $typdur $text
  949. } else {
  950. set recholder [lindex [split $record] 0]
  951. set rectime [lindex [split $record] 1]
  952.  
  953. if {$rectime > $typdur} {
  954. mx_save_record $nick $typdur $text
  955. }
  956.  
  957. set recdiff [expr $typdur - $rectime]
  958. if {$recdiff > 0} {set recdiff "+${recdiff}"} else {set recdiff "\002$recdiff\002"}
  959. set recdiff "\(${recdiff} Sek. zu [mx_nickobf $recholder]\) "
  960. }
  961. }
  962. }
  963.  
  964.  
  965.  
  966.  
  967. # if it wasn't the author
  968. if {!$authorsolved} {
  969. ## save last top score for the test if reset is near (later below)
  970. set lastbest [lindex [lsort -command mx_sortrank [array names userlist]] 0]
  971. if {$lastbest == ""} {
  972. set lastbestscore 0
  973. } else {
  974. array set aa $userlist($lastbest)
  975. set lastbestscore $aa(score)
  976. }
  977.  
  978. ## record nick for bonus points
  979. if {[mx_str_ieq [maskhost $host] $lastsolver]} {
  980. incr lastsolvercount
  981. } else {
  982. set lastsolver [maskhost $host]
  983. set lastsolvercount 1
  984. }
  985.  
  986. ## save score (set started time to time of first point)
  987. incr userarray(score) $theq(Score)
  988. if {$userarray(score) == 1} {
  989. set userarray(started) [unixtime]
  990. }
  991. set userlist($nick) [array get userarray]
  992.  
  993. ## tell channel, that the question is solved
  994. mx_log "--- solved after $duration by $nick with \"$text\", now $userarray(score) points"
  995.  
  996.  
  997. set daten [mx_incr_qnr]
  998.  
  999.  
  1000.  
  1001. global vokspamvar hintmax hintlist
  1002. set vokspamvar 0
  1003. set hintmax 0
  1004. set hintlist ""
  1005.  
  1006.  
  1007. mx_statslog "solved" [list [unixtime] $nick $duration $userarray(score) $theq(Score)]
  1008.  
  1009. #mxirc_say $channel [mc "%s solved after %s and now has %s<%d>%s points (+%d) on rank %d." "[banner] [botcolor nick]$nick[botcolor txt]" $duration [botcolor nick] $userarray(score) [botcolor txt] $theq(Score) [mx_get_rank_pos $nick]]
  1010.  
  1011. set answrnr [mx_answ_user $nick 1]
  1012. set total [regexp -all -nocase {[A-Z]|[0-9]|[ ]} $text]
  1013.  
  1014.   #bugfix:
  1015. if {$typdur <= 0 || $typdur == ""} { set typdur $duration }
  1016.  
  1017. set speed [expr $total / $typdur * 60]
  1018.  
  1019. mxirc_rsay $channel [mc "%s löst nach %s Sek. ${recdiff}seine %d. Frage und hat %s<%d>%s Punkte (+%d), Platz 9,1~%d~1,11.%s %sA/M: %3.0f" "[banner] [botcolor nick]$nick[botcolor txt]" $typdur $answrnr [botcolor nick] $userarray(score) [botcolor txt] $theq(Score) [mx_get_rank_pos $nick] [botcolor norm] [botcolor question] $speed]
  1020.  
  1021.  
  1022.   # remove area of tip generation tags
  1023. regsub -all "\#(\[^\#\]*\)\#" $theq(Answer) "\\1" answer
  1024.  
  1025.  
  1026. global schaetzwert subexp
  1027. if {$schaetzwert != ""} {
  1028. set showanswer $answer
  1029. set schaetzwert [commas $schaetzwert]
  1030.  
  1031. set stotal [regexp -all -nocase {[A-Z]|[0-9]|[ ]} $subexp]
  1032.  
  1033. if {$stotal > 4} {
  1034. regsub -all $subexp $showanswer [commas $subexp] showanswer
  1035. }
  1036.  
  1037. set showanswer "$showanswer \(Abweichung: ${schaetzwert}\)"
  1038. set schaetzwert ""
  1039.  
  1040. } else {
  1041. set showanswer $answer
  1042. }
  1043.  
  1044.  
  1045. mxirc_say $channel [mc "%sThe answer was:%s%s" "[bannerspace] [botcolor txt]" "[botcolor norm] [botcolor answer]" $showanswer]
  1046. ## honor good games!
  1047. if {$lastsolvercount == 3} {
  1048. mxirc_say $channel [mc "%sThree in a row!" "[bannerspace] [botcolor txt]"]
  1049. mx_log "--- $nick has three in a row."
  1050. mx_statslog "tiar" [list [unixtime] $nick 3 0]
  1051. } elseif {$lastsolvercount == 5} {
  1052. mxirc_say $channel [mc "%sCongratulation, five in a row! You receive an extra point." "[bannerspace] [botcolor txt]"]
  1053. mx_log "--- $nick has five in a row. score++"
  1054. mx_statslog "tiar" [list [unixtime] $nick 5 1]
  1055. moxquiz_rank_set $botnick 0 "$nick +1"
  1056. } elseif {$lastsolvercount == 10} {
  1057. mxirc_say $channel [mc "%sTen in a row! This is really rare, so you get 3 extra points." "[bannerspace] [botcolor txt]"]
  1058. mx_log "--- $nick has ten in a row. score += 3"
  1059. mx_statslog "tiar" [list [unixtime] $nick 10 3]
  1060. moxquiz_rank_set $botnick 0 "$nick +3"
  1061. } elseif {$lastsolvercount == 20} {
  1062. mxirc_say $channel [mc "%sTwenty in a row! This is extremely rare, so you get 5 extra points." "[bannerspace] [botcolor txt]"]
  1063. mx_log "--- $nick has twenty in a row. score += 5"
  1064. mx_statslog "tiar" [list [unixtime] $nick 20 5]
  1065. moxquiz_rank_set $botnick 0 "$nick +5"
  1066. }
  1067.  
  1068. ## rankreset, if above winscore
  1069. # notify if this comes near
  1070. set best [lindex [lsort -command mx_sortrank [array names userlist]] 0]
  1071. if {$best == ""} {
  1072. set bestscore 0
  1073. } else {
  1074. array set aa $userlist($best)
  1075. set bestscore $aa(score)
  1076. }
  1077.  
  1078. set waitforrank 0
  1079. if {[mx_str_ieq $best $nick] && $bestscore > $lastbestscore} {
  1080. array set aa $userlist($best)
  1081. # tell the end is near
  1082. if {$bestscore >= $quizconf(winscore)} {
  1083.  
  1084. mx_web $daten $nick
  1085.  
  1086. set price "."
  1087.  
  1088. if {$quizconf(prices) == "yes"} {
  1089. set price " [lindex $prices [rand [llength $prices]]]"
  1090. }
  1091.  
  1092. mxirc_say $channel [mc "%s%s reaches %d points and wins%s" "[bannerspace] [botcolor txt]" $nick $quizconf(winscore) $price]
  1093. set now [unixtime]
  1094. if {[mx_str_ieq [maskhost $host] $lastwinner]} {
  1095. incr lastwinnercount
  1096. if {$lastwinnercount >= $quizconf(lastwinner_max_games)
  1097. && $quizconf(lastwinner_restriction) == "yes"} {
  1098. mxirc_say $channel [mc "%s: since you won %d games in a row, you will be ignored for the next game." $nick $quizconf(lastwinner_max_games)]
  1099. }
  1100. } else {
  1101. set lastwinner [maskhost $host]
  1102. set lastwinnercount 1
  1103. }
  1104. # save $nick in allstars table
  1105. mx_saveallstar $now [expr $now - $aa(started)] $bestscore $nick [maskhost $host]
  1106. mx_statslog "gamewon" [list $now $nick $bestscore $quizconf(winscore) [expr $now - $aa(started)]]
  1107.  
  1108. moxquiz_alltimestars_load $botnick 0 $nick
  1109. #mxsave_alltimestars
  1110.  
  1111. moxquiz_rank $botnick 0 {}
  1112. moxquiz_rank_reset $botnick {} {}
  1113. set gameend 1
  1114. set waitforrank 15
  1115. } elseif {$bestscore == [expr $quizconf(winscore) / 2]} {
  1116. mxirc_say $channel [mc "%sHalftime. Game is won at %d points." \
  1117. "[bannerspace] [botcolor txt]" $quizconf(winscore)]
  1118. } elseif {$bestscore == [expr $quizconf(winscore) - 10]} {
  1119. mxirc_say $channel [mc "%s%s has 10 points to go." "[bannerspace] [botcolor txt]" $best]
  1120. } elseif {$bestscore == [expr $quizconf(winscore) - 5]} {
  1121. mxirc_say $channel [mc "%s%s has 5 points to go." "[bannerspace] [botcolor txt]" $best]
  1122. } elseif {$bestscore >= [expr $quizconf(winscore) - 3]} {
  1123. mxirc_say $channel [mc "%s%s has %d point(s) to go." \
  1124. "[bannerspace] [botcolor txt]" $best [expr $quizconf(winscore) - $bestscore]]
  1125. }
  1126.  
  1127. # show rank at 1/3, 2/3 of and 5 before winscore
  1128. set spitrank 1
  1129. foreach third [list [expr $quizconf(winscore) / 3] [expr 2 * $quizconf(winscore) / 3] [expr $quizconf(winscore) - 5]] {
  1130. if {$lastbestscore < $third && $bestscore >= $third && $spitrank} {
  1131. moxquiz_rank $botnick 0 {}
  1132. set spitrank 0
  1133. set waitforrank 15
  1134. }
  1135. }
  1136.  
  1137. }
  1138. } else {
  1139. ## tell channel, that the question is solved by author
  1140. mx_log "--- solved after $duration by $nick with \"$text\" by author"
  1141. mxirc_say $channel [mc "%s solved own question after %s and gets no points, keeping %s<%d>%s points on rank %d." \
  1142. "[banner] [botcolor nick]$nick[botcolor txt]" $duration [botcolor nick] $userarray(score) [botcolor txt] [mx_get_rank_pos $nick]]
  1143. # remove area of tip generation tags
  1144. regsub -all "\#(\[^\#\]*\)\#" $theq(Answer) "\\1" answer
  1145. mxirc_say $channel [mc "%sThe answer was:%s%s" "[bannerspace] [botcolor txt]" "[botcolor norm] [botcolor answer]" $answer]
  1146. }
  1147.  
  1148. ## Give some occasional tips
  1149. if {$quizconf(channeltips) == "yes" && [rand 30] == 0} {
  1150. mxirc_say $channel [mc "%sHint: %s" "[bannerspace] [botcolor txt]" [lindex $channeltips [rand [llength $channeltips]]]]
  1151. }
  1152.  
  1153. ## check if game has ended and react
  1154. if {!$gameend || $aftergame == "newgame"} {
  1155. # set up ask timer
  1156. utimer [expr $waitforrank + $quizconf(askdelay)] mx_timer_ask
  1157. } else {
  1158. mx_aftergameaction
  1159. }
  1160. } elseif {[info exists theq(Category)]} {
  1161.  
  1162. if {$theq(Category) == "Schätzfragen"} {
  1163.  
  1164.  
  1165. set text [lindex [split $text] 0]
  1166.  
  1167. if {![regexp "\[0-9\]+" $text]} { return }
  1168. if {[regexp "\[A-Z\]" $text]} { return }
  1169. if {[regexp "\[a-z\]" $text]} { return }
  1170.  
  1171. if {[regexp -all -nocase {[A-Z]|[0-9]|[ ]} $text] > 12} {}
  1172.  
  1173.  
  1174. global schaetzarray timetypasked subexp
  1175. regsub -all \[{',.!}] $subexp "" subexp
  1176.  
  1177. set entry schaetzarray($nick)
  1178.  
  1179. set text [expr $text - $subexp]
  1180.  
  1181. if {$text < 0} {
  1182. set text [expr $text * -1]
  1183. }
  1184.  
  1185.  
  1186. set typdur [expr ([clock clicks -milliseconds] - $timetypasked) * 0.001]
  1187. set schaetzarray($nick) [list $text $typdur]
  1188. }
  1189.  
  1190. } else {
  1191.  
  1192.  
  1193.  
  1194. if {$text==""||$text==" "} { return }
  1195.  
  1196. if {[info exists answerarray($nick)]} {
  1197.  
  1198. set textzwei [lindex $answerarray($nick) 1]
  1199.  
  1200.  
  1201. if {$textzwei==$text||$textzwei=="$text "} { return }
  1202.  
  1203.  
  1204. regsub "\{" $textzwei "" textzwei
  1205. regsub "\}" $textzwei "" textzwei
  1206.  
  1207. regsub " " $textzwei "" textzwei
  1208.  
  1209.  
  1210. if {$textzwei==$text||$textzwei=="$text "} { return }
  1211.  
  1212. set textzwei "$textzwei $text"
  1213. regsub "\{" $textzwei "" textzwei
  1214. regsub "\}" $textzwei "" textzwei
  1215.  
  1216. regsub " " $textzwei "" textzwei
  1217.  
  1218. set entry $answerarray($nick)
  1219. set answerarray($nick) [list \
  1220. $nick \
  1221. $textzwei \
  1222. ]
  1223.  
  1224. moxquiz_pubm $nick $host $handle $channel $textzwei
  1225.  
  1226.  
  1227. } else {
  1228. set answerarray($nick) [list \
  1229. $nick \
  1230. $text \
  1231. ]
  1232. }
  1233.  
  1234. }
  1235. }
  1236.  
  1237.  
  1238. ## Tool function to get the question introduction text
  1239. proc mx_get_qtext {complete} {
  1240. global theq qnum_thisgame timeasked usergame qlist
  1241.  
  1242. set qtext [list "Die Frage Nr. %d (aus [commas [llength $qlist]] Fragen) ist" \
  1243. "The question no. %d is worth %d points" \
  1244. "The question no. %d by %s is" \
  1245. "The question no. %d by %s is worth %d points" \
  1246. "The user question no. %d is" \
  1247. "The user question no. %d is worth %d points" \
  1248. "The user question no. %d by %s is" \
  1249. "The user question no. %d by %s is worth %d points" \
  1250. "The level %s question no. %d is" \
  1251. "The level %s question no. %d is worth %d points" \
  1252. "The level %s question no. %d by %s is" \
  1253. "The level %s question no. %d by %s is worth %d points" \
  1254. "The level %s user question no. %d is" \
  1255. "The level %s user question no. %d is worth %d points" \
  1256. "The level %s user question no. %d by %s is" \
  1257. "The level %s user question no. %d by %s is worth %d points" ]
  1258.  
  1259.  
  1260.   ## game runs, tell user the question via msg
  1261. set qtextnum 0
  1262. set txt [list $qnum_thisgame]
  1263.  
  1264. if {[info exists theq(Level)]} {
  1265. incr qtextnum 8
  1266. set txt [linsert $txt 0 $theq(Level)]
  1267. }
  1268.  
  1269. if {$usergame == 1} { incr qtextnum 4 }
  1270.  
  1271. if {[info exists theq(Author)]} {
  1272. incr qtextnum 2
  1273. lappend txt [mx_nickobf $theq(Author)]
  1274. }
  1275.  
  1276. if {$theq(Score) > 1} {
  1277. incr qtextnum 1
  1278. lappend txt $theq(Score)
  1279. }
  1280.  
  1281. set txt [linsert $txt 0 mc [lindex $qtext $qtextnum]]
  1282. set txt [eval $txt]
  1283.  
  1284. if {$complete == "long"} {
  1285. set txt [mc "%s, open for %s:" $txt [mx_duration $timeasked]]
  1286. if {[info exists theq(Category)]} {
  1287. set txt "$txt \($theq(Category)\)"
  1288. }
  1289. set txt "$txt $theq(Question)"
  1290. } else {
  1291. set txt "$txt:"
  1292. }
  1293.  
  1294.  
  1295. global datadir
  1296. set fname "$datadir/qnr.data"
  1297.  
  1298. if {[file exists $fname] && [file readable $fname]} {
  1299.  
  1300. set fp [open $fname "r"]
  1301. set daten [read -nonewline $fp]
  1302. close $fp
  1303.  
  1304. } else {
  1305.  
  1306. set daten 0
  1307.  
  1308. global statsfile
  1309. set fp [open $statsfile "r"]
  1310. set data [read $fp]
  1311. close $fp
  1312.  
  1313. foreach line [split $data "\n"] {
  1314.  
  1315. if {[lindex [split $line] 0] == "solved"} {
  1316. incr daten
  1317. }
  1318. }
  1319.  
  1320. set file [open $fname w]
  1321. puts $file $daten
  1322. close $file
  1323.  
  1324. }
  1325.  
  1326.   #return [eval $txt]
  1327. set pre "[banner] [botcolor boldtxt]"
  1328. return "${pre}($daten.) $txt"
  1329. }
  1330.  
  1331.  
  1332.  
  1333. ## ask a question, start game
  1334. proc moxquiz_ask {nick host handle channel arg} {
  1335. global qlist quizstate botnick banner bannerspace
  1336. global tipno tiplist
  1337. global userqnumber usergame userqlist
  1338. global timeasked qnumber theq
  1339. global qnum_thisgame
  1340. global userlist timerankreset
  1341. global quizconf schaetztime subexp
  1342. variable anum 0
  1343. variable txt
  1344.  
  1345.   ## only accept chatter on quizchannel
  1346. if {![mx_str_ieq $channel $quizconf(quizchannel)]} {
  1347. return
  1348. }
  1349.  
  1350. switch -exact $quizstate {
  1351. "paused" {
  1352. mxirc_notc $nick [mc "Game is paused."]
  1353. return 1
  1354. }
  1355. "stopped" {
  1356. mxirc_notc $nick [mc "Game is stopped."]
  1357. return 1
  1358. }
  1359. }
  1360.  
  1361.   ## record that $nick spoke (prevents desert detection from stopping,
  1362. ## when an user joins and starts the game with !ask)
  1363. if {![mx_str_ieq $nick $botnick]} {
  1364. mx_getcreate_userentry $nick $host
  1365. }
  1366.  
  1367.   ## any questions available?
  1368. if {[llength $qlist] == 0 && [mx_userquests_available] == 0} {
  1369. mxirc_say $channel [mc "%sSorry, my database is empty." "[banner] [botcolor boldtxt]"]
  1370. } elseif {$quizstate == "asked"} {
  1371. mxirc_notc $nick [mx_get_qtext "long"]
  1372. } elseif {$quizstate == "waittoask" && ![mx_str_ieq $nick $botnick]} {
  1373. ## no, user has to be patient
  1374. mxirc_notc $nick [mc "Please stand by, the next question comes in less than %d seconds." $quizconf(askdelay)]
  1375. } else {
  1376. ##
  1377. ## ok, now lets see, which question to ask (normal or user)
  1378. ##
  1379.  
  1380. ## clear old question
  1381. foreach k [array names theq] {
  1382. unset theq($k)
  1383. }
  1384.  
  1385. if {[mx_userquests_available]} {
  1386. ## select a user question
  1387. array set theq [lindex $userqlist $userqnumber]
  1388. set usergame 1
  1389. incr userqnumber
  1390. mx_log "--- asking a user question: $theq(Question)"
  1391. } else {
  1392. variable ok 0
  1393.  
  1394. global bestscore
  1395.  
  1396. while {!$ok} {
  1397.  
  1398. array set theq [lindex $qlist [mx_next_qnumber]]
  1399. set usergame 0
  1400.  
  1401. # skip question if author is about to win
  1402. if {[info exists theq(Author)] && [info exists userlist($theq(Author))]} {
  1403. array set auser $userlist($theq(Author))
  1404. if {$auser(score) >= [expr $quizconf(winscore) - 5]} {
  1405. mx_log "--- skipping question number $qnumber, author is about to win"
  1406. } else {
  1407. mx_log "--- asking question number $qnumber: $theq(Question)"
  1408. set ok 1
  1409. }
  1410. } else {
  1411. mx_log "--- asking question number $qnumber: $theq(Question)"
  1412. set ok 1
  1413. }
  1414.  
  1415.  
  1416. if {[info exists theq(Category)]} {
  1417.  
  1418. if {$theq(Category) == "Ratefragen" && $bestscore > 24} {
  1419. set ok 0
  1420. } elseif {$theq(Category) == "Schätzfragen"} {
  1421.  
  1422. if {[mx_quizzer_count] < 3} {
  1423. set ok 0
  1424. }
  1425. }
  1426. }
  1427.  
  1428. if {!$ok} {
  1429. foreach k [array names theq] {
  1430. unset theq($k)
  1431. }
  1432. }
  1433. incr qnumber
  1434. }
  1435. }
  1436. incr qnum_thisgame
  1437. if {$qnum_thisgame == 1} {
  1438. set timerankreset [unixtime]
  1439. mx_log "---- it's the no. $qnum_thisgame in this game, rank timer started at: [unixtime]"
  1440. mx_statslog "gamestart" [list $timerankreset]
  1441. } else {
  1442. mx_log "---- it's the no. $qnum_thisgame in this game."
  1443. }
  1444.  
  1445. if {[info exists theq(Category)]} {
  1446. if {$theq(Category) == "Schätzfragen"} {
  1447. global schaetzarray
  1448. foreach name [array names schaetzarray] {
  1449. unset schaetzarray($name)
  1450. }
  1451. utimer $schaetztime mx_schaetz_end
  1452. } elseif {$theq(Category) == "Ratefragen"} {
  1453. Rate_Start $nick $host $handle $channel $arg
  1454. return
  1455. }
  1456. }
  1457.  
  1458.  
  1459.  
  1460. ##
  1461. ## ok, set some minimal required fields like score, regexp and the tiplist.
  1462. ##
  1463.  
  1464. ## set regexp to match
  1465. if {![info exists theq(Regexp)]} {
  1466. ## mask all regexp special chars except "."
  1467. set aexp [mx_tweak_umlauts $theq(Answer)]
  1468. regsub -all "(\\+|\\?|\\*|\\^|\\$|\\(|\\)|\\\[|\\\]|\\||\\\\)" $aexp "\\\\\\1" aexp
  1469. # get #...# area tags for tipgeneration as regexp
  1470. regsub -all ".*\#(\[^\#\]*\)\#.*" $aexp "\\1" aexp
  1471. set theq(Regexp) $aexp
  1472. } else {
  1473. set theq(Regexp) [mx_tweak_umlauts $theq(Regexp)]
  1474. }
  1475.  
  1476.  
  1477. set subexp $theq(Answer)
  1478. # protect embedded numbers
  1479. if {[regexp "\[0-9\]+" $theq(Regexp)]} {
  1480. set newexp ""
  1481. set oldexp $theq(Regexp)
  1482. set theq(Oldexp) $oldexp
  1483.  
  1484. while {[regexp -indices "(\[0-9\]+)" $oldexp pair]} {
  1485. set subexp [string range $oldexp [lindex $pair 0] [lindex $pair 1]]
  1486. set newexp "${newexp}[string range $oldexp -1 [expr [lindex $pair 0] - 1]]"
  1487. if {[regexp -- $theq(Regexp) $subexp]} {
  1488. set newexp "${newexp}(^|\[^0-9\])${subexp}(\$|\[^0-9\])"
  1489. } else {
  1490. set newexp "${newexp}${subexp}"
  1491. }
  1492. set oldexp "[string range $oldexp [expr [lindex $pair 1] + 1] [string length $oldexp]]"
  1493. }
  1494. set newexp "${newexp}${oldexp}"
  1495. set theq(Regexp) $newexp
  1496. #mx_log "---- replaced regexp '$theq(Oldexp)' with '$newexp' to protect numbers."
  1497. }
  1498.  
  1499. ## set score
  1500. if {![info exists theq(Score)]} {
  1501. set theq(Score) 1
  1502. }
  1503.  
  1504.   ## obfs question (answer script stopper)
  1505. # [pending] done elsewhere
  1506. ##set theq(Question) [mx_obfs $theq(Question)]
  1507.  
  1508. ## set category
  1509. ## set anum [lsearch -exact $alist "Category"]
  1510. ## if {![info exists theq(Category)} {
  1511. ## set theq(Category) "unknown"
  1512. ##}
  1513.  
  1514. ## initialize tiplist
  1515. set anum 0
  1516. set tiplist ""
  1517. while {[info exists theq(Tip$anum)]} {
  1518. lappend tiplist $theq(Tip$anum)
  1519. incr anum
  1520. }
  1521. # No tips found? construct standard list
  1522. if {$anum == 0} {
  1523. set add "·"
  1524.  
  1525. # extract area of tip generation tags (side effect sets answer)
  1526. if {![regsub -all ".*\#(\[^\#\]*\)\#.*" $theq(Answer) "\\1" answer]} {
  1527. set answer $theq(Answer)
  1528. }
  1529.  
  1530. ## use tipcycle from questions or
  1531. ## generate less tips if all words shorter than $tipcycle
  1532. if {[info exists theq(Tipcycle)]} {
  1533. set limit $theq(Tipcycle)
  1534. } else {
  1535. set limit $quizconf(tipcycle)
  1536. ## check if at least one word long enough
  1537. set tmplist [lsort -command mx_cmp_length -decreasing [split $answer " "]]
  1538. # not a big word
  1539. if {[string length [lindex $tmplist 0]] < $quizconf(tipcycle)} {
  1540. set limit [string length [lindex $tmplist 0]]
  1541. }
  1542. }
  1543.  
  1544. for {set anum 0} {$anum < $limit} {incr anum} {
  1545. set tiptext ""
  1546. set letterno 0
  1547. for {set i 0} {$i < [string length $answer]} {incr i} {
  1548. if {([expr [expr $letterno - $anum] % $quizconf(tipcycle)] == 0) ||
  1549. ([regexp "\[- \.,`'\"\]" [string range $answer $i $i] foo])} {
  1550. set tiptext "$tiptext[string range $answer $i $i]"
  1551. if {[regexp "\[- \.,`'\"\]" [string range $answer $i $i] foo]} {
  1552. set letterno -1
  1553. }
  1554. } else {
  1555. set tiptext "$tiptext$add"
  1556. }
  1557. incr letterno
  1558. }
  1559. lappend tiplist $tiptext
  1560. }
  1561.  
  1562.   # reverse tips for numeric questions
  1563. if {[regexp "^\[0-9\]+$" $answer]} {
  1564. set foo ""
  1565. for {set i [expr [llength $tiplist] - 1]} {$i >= 0} {set i [expr $i - 1]} {
  1566. lappend foo [lindex $tiplist $i]
  1567. }
  1568. set tiplist $foo
  1569. }
  1570. }
  1571.  
  1572. ##
  1573. ## Now print question header and question
  1574. ##
  1575.  
  1576. mxirc_serv $channel [mx_get_qtext "short"]
  1577.  
  1578. set txt "[bannerspace] [botcolor question]"
  1579. if {[info exists theq(Category)]} {
  1580. set txt "$txt\($theq(Category)\) $theq(Question)"
  1581.  
  1582. if {[info exists theq(Category)]} {
  1583. if {$theq(Category) == "Schätzfragen"} {
  1584. set txt "$txt \[\00306Ihr habt\00310 $schaetztime \00306Sekunden, um eine Schätzung in arabischen Zahlen abzugeben.\]\003"
  1585. }
  1586. }
  1587.  
  1588. } else {
  1589. set txt "$txt$theq(Question)"
  1590. }
  1591.  
  1592. mxirc_serv $channel $txt
  1593.  
  1594. set quizstate "asked"
  1595. set tipno 0
  1596. set timeasked [unixtime]
  1597. global timetypasked
  1598. set timetypasked [clock clicks -milliseconds]
  1599. ## set up tip timer
  1600. utimer $quizconf(tipdelay) mx_timer_tip
  1601. }
  1602. }
  1603.  
  1604.  
  1605.  
  1606.  
  1607.  
  1608. proc mx_quizzer_count {} {
  1609. global quizconf userlist
  1610.  
  1611. set qnow [unixtime]
  1612. set usermax 0
  1613.  
  1614. foreach u [lsort -command mx_sortrank [array names userlist]] {
  1615.  
  1616. array set aa $userlist($u)
  1617. if {[expr $qnow - $aa(lastspoken)] <= $quizconf(useractivetime)} {
  1618. incr usermax
  1619. }
  1620. }
  1621. return $usermax
  1622. }
  1623.  
  1624.  
  1625.  
  1626. ## A user dislikes the question
  1627. proc moxquiz_user_revolt {nick host handle channel text} {
  1628. global revoltlist revoltmax tipno botnick quizstate
  1629. global userlist RateRunning raterevolt
  1630. global quizconf
  1631.  
  1632.   ## only accept revolts on the quizchannel
  1633. if {![mx_str_ieq $channel $quizconf(quizchannel)]} {
  1634. return
  1635. }
  1636.  
  1637. if {$quizstate == "asked" || $RateRunning == 1} {
  1638. if {$tipno < 1&&$RateRunning!=1} {
  1639. mxirc_action $channel [mc "does not react on revolts before at least one tip was given."]
  1640. return
  1641. }
  1642.  
  1643. ## ensure that the revolting user has an entry
  1644. if {![info exists userlist($nick)]} {
  1645. mx_getcreate_userentry $nick $host
  1646. }
  1647.  
  1648. ## calculate people needed to make a revolution (50% of active users)
  1649. mx_log "--- a game runs, !revolt. revoltmax = $revoltmax"
  1650. if {$revoltmax == 0} {
  1651. set now [unixtime]
  1652. foreach u [array names userlist] {
  1653. array set afoo $userlist($u)
  1654. if {[expr $now - $afoo(lastspoken)] <= $quizconf(useractivetime)} {
  1655. incr revoltmax
  1656. }
  1657. }
  1658. mx_log "---- active people are $revoltmax"
  1659. # one and two player shoud revolt "both"
  1660. if {$revoltmax > 2} {
  1661. set revoltmax [expr int(ceil(double($revoltmax) / 2))]
  1662. }
  1663. mx_log "---- people needed for a successful revolution: $revoltmax"
  1664. }
  1665.  
  1666. # records known users dislike
  1667. if {[info exists userlist($nick)]} {
  1668. array set anarray $userlist($nick)
  1669. set hostmask $anarray(mask)
  1670. if {[lsearch -exact $revoltlist $hostmask] == -1} {
  1671. #mxirc_quick_notc $nick [mc "Since you are revolting, you will be ignored for this question."]
  1672.  
  1673. if {[llength $revoltlist] < $revoltmax && $revoltmax > 0} {
  1674. mxirc_quick_action $channel [mc "sees that %s and %d other dislike the question, you need %d people." \
  1675. $nick [llength $revoltlist] $revoltmax]
  1676. }
  1677. lappend revoltlist $hostmask
  1678. set anarray(lastspoken) [unixtime]
  1679. set userlist($nick) [array get anarray]
  1680. mx_log "--- $nick is revolting, revoltmax is $revoltmax"
  1681. mx_statslog "revolt" [list [unixtime] $nick [llength $revoltlist] $revoltmax]
  1682. }
  1683. }
  1684. if {[llength $revoltlist] >= $revoltmax} {
  1685. set revoltmax 0
  1686. mx_log "--- solution forced by revolting."
  1687. mx_statslog "revoltsolve" [list [unixtime] $revoltmax]
  1688. #mxirc_action $channel [mc "will solve the question immediately."]
  1689.  
  1690. if {$RateRunning != 0} {
  1691.  
  1692. foreach t [utimers] {
  1693. set tname [lindex $t 1]
  1694.  
  1695. if {[lindex $t 1] == "RateTimeUp"||[lindex $t 1] == "RateDisplayRemainingTime"||[lindex $t 1] == "Rate_ShowResults"||[regexp $tname "Rate"]} {
  1696. killutimer [lindex $t 2]
  1697. }
  1698. }
  1699.  
  1700. RateTimesUp
  1701. set revoltlist ""
  1702. set revoltmax 0
  1703. set vokspamvar 0
  1704. set raterevolt 1
  1705. } else {
  1706. moxquiz_solve $botnick 0 {}
  1707. }
  1708. }
  1709. }
  1710. }
  1711.  
  1712.  
  1713. ## solve question
  1714. proc moxquiz_solve {handle idx arg} {
  1715. global quizstate theq banner bannerspace
  1716. global botnick lastsolvercount lastsolver timeasked
  1717. global quizconf
  1718.  
  1719. variable txt
  1720. variable answer
  1721. if {$quizstate != "asked"} {
  1722. mxirc_dcc $idx "There is no open question."
  1723. } else {
  1724. mx_answered
  1725. set lastsolver ""
  1726. set lastsolvercount 0
  1727.  
  1728. if {[mx_str_ieq $botnick $handle]} {
  1729. set txt [mc "%sAutomatically solved after %s." \
  1730. "[banner] [botcolor boldtxt]" [mx_duration $timeasked]]
  1731. } else {
  1732. set txt [mc "%sManually solved after %s by %s" \
  1733. "[banner] [botcolor boldtxt]" [mx_duration $timeasked] $handle]
  1734. }
  1735. mxirc_serv $quizconf(quizchannel) $txt
  1736.  
  1737. # remove area of tip generation tags
  1738. regsub -all "\#(\[^\#\]*\)\#" $theq(Answer) "\\1" answer
  1739. mxirc_say $quizconf(quizchannel) [mc "%sThe answer is:%s%s" \
  1740. "[bannerspace] [botcolor txt]" "[botcolor norm] [botcolor answer]" $answer]
  1741.  
  1742. # remove protection of numbers from regexp
  1743. if {[info exists theq(Oldexp)]} {
  1744. set theexp $theq(Oldexp)
  1745. } else {
  1746. set theexp $theq(Regexp)
  1747. }
  1748.  
  1749. #if {$answer != $theexp} {
  1750. # mxirc_say $quizconf(quizchannel) [mc "%sAnd should match:%s%s" \
  1751.   # "[bannerspace] [botcolor txt]" "[botcolor norm] [botcolor answer]" $theexp]
  1752. #}
  1753.  
  1754. mx_log "--- solved by $handle manually."
  1755. # schedule ask
  1756. utimer $quizconf(askdelay) mx_timer_ask
  1757. }
  1758. return 1
  1759. }
  1760.  
  1761.  
  1762. ## show a tip
  1763. proc moxquiz_tip {handle idx arg} {
  1764. global tipno quizstate banner bannerspace
  1765. global botnick tiplist
  1766. global quizconf theq
  1767.  
  1768. if {[info exists theq(Category)]} {
  1769. if {$theq(Category) == "Schätzfragen"} {
  1770. return
  1771. }
  1772. }
  1773.  
  1774.  
  1775. if {$quizstate == "asked"} {
  1776. if {$arg != ""} {
  1777. mxirc_dcc $idx "Extra tip \'$arg\' will be given."
  1778. set tiplist [linsert $tiplist $tipno $arg]
  1779. }
  1780. if {$tipno == [llength $tiplist]} {
  1781. # enough tips, solve!
  1782. set tipno 0
  1783. moxquiz_solve $botnick 0 {}
  1784. } else {
  1785. set tiptext [lindex $tiplist $tipno]
  1786. mxirc_say $quizconf(quizchannel) [mc "%sHint %d:" "[banner] [botcolor boldtxt]" [expr $tipno + 1]]
  1787. mxirc_say $quizconf(quizchannel) "[bannerspace] [botcolor tip]$tiptext"
  1788. foreach j [utimers] {
  1789. if {[lindex $j 1] == "mx_timer_tip"} {
  1790. killutimer [lindex $j 2]
  1791. }
  1792. }
  1793. mx_log "----- Tip number $tipno: $tiptext"
  1794. # only short delay after last tip
  1795. incr tipno
  1796. if {$tipno == [llength $tiplist]} {
  1797. utimer 15 mx_timer_tip
  1798. } else {
  1799. utimer $quizconf(tipdelay) mx_timer_tip
  1800. }
  1801. }
  1802. } else {
  1803. mxirc_dcc $idx "Sorry, no question is open."
  1804. }
  1805. return 1
  1806. }
  1807.  
  1808.  
  1809. ## schedule a userquest
  1810. proc moxquiz_userquest {nick host handle arg} {
  1811. global userqlist ignore_for_userquest
  1812. global quizconf usebadwords badwords
  1813. variable uanswer "" uquestion "" umatch ""
  1814. variable tmptext ""
  1815.  
  1816. if {$quizconf(userquestions) == "no"} {
  1817. mxirc_notc $nick [mc "Sorry, userquestions are disabled."]
  1818. return
  1819. }
  1820.  
  1821. if {[lsearch $ignore_for_userquest [string tolower $nick]] != -1 || [lsearch $ignore_for_userquest [maskhost $host]] != -1} {
  1822. mxirc_notc $nick "Sorry, you are not allowed to post userquestions at this time."
  1823. return
  1824. }
  1825.  
  1826. if {![onchan $nick $quizconf(quizchannel)]} {
  1827. mxirc_notc $nick [mc "Sorry, you MUST be in the quizchannel to ask questions."]
  1828. } else {
  1829. if {[mx_userquests_available] >= $quizconf(userqbufferlength)} {
  1830. mxirc_notc $nick [mc "Sorry, there are already %d user questions scheduled. Try again later." $quizconf(userqbufferlength)]
  1831. } elseif {[info exists usebadwords] && $usebadwords && [regexp -nocase "([join $badwords, "|"])" $arg]} {
  1832. mxirc_notc $nick [mc "Sorry, your userquest would trigger the badwords detection and will not be asked."]
  1833. } else {
  1834. set arg [mx_strip_colors $arg]
  1835. if {$quizconf(stripumlauts) == "yes"} {
  1836. set arg [mx_tweak_umlauts $arg]
  1837. }
  1838. if {[regexp "^(.+)::(.+)::(.+)$" $arg foo uquestion uanswer umatch] || \
  1839. [regexp "(.+)::(.+)" $arg foo uquestion uanswer]} {
  1840. set uquestion [string trim $uquestion]
  1841. set uanswer [string trim $uanswer]
  1842. set alist [list "Question" "$uquestion" "Answer" "$uanswer" "Author" "$nick" "Date" [ctime [unixtime]] "TipGiven" "no"]
  1843. if {$umatch != ""} {
  1844. set umatch [string trim $umatch]
  1845. lappend alist "Regexp" "$umatch"
  1846. set tmptext [mc " (regexp \"%s\")" $umatch]
  1847. }
  1848. lappend userqlist $alist
  1849.  
  1850. mxirc_notc $nick [mc "Your quest \"%s\" is scheduled with answer \"%s\"%s and will be asked after %d questions." \
  1851. $uquestion $uanswer $tmptext [expr [mx_userquests_available] - 1]]
  1852. mx_log "--- Userquest scheduled by $nick: \"$uquestion\"."
  1853. } else {
  1854. mxirc_notc $nick [mc "Wrong number of parameters. Use alike <question>::<answer>::<regexp>. The regexp is optional and used with care."]
  1855. mxirc_notc $nick [mc "You said: \"%s\". I recognize this as: \"%s\" and \"%s\", regexp: \"%s\"." \
  1856. $arg $uquestion $uanswer $umatch]
  1857. mx_log "--- userquest from $nick failed with: \"$arg\""
  1858. }
  1859. }
  1860. }
  1861. return
  1862. }
  1863.  
  1864.  
  1865. ## usertip
  1866. proc moxquiz_usertip {nick host handle arg} {
  1867. global quizstate usergame theq
  1868. global quizconf
  1869.  
  1870. if {[onchan $nick $quizconf(quizchannel)]} {
  1871. mx_log "--- Usertip requested by $nick: \"$arg\"."
  1872. if {$quizstate == "asked" && $usergame == 1} {
  1873. if {[info exists theq(Author)] && ![mx_str_ieq $nick $theq(Author)]} {
  1874. mxirc_notc $nick [mc "No, only %s can give tips here!" $theq(Author)]
  1875. } else {
  1876. moxquiz_tip $nick 0 $arg
  1877. if {$arg != ""} {
  1878. set theq(TipGiven) "yes"
  1879. }
  1880. }
  1881. } else {
  1882. mxirc_notc $nick [mc "No usergame running."]
  1883. }
  1884. } else {
  1885. mxirc_notc $nick [mc "Sorry, you MUST be in the quizchannel to give tips."]
  1886. }
  1887. return 1
  1888. }
  1889.  
  1890.  
  1891. ## usersolve
  1892. proc moxquiz_usersolve {nick host handle arg} {
  1893. global quizstate usergame theq
  1894.  
  1895. mx_log "--- Usersolve requested by $nick."
  1896. if {$quizstate == "asked" && $usergame == 1} {
  1897. if {[info exists theq(Author)] && ![mx_str_ieq $nick $theq(Author)]} {
  1898. mxirc_notc $nick [mc "No, only %s can solve this question!" $theq(Author)]
  1899. } else {
  1900. moxquiz_solve $nick 0 {}
  1901. }
  1902. } else {
  1903. mxirc_notc $nick [mc "No usergame running."]
  1904. }
  1905. return 1
  1906. }
  1907.  
  1908.  
  1909. bind msg - !adver mx_adver
  1910. ## advertisement
  1911. proc mx_adver {nick host handle arg} {
  1912. global botnick
  1913. global quizconf
  1914.  
  1915. mxirc_say $quizconf(quizchannel) "[banner] $botnick is a MoxQuizz © by Moxon <[email protected]>"
  1916. mxirc_say $quizconf(quizchannel) "[bannerspace] and can be downloaded from http://meta-x.de/moxquizz"
  1917.  
  1918. return 0
  1919. }
  1920.  
  1921.  
  1922. ## usercancel
  1923. proc moxquiz_usercancel {nick host handle arg} {
  1924. global quizstate usergame theq userqnumber userqlist
  1925. mx_log "--- Usercancel requested by $nick."
  1926. if {$quizstate == "asked" && $usergame == 1} {
  1927. if {[info exists theq(Author)] && ![mx_str_ieq $nick $theq(Author)]} {
  1928. mxirc_notc $nick [mc "No, only %s can cancel this question!" $theq(Author)]
  1929. } else {
  1930. mxirc_notc $nick [mc "Your question is canceled and will be solved."]
  1931. set theq(Comment) "canceled by user"
  1932. moxquiz_solve "user canceling" 0 {}
  1933. }
  1934. } elseif {[mx_userquests_available]} {
  1935. array set aq [lindex $userqlist $userqnumber]
  1936. if {[mx_str_ieq $aq(Author) $nick]} {
  1937. mxirc_notc $nick [mc "Your question \"%s\" will be skipped." $aq(Question)]
  1938. set aq(Comment) "canceled by user"
  1939. set userqlist [lreplace $userqlist $userqnumber $userqnumber [array get aq]]
  1940. incr userqnumber
  1941. } else {
  1942. mxirc_notc $nick [mc "Sorry, the next question is by %s." $aq(Author)]
  1943. }
  1944. } else {
  1945. mxirc_notc $nick [mc "No usergame running."]
  1946. }
  1947. return 1
  1948. }
  1949.  
  1950.  
  1951.  
  1952.  
  1953. ## ignore nick!*@* and *!ident@*.subdomain.domain for userquests for 45 minutes
  1954. proc moxquiz_userquest_ignore {nick host handle channel arg} {
  1955. global quizconf ignore_for_userquest
  1956.  
  1957. regsub -all " +" [string trim $arg] " " arg
  1958.  
  1959. variable nicks [split $arg]
  1960. variable n
  1961.  
  1962. for {set pos 0} {$pos < [llength $nicks]} {incr pos} {
  1963. set n [string tolower [lindex $nicks $pos]]
  1964. mxirc_notc $nick "Ignoring userquestions from $n for 45 minutes."
  1965. lappend ignore_for_userquest $n
  1966. if {[onchan $n $quizconf(quizchannel)]} {
  1967. lappend ignore_for_userquest [maskhost [getchanhost $n $quizconf(quizchannel)]]
  1968. } else {
  1969. lappend ignore_for_userquest "-!-@-"
  1970. }
  1971.  
  1972. }
  1973. timer 45 mx_timer_userquest_ignore_expire
  1974. return 1
  1975. }
  1976.  
  1977. ## unignore nick!*@* and *!ident@*.subdomain.domain for userquests for 45 minutes
  1978. proc moxquiz_userquest_unignore {nick host handle channel arg} {
  1979.   ## replace each [split $arg] and associated hostmask with some impossible values
  1980. global quizconf ignore_for_userquest
  1981.  
  1982. regsub -all " +" [string trim $arg] " " arg
  1983.  
  1984. variable nicks [split $arg]
  1985. variable n
  1986.  
  1987. for {set pos 0} {$pos < [llength $nicks]} {incr pos} {
  1988. set n [string tolower [lindex $nicks $pos]]
  1989. set listpos [lsearch -exact $ignore_for_userquest $n]
  1990. if {$listpos != -1} {
  1991. set ignore_for_userquest [lreplace $ignore_for_userquest $listpos [expr $listpos + 1] "@" "-!-@-"]
  1992. mxirc_notc $nick "User $n removed from ignore list for userquestions."
  1993. } else {
  1994. mxirc_notc $nick "User $n was not in the ignore list for userquestions."
  1995. }
  1996. }
  1997. return 1
  1998. }
  1999.  
  2000. ## lists current names on ignore for userquestions
  2001. proc moxquiz_userquest_clearignores {nick host handle channel arg} {
  2002. variable ignore_for_userquest
  2003. for {set pos 0} {$pos < [llength $ignore_for_userquest]} {incr pos 2} {
  2004. set ignore_for_userquest [lreplace $ignore_for_userquest $pos [expr $pos + 1] "@" "-!-@-"]
  2005. }
  2006. mxirc_notc $nick "Cleared ignore list for userquestions."
  2007. return 1
  2008. }
  2009.  
  2010. ## lists current names on ignore for userquestions
  2011. proc moxquiz_userquest_listignores {nick host handle channel arg} {
  2012. variable ignore_for_userquest
  2013. variable nicks ""
  2014. for {set pos 0} {$pos < [llength $ignore_for_userquest]} {incr pos 2} {
  2015. if {[lindex $ignore_for_userquest $pos] != "@"} {
  2016. lappend nicks [lindex $ignore_for_userquest $pos]
  2017. }
  2018. }
  2019. if {$nicks != ""} {
  2020. mxirc_notc $nick "Currently ignored for userquestions: $nicks"
  2021. } else {
  2022. mxirc_notc $nick "Currently ignoring nobody for userquestions."
  2023. }
  2024. return 1
  2025. }
  2026.  
  2027. ## removes the first two elements from ignore_for_userquest (nick and mask)
  2028. proc mx_timer_userquest_ignore_expire {} {
  2029. global ignore_for_userquest
  2030. set ignore_for_userquest [lreplace $ignore_for_userquest 0 1]
  2031. }
  2032.  
  2033. ## pubm !score to report scores
  2034. proc moxquiz_pub_score {nick host handle channel arg} {
  2035. global alltimestarsarray allstarsarray userlist
  2036. global quizconf
  2037.  
  2038. variable allstarspos
  2039. variable pos 0
  2040. variable target
  2041. variable self 0
  2042.  
  2043. if {![mx_str_ieq $channel $quizconf(quizchannel)]} {
  2044. return 0
  2045. } else {
  2046. set arg [string trim "$arg"]
  2047.  
  2048. if {$arg != "" && $arg != $nick} {
  2049. set target $arg
  2050. } else {
  2051. set target $nick
  2052. set self 1
  2053. }
  2054.  
  2055. # report rank entries
  2056. if {[info exists userlist($targ

URL: http://www.moxquiz.de

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.