-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbasics.tcl
294 lines (256 loc) · 8.58 KB
/
basics.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#
# Basic TCL Commands used in MPOS Api Scripts
#
# 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 ##########
######################################################################
#
# key bindings
#
bind pub - !pool pool_info
bind pub - !block block_info
bind pub - !last last_info
bind pub - !user user_info
bind pub - !round round_info
bind pub - !worker worker_info
bind pub - !balance balance_info
bind pub - !price price_info
bind pub - !coinchoose coinchoose_info
bind pub - !request user_request
bind pub - ?help printUsage
bind pub - !help printUsage
bind pub - !hashrate pool_hashrate
bind pub - !diff pool_diff
bind pub - !calc calc_income
bind pub no|- !adduser user_add
bind pub no|- !deluser user_del
bind pub no|- !addpool pool_add
bind pub no|- !delpool pool_del
bind pub no|- !pools pool_list
bind pub no|- !blockfinder announce_blockfinder
bind pub no|- !announce announce_channel
bind pub no|- !command channel_commands
bind msg no|- !apikey pool_apikey
#
# check for required packages
#
if {[catch {package require http 2.5}]} {
if {$debug eq "1"} { putlog "Eggdrop: package http 2.5 or above required" }
die "Eggdrop: package http 2.5 or above required"
}
if {[catch {package require json}]} {
if {$debug eq "1"} { putlog "Eggdrop: package json required" }
die "Eggdrop: package json required"
}
if {[catch {package require tls}]} {
if {$debug eq "1"} { putlog "Eggdrop: package tls required" }
die "Eggdrop: package tls required"
}
if {[catch {package require sqlite3}]} {
if {$debug eq "1"} { putlog "Eggdrop: package sqlite3 required" }
die "Eggdrop: package sqlite3 required"
}
#
# unset arrays for userdefined ouput when rehashing the bot, otherwise the
# array variables are always present, even if they are commented out. arrays are set
# again if output.tcl is loaded and variables are not commented out
#
if {[array exists output_balance_percoin]} { unset output_balance_percoin }
if {[array exists output_blockinfo_percoin]} { unset output_blockinfo_percoin }
if {[array exists output_lastblock_percoin]} { unset output_lastblock_percoin }
if {[array exists output_findblocks_percoin]} { unset output_findblocks_percoin }
if {[array exists output_poolstats_percoin]} { unset output_poolstats_percoin }
if {[array exists output_roundstats_percoin]} { unset output_roundstats_percoin }
if {[array exists output_userstats_percoin]} { unset output_userstats_percoin }
if {[array exists output_workerinfo_percoin]} { unset output_workerinfo_percoin }
if {[array exists output_worker_offline_percoin]} { unset output_worker_offline_percoin }
if {[array exists output_worker_online_percoin]} { unset output_worker_online_percoin }
#
# getting the pool vars from dictionary
# set in config for specific pool
#
proc pool_vars {coinname} {
global sqlite_poolfile debug debugoutput
sqlite3 registeredpools $sqlite_poolfile
if {$debug eq "1"} { putlog "running proc [dict get [info frame 0] proc]" }
set pool_found "false"
if {[llength [registeredpools eval {SELECT apikey FROM pools WHERE coin=$coinname}]] != 0} {
set poolscount [registeredpools eval {SELECT COUNT(1) FROM pools WHERE apikey != 0 AND coin == $coinname}]
if {$debug eq "1"} { putlog "Number of Pools: $poolscount" }
foreach {apiurl poolcoin apikey} [registeredpools eval {SELECT url,coin,apikey FROM pools WHERE apikey != 0 AND coin == $coinname} ] {
if {[string toupper $poolcoin] eq [string toupper $coinname]} {
set pool_found "true"
set apiurl [string trimright $apiurl "/"]
set pool_data "[string toupper $poolcoin] $apiurl $apikey"
}
}
} else {
if {$debug eq "1"} { putlog "API Key for Pool not found" }
}
registeredpools close
if {$pool_found eq "true"} {
return $pool_data
} else {
return "0"
}
}
#
# getting the user status
#
proc check_userrights {nick} {
global debug debugoutput
if {$debug eq "1"} { putlog "running proc [dict get [info frame 0] proc]" }
if {[matchattr $nick +n]} {
putlog "$nick is botowner"
return "true"
} else {
return "false"
}
}
#
# getting the user status
#
proc check_registereduser {chan nick} {
global debug debugoutput
if {$debug eq "1"} { putlog "running proc [dict get [info frame 0] proc]" }
set hostmask "$nick!*[getchanhost $nick $chan]"
if {[check_mpos_user $nick $hostmask] eq "false"} {
return "false"
} else {
return "true"
}
}
#
# checking http data
#
proc check_httpdata {url} {
global debug debugoutput http_query_timeout
if {$debug eq "1"} { putlog "running proc [dict get [info frame 0] proc]" }
set returnvalue ""
if {[string match "*https*" [string tolower $url]]} {
set usehttps 1
} else {
set usehttps 0
}
if {$usehttps eq "1"} {
::http::register https 443 tls::socket
}
if {[catch { set token [http::geturl $url -timeout $http_query_timeout]} error] == 1} {
if {$debug eq "1"} { putlog "$error" }
if {[info exists $token]} {
http::cleanup $token
}
set returnvalue "error - $error"
} elseif {[http::ncode $token] == "404"} {
if {$debug eq "1"} { putlog "Error: [http::code $token]" }
if {[info exists $token]} {
http::cleanup $token
}
set returnvalue "error - [http::code $token]"
} elseif {[http::status $token] == "ok"} {
set data [http::data $token]
if {[info exists $token]} {
http::cleanup $token
}
set returnvalue "success $data"
} elseif {[http::status $token] == "timeout"} {
if {$debug eq "1"} { putlog "Timeout occurred" }
if {[info exists $token]} {
http::cleanup $token
}
set returnvalue "error - Timeout occurred"
} elseif {[http::status $token] == "error"} {
if {$debug eq "1"} { putlog "Error: [http::error $token]" }
if {[info exists $token]} {
http::cleanup $token
}
set returnvalue "error - [http::error $token]"
}
if {$usehttps eq "1"} {
::http::unregister https
}
return $returnvalue
}
#
# ACL Command Check
#
proc channel_command_acl {channel command} {
global protected_commands sqlite_commands debug debugoutput
sqlite3 poolcommands $sqlite_commands
if {$debug eq "1"} { putlog "running proc [dict get [info frame 0] proc]" }
if {[lsearch $protected_commands $command] > 0 } {
regsub "#" $channel "" command_channel
if {[llength [poolcommands eval {SELECT command_id FROM commands WHERE channel=$command_channel AND command="$command" AND activated=1}]] != 0} {
if {$debug eq "1"} { putlog "-> command !balance found" }
return "True"
} elseif {[llength [poolcommands eval {SELECT command_id FROM commands WHERE channel=$command_channel AND command="all" AND activated=1}]] != 0} {
if {$debug eq "1"} { putlog "-> command ALL found" }
return "True"
} else {
if {$debug eq "1"} { putlog "-> protected" }
return "False"
}
} else {
if {$debug eq "1"} { putlog "-> not protected" }
return "True"
}
}
#
# replace variables
#
proc replacevar {string cookie value} {
global debug debugoutput
if {$debug eq "1"} { putlog "running proc [dict get [info frame 0] proc]" }
variable zeroconvert
if {[string length $value] == 0 && [info exists zeroconvert($cookie)]} {
set value $zeroconvert($cookie)
}
return [string map [list $cookie $value] $string]
}
#
# wordwrap proc that accepts multiline data
# (empty lines will be stripped because there's no way to relay them via irc)
#
proc wordwrap {data len} {
global debug debugoutput
if {$debug eq "1"} { putlog "running proc [dict get [info frame 0] proc]" }
set out {}
foreach line [split [string trim $data] \n] {
set curr {}
set i 0
foreach word [split [string trim $line]] {
if {[incr i [string len $word]]>$len} {
lappend out [join $curr]
set curr [list $word]
set i [string len $word]
} {
lappend curr $word
}
incr i
}
if {[llength $curr]} {
lappend out [join $curr]
}
}
set out
}
#
# character filter
#
proc charfilter {arg} { return [string map {"\\" "\\\\" "\{" "\\\{" "\}" "\\\}" "\[" "\\\[" "\]" "\\\]" "\'" "\\\'" "\"" "\\\""} $arg] }
putlog "===>> Mining-Pool-Basics - Version $scriptversion loaded"