Changeset 12


Ignore:
Timestamp:
09/30/06 19:18:54 (6 years ago)
Author:
james
Message:

add handling of reports in query

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TriviaEngine/TriviaEngine-sqlite.tcl

    r11 r12  
    8585 
    8686        if {($nick == "Greeneyez") || ($nick == "JamesOff")} { 
     87#<<< set a question's category 
    8788                if [regexp -nocase "^setcat (.+)" $cmd matches category] { 
    8889 
     
    116117                        } 
    117118                } 
     119#>>> 
     120 
     121#<<< handle reports 
     122                if [regexp -nocase {^report (help|list|fix|view|done)?( .+)?} $cmd matches func arg] { 
     123                        if {($func == "") || ($func == "help")} { 
     124                                puthelp "PRIVMSG $nick :Use: report (list|view|fix|done)" 
     125                                puthelp "PRIVMSG $nick :report list: see 10 reports" 
     126                                puthelp "PRIVMSG $nick :report view <id>: see the question and answer associated with a report" 
     127                                puthelp "PRIVMSG $nick :report fix <id> (question|answer) <new text>: update a question or answer" 
     128                                puthelp "PRIVMSG $nick :report done <id>: mark a report as done" 
     129                                return 0 
     130                        } 
     131 
     132                        if {$func == "list"} { 
     133                                putserv "PRIVMSG $nick :Gathering 10 trivia reports..." 
     134                                set sql "SELECT * FROM reports WHERE resolved = 'N' LIMIT 10" 
     135                                trivia_db_handle eval $sql result { 
     136                                        putserv "PRIVMSG $nick :$result(report_id): [format %10s $result(who)] $result(message)" 
     137                                } 
     138                                return 0 
     139                        } 
     140 
     141                        if {$func == "view"} { 
     142                                if {$arg == ""} { 
     143                                        puthelp "PRIVMSG $nick :Use: report view <id>" 
     144                                        return 0 
     145                                } 
     146 
     147                                set arg [string trim $arg] 
     148                                set arg [trivia_sqlite_escape $arg] 
     149                                set sql "SELECT * FROM reports, questions WHERE report_id = '$arg' AND reports.question_id = questions.question_id" 
     150                                trivia_db_handle eval $sql result { 
     151                                        putserv "PRIVMSG $nick :Report$trivia_c(purple) $result(report_id) $trivia_c(off)by$trivia_c(purple) $result(who) $trivia_c(off)on$trivia_c(blue) [clock format $result(when) -gmt 1]" 
     152                                        putserv "PRIVMSG $nick :Question: $result(question)" 
     153                                        putserv "PRIVMSG $nick :  Answer: $result(answer)" 
     154                                        putserv "PRIVMSG $nick :  Report: $result(message)" 
     155                                } 
     156                                return 0 
     157                        } 
     158 
     159                        if {$func == "fix"} { 
     160                                set arg [string trim $arg] 
     161                                if [regexp -nocase {([0-9]+) (question|answer) (.+)} $arg matches report_id thing fix] { 
     162                                        putserv "PRIVMSG $nick :Attempting to fix $trivia_c(purple)$thing$trivia_c(off) from report$trivia_c(purple) $report_id" 
     163                                        #get question ID for this report 
     164                                        set sql "SELECT question_id FROM reports WHERE report_id = '$report_id'" 
     165                                        putloglev d * $sql 
     166                                        set question_id 0 
     167                                        trivia_db_handle eval $sql result { 
     168                                                set question_id $result(question_id) 
     169                                        } 
     170                                         
     171                                        if {$question_id == 0} { 
     172                                                putserv "PRIVMSG $nick :I can't seem to find that report, sorry :(" 
     173                                                return 0 
     174                                        } 
     175 
     176                                        set fix [trivia_sqlite_escape $fix] 
     177                                        set sql "UPDATE questions SET $thing = '$fix' WHERE question_id = '$question_id'" 
     178                                        putloglev d * $sql 
     179                                        trivia_db_handle eval $sql 
     180 
     181                                        putserv "PRIVMSG $nick :Updated!" 
     182                                        return 0 
     183                                } else { 
     184                                        puthelp "PRIVMSG $nick :Use: report fix <id> (question|answer) <new text>" 
     185                                        return 0 
     186                                } 
     187                        } 
     188 
     189                        if {$func == "done"} { 
     190                                set arg [string trim $arg] 
     191                                set arg [trivia_sqlite_escape $arg] 
     192                                putserv "PRIVMSG $nick :Marking report$trivia_c(purple) $arg $trivia_c(off)as done." 
     193                                set sql "UPDATE reports SET resolved = 'Y' WHERE report_id = '$arg'" 
     194                                putloglev d * $sql 
     195                                trivia_db_handle eval $sql 
     196                                return 0 
     197                        } 
     198                } 
     199#>>> 
    118200        } 
    119201} 
Note: See TracChangeset for help on using the changeset viewer.