Selaa lähdekoodia

Remember a default location and use it if none is given

Will Storey 9 vuotta sitten
vanhempi
commit
c8868de185
1 muutettua tiedostoa jossa 37 lisäystä ja 2 poistoa
  1. 37 2
      weather-darksky.tcl

+ 37 - 2
weather-darksky.tcl

@@ -24,7 +24,7 @@ namespace eval ::wds {
 proc ::wds::lookup_current {nick uhost hand chan argv} {
 	if {![channel get $chan weather-darksky]} { return }
 
-	set query [string trim $argv]
+	set query [::wds::get_query $nick $uhost $argv]
 	if {$query == ""} {
 		$::wds::output_cmd "PRIVMSG $chan :Usage: .wz <location>"
 		return
@@ -43,7 +43,7 @@ proc ::wds::lookup_current {nick uhost hand chan argv} {
 proc ::wds::lookup_forecast {nick uhost hand chan argv} {
 	if {![channel get $chan weather-darksky]} { return }
 
-	set query [string trim $argv]
+	set query [::wds::get_query $nick $uhost $argv]
 	if {$query == ""} {
 		$::wds::output_cmd "PRIVMSG $chan :Usage: .wzf <location>"
 		return
@@ -59,6 +59,41 @@ proc ::wds::lookup_forecast {nick uhost hand chan argv} {
 	::wds::output_forecast $chan $geonames $darksky
 }
 
+# Retrieve the query to look up. If none is given, return the last one we used.
+# If one was given, remember it.
+#
+# We only remember it if there is a matching user record. In theory we could add
+# users but in order to do that we must have a handle to assign them, and what
+# to use is unclear. I suppose we could generate something random.
+proc ::wds::get_query {nick uhost argv} {
+	set query [string trim $argv]
+	if {$query != ""} {
+		::wds::set_default_location $nick $uhost $query
+		return $query
+	}
+
+	return [::wds::get_default_location $nick $uhost]
+}
+
+proc ::wds::set_default_location {nick uhost query} {
+	set hand [finduser $nick!$uhost]
+	if {$hand == "*"} {
+		return
+	}
+
+	setuser $hand XTRA weather-darksky $query
+}
+
+proc ::wds::get_default_location {nick uhost} {
+	set hand [finduser $nick!$uhost]
+	if {$hand == "*"} {
+		return ""
+	}
+
+	set location [getuser $hand XTRA weather-darksky]
+	return $location
+}
+
 proc ::wds::get_data {chan query} {
 	set conf [::wds::load_config]