forked from molo1134/rigs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rigs.tcl
95 lines (77 loc) · 2.3 KB
/
rigs.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# !rig irc command -- 2-clause BSD license.
#
# Copyright (c) 2018 /u/molo1134. All rights reserved.
bind pub - !rig rig_pub
bind msg - !rig rig_msg
set rigscsv "rigs.csv"
proc rig_msg {nick uhand handle input} {
set rig [sanitize_string [string trim ${input}]]
set rig [encoding convertfrom utf-8 ${rig}]
putlog "rig msg: $nick $uhand $handle $rig"
set output [getrig $rig]
set output [split $output "\n"]
foreach line $output {
if { [string match -nocase "*potato*" $line] } {
# this is a hack to work around tcl's lack of support for unicode above
# U+FFFF.
putmsg $nick "$line"
} else {
putmsg $nick [encoding convertto utf-8 "$line"]
}
}
}
proc rig_pub { nick host hand chan text } {
set rig [sanitize_string [string trim ${text}]]
set rig [encoding convertfrom utf-8 ${rig}]
putlog "rig pub: $nick $host $hand $chan $rig"
set output [getrig $rig]
set output [split $output "\n"]
foreach line $output {
if { [string match -nocase "*potato*" $line] } {
# this is a hack to work around tcl's lack of support for unicode above
# U+FFFF.
putchan $chan "$line"
} else {
putchan $chan [encoding convertto utf-8 "$line"]
}
}
}
proc getrig {rig} {
global rigscsv
if { ![file exists $rigscsv] } {
return ""
}
set csvfile [open $rigscsv r]
while {![eof $csvfile]} {
set line [gets $csvfile]
if { ( [string match -nocase "*potato*" $line] == 0) } {
# this is a hack to work around tcl's lack of support for unicode above
# U+FFFF.
set line [encoding convertfrom utf-8 $line]
}
if {[regexp -- {^#} $line]} {
continue;
}
if {[regexp -- {^\s*$} $line]} {
continue;
}
set fields [split $line ","]
set rxp [lindex $fields 0]
set manuf [lindex $fields 1]
set model [lindex $fields 2]
set link [lindex $fields 3]
set manualpdf [lindex $fields 4]
set re {^[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,\"([^\"]*)\"$}
regexp $re $line -> desc
if {[string match -nocase "*${rig}*" $model]} {
close $csvfile
return "$manuf $model: $desc"
}
if {[regexp -nocase -- $rxp $rig]} {
close $csvfile
return "$manuf $model: $desc"
}
}
close $csvfile
return "not found; pull requests accepted: http://github.com/molo1134/rigs/"
}