Przeglądaj źródła

dictionary: Add way to add chatty responses

Will Storey 8 lat temu
rodzic
commit
54a662f66f
1 zmienionych plików z 19 dodań i 0 usunięć
  1. 19 0
      dictionary.tcl

+ 19 - 0
dictionary.tcl

@@ -180,6 +180,17 @@ proc ::dictionary::publearn {nick host hand chan argv} {
     return
   }
 
+  if {[regexp -nocase -- {^remember this:\s+(.+)} $rest -> response]} {
+    lappend ::dictionary::chatty_responses $response
+    if {[catch {::dictionary::list_to_file $::dictionary::chatty_responses \
+          $::dictionary::chatty_responses_file} err]} {
+      putserv "PRIVMSG $chan :Error! $err"
+      return
+    }
+    putserv "PRIVMSG $chan :OK, $nick."
+    return
+  }
+
   # Set a term. <botnick>: <term> is <definition>
   if {[regexp -nocase -- {^(.+?)\s+is\s+(.+)$} $rest -> term def]} {
     if {[dict exists $terms $term]} {
@@ -360,6 +371,14 @@ proc ::dictionary::file_contents_to_list {path} {
   return $l
 }
 
+proc ::dictionary::list_to_file {l path} {
+  set fh [open $path w]
+  foreach e $l {
+    puts $fh $e
+  }
+  close $fh
+}
+
 # Load a list of nicks to skip from a data file.
 proc ::dictionary::load_skip_nicks {} {
   set ::dictionary::skip_nicks [::dictionary::file_contents_to_list \