Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F11724025
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/Nasqueron/GIS.tcl b/Nasqueron/GIS.tcl
new file mode 100644
--- /dev/null
+++ b/Nasqueron/GIS.tcl
@@ -0,0 +1,67 @@
+# Geographical data procs
+
+bind pub - !fantoir pub:fantoir
+bind dcc - fantoir dcc:fantoir
+
+namespace eval fantoir {
+ #Path to the FANTOIR file
+ variable file_all [registry get fantoir.files.all]
+
+ #Path to the FANTOIR file, containing only streets
+ variable file_streets [registry get fantoir.files.streets]
+
+ # Performs a search
+ #
+ # @param text The text to search
+ # @return the number of lines in the file matching the expression
+ proc search {text} {
+ variable file_all
+ variable file_streets
+
+ if {[catch {set count_all [exec -- grep -a -c "$text" $file_all]}]} {
+ set count_all 0
+ }
+ set count_all [string trim $count_all]
+ set reply "$count_all occurrence[s $count_all]"
+ if {$count_all > 0} {
+ if {[catch {set count_voies [exec -- grep -a -c "$text" $file_streets]}]} {
+ set count_voies 0
+ }
+ set count_voies [string trim $count_voies]
+ append reply "(dont $count_voies voie[s $count_voies])"
+ } {
+ return $reply
+ }
+ }
+
+ # Determines if a search expression is valid
+ #
+ # @param $expression The expression to check
+ # @return 1 if the expression is valid; otherwise, 0
+ proc is_valid_search_expression {expression} {
+ #TODO: allow some regexp
+ expr [regexp "^\[A-Z0-9 ]*\$" $expression] && [string length $expression] < 100
+ }
+}
+
+# Handles fantoir dcc bind
+proc dcc:fantoir {handle idx arg} {
+ set text [string toupper $arg]
+ if {![::fantoir::is_valid_search_expression $text]} {
+ putdcc $idx "Format incorrect, !fantoir <chaîne de texte à rechercher, sans accent>"
+ return 0
+ }
+ putdcc $idx [::fantoir::search $text]
+ return 1
+}
+
+# Handles !fantoir pub bind
+proc pub:fantoir {nick uhost handle chan text} {
+ set text [string toupper $text]
+ if {![::fantoir::is_valid_search_expression $text]} {
+ puthelp "NOTICE $nick :Format incorrect, !fantoir <chaîne de texte à rechercher, sans accent>"
+ return 0
+ }
+ putserv "PRIVMSG $chan :$nick: [::fantoir::search $text]"
+ return 1
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Sep 18, 12:25 (14 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2990801
Default Alt Text
(2 KB)
Attached To
Mode
rVIPERSERV ViperServ scripts [legacy Mercurial repo]
Attached
Detach File
Event Timeline
Log In to Comment