-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpools.tcl
185 lines (158 loc) · 6.57 KB
/
pools.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
#
# Pool 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 ##########
######################################################################
#
# add pools from database
#
proc pool_add {nick uhost hand chan arg} {
global debug sqlite_poolfile
sqlite3 registeredpools $sqlite_poolfile
if {$debug eq "1"} { putlog "running proc [dict get [info frame 0] proc]" }
if {[check_userrights $nick] eq "false"} {
if {$debug eq "1"} { putlog "$nick tried to add $arg to pools" }
return
}
set userarg [charfilter $nick]
set hostmask "$userarg!*[getchanhost $userarg $chan]"
if {[llength $arg] != "4"} {
putquick "PRIVMSG $chan :wrong arguments, should be !addpool POOLURL COINNAME PAYOUTSYSTEM FEE"
return
}
set pool_url [string tolower [lindex $arg 0]]
set pool_url [string trimright $pool_url "/"]
set pool_coin [string toupper [lindex $arg 1]]
set pool_payout [string toupper [lindex $arg 2]]
set pool_fee [lindex $arg 3]
set actualtime [unixtime]
set data [check_httpdata $pool_url]
if { [regexp -nocase {error} $data] } {
putlog $data
return
}
if {[llength [registeredpools eval {SELECT coin FROM pools WHERE coin=$pool_coin}]] == 0} {
if {[llength [registeredpools eval {SELECT url FROM pools WHERE url=$pool_url}]] == 0} {
if {$debug eq "1"} { putlog "adding pool" }
putquick "PRIVMSG $chan :pool $pool_url added"
registeredpools eval {INSERT INTO pools (url,coin,payoutsys,fees,user,timestamp) VALUES ($pool_url,$pool_coin,$pool_payout,$pool_fee,$userarg,$actualtime)}
} else {
if {$debug eq "1"} { putlog "updating pool" }
putquick "PRIVMSG $chan :pool $pool_url updated"
registeredpools eval {UPDATE pools SET url=$pool_url, coin=$pool_coin, payoutsys=$pool_payout, fees=$pool_fee, user=$userarg WHERE url=$pool_url}
}
} else {
if {$debug eq "1"} { putlog "Pool for Coin $pool_coin already exists" }
putquick "PRIVMSG $chan :Pool for Coin $pool_coin already exists"
}
registeredpools close
}
#
# delete pools from database
#
proc pool_del {nick uhost hand chan arg} {
global debug sqlite_poolfile
sqlite3 registeredpools $sqlite_poolfile
if {$debug eq "1"} { putlog "running proc [dict get [info frame 0] proc]" }
if {[check_userrights $nick] eq "false"} {
if {$debug eq "1"} { putlog "$nick tried to delete $arg to pools" }
return
}
if {[llength $arg] != "1"} {
putquick "PRIVMSG $chan :wrong arguments, should be !delpool POOLURL"
return
}
set pool_url [string tolower $arg]
set pool_url [string trimright $pool_url "/"]
if {[llength [registeredpools eval {SELECT user FROM pools WHERE url=$pool_url}]] == 0} {
puthelp "PRIVMSG $chan :\002$pool_url\002 is not in the database."
} {
registeredpools eval {DELETE FROM pools WHERE url=$pool_url}
puthelp "PRIVMSG $chan :\002$pool_url\002 deleted."
}
registeredpools close
}
#
# add apikey to pool
#
proc pool_apikey {nick uhost hand arg} {
global debug sqlite_poolfile
sqlite3 registeredpools $sqlite_poolfile
if {$debug eq "1"} { putlog "running proc [dict get [info frame 0] proc]" }
if {[check_userrights $nick] eq "false"} {
if {$debug eq "1"} { putlog "$nick tried to add api key $arg to pools" }
return
}
if {[llength $arg] != "2"} {
putquick "NOTICE $nick :wrong arguments, should be /msg BOTNICK !apikey POOLURL APIKEY"
return
}
set pool_url [string tolower [lindex $arg 0]]
set pool_url [string trimright $pool_url "/"]
set api_key [lindex $arg 1]
if {[llength [registeredpools eval {SELECT url FROM pools WHERE url=$pool_url}]] != 0} {
if {$debug eq "1"} { putlog "-> adding api key" }
putquick "NOTICE $nick :added api key for $pool_url"
registeredpools eval {UPDATE pools SET apikey=$api_key WHERE url=$pool_url}
}
registeredpools close
}
#
# list pools from database
#
proc pool_list {nick uhost hand chan arg} {
global debug sqlite_poolfile
sqlite3 registeredpools $sqlite_poolfile
if {$debug eq "1"} { putlog "running proc [dict get [info frame 0] proc]" }
if {[check_userrights $nick] eq "false"} {
if {$debug eq "1"} { putlog "$nick tried to list $arg to pools" }
return
}
if {$arg eq ""} {
set scount [registeredpools eval {SELECT COUNT(1) FROM pools}]
foreach {url coin payout_sys fees} [registeredpools eval {SELECT url,coin,payoutsys,fees FROM pools} ] {
append outvar "\002Coin:\002 $coin -> \002URL:\002 $url -> \002Payout:\002 $payout_sys | \002Poolfee:\002 $fees %\n"
}
} elseif {[string tolower $arg] eq "enabled" || [string tolower $arg] eq "true" || [string tolower $arg] eq "1"} {
set scount [registeredpools eval {SELECT COUNT(1) FROM pools WHERE blockfinder = 1}]
foreach {url coin payout_sys fees} [registeredpools eval {SELECT url,coin,payoutsys,fees FROM pools WHERE blockfinder = 1} ] {
append outvar "\002Coin:\002 $coin -> \002URL:\002 $url -> \002Payout:\002 $payout_sys | \002Poolfee:\002 $fees %\n"
}
} elseif {[string tolower $arg] eq "disabled" || [string tolower $arg] eq "false" || [string tolower $arg] eq "0"} {
set scount [registeredpools eval {SELECT COUNT(1) FROM pools WHERE blockfinder = 0}]
foreach {url coin payout_sys fees} [registeredpools eval {SELECT url,coin,payoutsys,fees FROM pools WHERE blockfinder = 0} ] {
append outvar "\002Coin:\002 $coin -> \002URL:\002 $url -> \002Payout:\002 $payout_sys | \002Poolfee:\002 $fees %\n"
}
} else {
set poolcoin [string toupper $arg]
set scount [registeredpools eval {SELECT COUNT(1) FROM pools WHERE coin=$poolcoin}]
foreach {url coin payout_sys fees} [registeredpools eval {SELECT url,coin,payoutsys,fees FROM pools WHERE coin=$poolcoin} ] {
append outvar "\002Coin:\002 $poolcoin -> \002URL:\002 $url -> \002Payout:\002 $payout_sys | \002Poolfee:\002 $fees %\n"
}
}
putquick "PRIVMSG $chan :Number of Pools: $scount"
if {$scount != 0} {
set records [split $outvar "\n"]
foreach rec $records {
putquick "PRIVMSG $chan :$rec"
}
}
registeredpools close
}
putlog "===>> Mining-Pool-Pools - Version $scriptversion loaded"