-
Notifications
You must be signed in to change notification settings - Fork 11
/
coinchoose.tcl
executable file
·240 lines (217 loc) · 8.55 KB
/
coinchoose.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#
# Coinchoose Informations
#
# Copyright: 2014, iAmShorty
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
######################################################################
########## nothing to edit below this line ##########
########## use config.tcl for setting options ##########
######################################################################
#
# info for specific coin form coinchoose
#
proc coinchoose_info {nick host hand chan arg} {
global help_blocktime help_blocked channels debug debugoutput output onlyallowregisteredusers output_coinchoose command_protect
if {$debug eq "1"} { putlog "running proc [dict get [info frame 0] proc]" }
if {$onlyallowregisteredusers eq "1"} {
if {[check_registereduser $chan $nick] eq "false"} {
putquick "NOTICE $nick :you are not allowed to use this command"
putquick "NOTICE $nick :please use !request command to get access to the bot"
return
}
}
if {$arg eq "" || [llength $arg] < 1} {
if {$debug eq "1"} { putlog "wrong arguments, must be !coininfo coinname" }
return
}
set mask [string trimleft $host ~]
regsub -all {@([^\.]*)\.} $mask {@*.} mask
set mask *!$mask
if {[info exists help_blocked($mask)]} {
putquick "NOTICE $nick :You have been blocked for $help_blocktime Seconds, please be patient..."
return
}
if {$command_protect eq "1"} {
if {[channel_command_acl $chan "coinchoose"] eq "False"} {
putquick "PRIVMSG $chan :command !coinchoose not allowed in $chan"
return
}
}
set coinchoose_api "http://www.coinchoose.com/api.php?base=BTC"
set data [check_httpdata $coinchoose_api]
if { [regexp -nocase {error} $data] } {
putlog $data
return
}
if {$debugoutput eq "1"} { putlog "xml: $data" }
set results [::json::json2dict $data]
set coin_found "false"
set coinchoose_name "0"
set coinchoose_algo "0"
set coinchoose_currentblocks "0"
set coinchoose_diff "0"
set coinchoose_exchange "0"
set coinchoose_price "0"
set coinchoose_reward "0"
set coinchoose_networkhashrate "0"
set coinchoose_avgprofit "0"
set coinchoose_avghashrate "0"
set coinchoose_nethashratevalue "0"
set coinchoose_avgnethashratevalue "0"
if {$debug eq "1"} { putlog "Search on coinchoose for [string toupper $arg]" }
foreach key $results {
foreach {value sub_value} $key {
#putlog "value: $value - sub_value: $sub_value"
if {$value eq "0" && $sub_value eq [string toupper $arg]} {
#putlog "--> coin found"
set coin_found "true"
}
if {$value eq "name"} { set coinchoose_name "$sub_value" }
if {$value eq "algo"} { set coinchoose_algo "$sub_value" }
if {$value eq "currentBlocks"} { set coinchoose_currentblocks "$sub_value" }
if {$value eq "difficulty"} { set coinchoose_diff "$sub_value" }
if {$value eq "exchange"} {
#set coinchoose_exchange "$sub_value"
#set coinchoose_networkhashrate "$sub_value"
if {$sub_value eq "0" ||$sub_value eq "null" || $sub_value eq ""} {
set coinchoose_exchange "n/a"
} else {
set coinchoose_exchange $sub_value
}
}
if {$value eq "price"} {
if {$sub_value eq "null"} {
set coinchoose_price "0"
} else {
set coinchoose_price [format "%0.8f" $sub_value]
}
}
if {$value eq "reward"} {
if {$sub_value eq "null"} {
set coinchoose_reward "0"
} else {
set coinchoose_reward [format "%0.2f" $sub_value]
}
}
if {$value eq "networkhashrate"} {
#set coinchoose_networkhashrate "$sub_value"
if {$sub_value eq "0" || $sub_value eq "null"} {
set coinchoose_nethashratedevider 0
set coinchoose_nethashratevalue ""
set coinchoose_networkhashrate "n/a"
} else {
if {[string match *.* $sub_value]} {
set sub_value [format "%0.0f" $sub_value]
}
if {[string length $sub_value] <= 3 } {
set coinchoose_nethashratedevider 1
set coinchoose_nethashratevalue "H/s"
} elseif {[string length $sub_value] <= 6 } {
set coinchoose_nethashratedevider 1000
set coinchoose_nethashratevalue "KH/s"
} elseif {[string length $sub_value] <= 9 } {
set coinchoose_nethashratedevider 1000000
set coinchoose_nethashratevalue "MH/s"
} elseif {[string length $sub_value] <= 12 } {
set coinchoose_nethashratedevider 1000000000
set coinchoose_nethashratevalue "GH/s"
} elseif {[string length $sub_value] <= 15 } {
set coinchoose_nethashratedevider 1000000000000
set coinchoose_nethashratevalue "TH/s"
} elseif {[string length $sub_value] <= 18 } {
set coinchoose_nethashratedevider 1000000000000000
set coinchoose_nethashratevalue "PH/s"
} else {
set coinchoose_nethashratedevider 1
set coinchoose_nethashratevalue "H/s"
}
set coinchoose_networkhashrate [format "%.2f" [expr {double(double($sub_value)/double($coinchoose_nethashratedevider))}]]
}
}
if {$value eq "avgProfit"} {
if {$sub_value eq "null"} {
set coinchoose_avgprofit "0"
} else {
set coinchoose_avgprofit [format "%0.2f" $sub_value]
}
}
if {$value eq "avgHash"} {
#set coinchoose_avghash "$sub_value"
if {$sub_value eq "0" || $sub_value eq "null"} {
set coinchoose_avghashrate "n/a"
set coinchoose_avgnethashratedevider 0
set coinchoose_avgnethashratevalue ""
} else {
if {[string match *.* $sub_value]} {
set sub_value [format "%0.0f" $sub_value]
}
if {[string length $sub_value] <= 3 } {
set coinchoose_avgnethashratedevider 1
set coinchoose_avgnethashratevalue "H/s"
} elseif {[string length $sub_value] <= 6 } {
set coinchoose_avgnethashratedevider 1000
set coinchoose_avgnethashratevalue "KH/s"
} elseif {[string length $sub_value] <= 9 } {
set coinchoose_avgnethashratedevider 1000000
set coinchoose_avgnethashratevalue "MH/s"
} elseif {[string length $sub_value] <= 12 } {
set coinchoose_avgnethashratedevider 1000000000
set coinchoose_avgnethashratevalue "GH/s"
} elseif {[string length $sub_value] <= 15 } {
set coinchoose_avgnethashratedevider 1000000000000
set coinchoose_avgnethashratevalue "TH/s"
} elseif {[string length $sub_value] <= 18 } {
set coinchoose_avgnethashratedevider 1000000000000000
set coinchoose_avgnethashratevalue "PH/s"
} else {
set coinchoose_avgnethashratedevider 1
set coinchoose_avgnethashratevalue "H/s"
}
set coinchoose_avghashrate [format "%.2f" [expr {double(double($sub_value)/double($coinchoose_avgnethashratedevider))}]]
}
}
}
if {$coin_found eq "true"} {
break
}
}
if {$coin_found eq "true"} {
set lineoutput $output_coinchoose
set lineoutput [replacevar $lineoutput "%coinchoose_name%" $coinchoose_name]
set lineoutput [replacevar $lineoutput "%coinchoose_algo%" $coinchoose_algo]
set lineoutput [replacevar $lineoutput "%coinchoose_currentblocks%" $coinchoose_currentblocks]
set lineoutput [replacevar $lineoutput "%coinchoose_diff%" $coinchoose_diff]
set lineoutput [replacevar $lineoutput "%coinchoose_exchange%" $coinchoose_exchange]
set lineoutput [replacevar $lineoutput "%coinchoose_price%" $coinchoose_price]
set lineoutput [replacevar $lineoutput "%coinchoose_reward%" $coinchoose_reward]
set lineoutput [replacevar $lineoutput "%coinchoose_networkhashrate%" $coinchoose_networkhashrate]
set lineoutput [replacevar $lineoutput "%coinchoose_networkhashratevalue%" $coinchoose_nethashratevalue]
set lineoutput [replacevar $lineoutput "%coinchoose_avgprofit%" $coinchoose_avgprofit]
set lineoutput [replacevar $lineoutput "%coinchoose_avghashrate%" $coinchoose_avghashrate]
set lineoutput [replacevar $lineoutput "%coinchoose_avghashvalue%" $coinchoose_avgnethashratevalue]
} else {
set lineoutput "cannot find coin -> [string toupper $arg]"
}
if {$output eq "CHAN"} {
putquick "PRIVMSG $chan :$lineoutput"
} elseif {$output eq "NOTICE"} {
putquick "NOTICE $nick :$lineoutput"
} else {
putquick "PRIVMSG $chan :please set output in config file"
}
set help_blocked($mask) 1
utimer $help_blocktime [ list unset help_blocked($mask) ]
}
putlog "===>> Mining-Pool-Coinchoose - Version $scriptversion loaded"