Advertisement

08.18.2008 at 08:31AM PDT, ID: 23656719
[x]
Attachment Details

Help me tune this coding

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

3.8
Tags:

TCL

I've try modify some TCL scripts that i run with my eggdrops. The original scripts only can make the eggdrop send the SMS to contact list only.

Can any expert in TCL language here gave me some idea how to modify this scripts to made it send sms to open number ??
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:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
# packages
 
package require http
 
# vars
 
# script version
set smsver "2"
 
# work chan flags ..
setudef flag sms
 
# tag bottom of sms with irc nick and tagmsg ... 0=no 1=yes
set tagnick "0"
set tagname "0"
set tagmsg "0"
 
# datafile
set datfile "scripts/sms.dat"
 
# clickatell details
set user "test"
set pass "123qwe"
set id "3109069"
 
 
# shouldnt need to edit these urls below, but can be edited if clickatell change their
# url structure, or if you wish to attempt to adapt script to another sms gateway 
 
set urlcreds "http://api.clickatell.com/http/getbalance?api_id=SMSID&user=SMSUSER&password=SMSPASS"
set url "http://api.clickatell.com/http/sendmsg?api_id=SMSID&user=SMSUSER&password=SMSPASS&to=NUMTOSEND&text=MSGTOSEND"
 
 
########## DO NOT EDIT BELOW UNLESS YOU KNOW TCL! ##########
 
# binds
 
namespace eval sms {
    variable pubsmsadd {!smsadd}
    variable pubbalbind {!smscreds}
    variable pubnumbind {!number}
    variable pubverbind {!smsver}
    variable pubhelpbind {!smshelp}
    variable pubbind {!sms}
    bind PUB o|o $pubsmsadd [namespace current]::smsadd 
    bind PUB o|o $pubnumbind [namespace current]::number
    bind PUB -|- $pubbalbind [namespace current]::credspublic
    bind PUB -|- $pubverbind [namespace current]::smsver
    bind PUB -|- $pubhelpbind [namespace current]::smshelp
    bind PUB -|- $pubbind [namespace current]::public
    namespace export getnames credspublic public private
}
 
 
proc sms::smsadd {nickname hostname handle channel arguments} {
    global chan datfile
 
    if ![channel get $channel sms] return
 
    set args [split $arguments]
    set data ""
 
    # check args are correct
    if {($arguments < 1) || ([llength $args] < 2)} {
        putquick "PRIVMSG $channel :\[\002SMS\017\] \002Format:\002 !smsadd <name> <number>"
        return 0
    }
 
    # check if names already added
    if {[validfeed [lindex $args 0] 1]} {
        putquick "PRIVMSG $channel :\[\002SMS\017\] \002Error:\002 User already exists!"
        return 0
    }
 
    # make sure no letters in sms number
    if {![ string is digit [lindex $args 1] ] } {
        putquick "PRIVMSG $channel : [lindex $args 1]"
        putquick "PRIVMSG $channel :\[\002SMS\017\] \002Error:\002 letters detected in <number> entry"
        return 0
    }
 
    # Complain and exit if input file does not exist
    if {![ file exists $datfile ] }  	{
        putquick "PRIVMSG $channel :\[\002SMS\017\] \002Error: \002File \"$datfile\" not found!"
        return 0
    }
 
    # Complain and exit if input file is not readable
    if {![ file readable $datfile ] }  	{
        putquick "PRIVMSG $channel :\[\002SMS\017\] \002Error:\002 Permission denied to read $datfile!"
        return 0
    }
 
 
   # save sms data
    if { [ catch { set fileId [open $datfile a] } err ] }  {
        putquick "PRIVMSG $channel :\[\002SMS\017\] Error:\002 $err"
        return 0
    }
 
    puts $fileId [lindex $args 0]:[lindex $args 1]
    close $fileId
 
    putquick "PRIVMSG $channel :\[\002SMS\017\] \002Added:\002 Name: [lindex $args 0] Number: [lindex $args 1]"
}
 
 
proc sms::public {nickname hostname handle channel arguments} {
    global tagnick tagname tagmsg url urlcreds user pass id
    variable token
    set args [split $arguments]
 
    if ![channel get $channel sms] return
 
    if {($arguments < 1) || ([llength $args] < 2)} {
        putquick "PRIVMSG $channel :\002Format:\002 !sms <name> <message>"
        putquick "PRIVMSG $channel :."
        putquick "PRIVMSG $channel :Available entries:"
        putquick "PRIVMSG $channel :[getnames]"
        return 0
    }
 
    if {![validfeed [lindex $args 0] 1]} {             
        putquick "PRIVMSG $channel :\[\002SMS\017\] \002Error:\002 please choose one of the following names: "
        putquick "PRIVMSG $channel :[getnames]"
        return 0
    }
 
    set nick [lindex $args 0]
    set number "0"
    set number [getnumber $nick]
 
    if {($nick == "") || ($number == "0")} {
        putlog "RSS: Warning: Couldn't load configuration for the \[$id\] feed."
        putquick "PRIVMSG $channel :\002Error:\002 couldnt get number for that user."
        return 0
    }
 
    set arguments [lreplace $args 0 0]
 
    #add tag and nick - if set in config above
    if {$tagnick eq "1"} {  
        set arguments "$arguments %5b $handle %2f $channel %5d"
    }
    if {$tagname eq "1"} {
        set arguments "$arguments %5b $tagmsg %5d"
    }
 
    # regsub some common irc chars for unicode
    regsub -all " " $arguments "%20" arguments
    regsub -all "#" $arguments "%23" arguments 
    regsub -all "&" $arguments "%26" arguments 
    regsub -all "@" $arguments "%40" arguments
 
    # regsub details into sms url
    set realurl $url
    regsub -all NUMTOSEND $realurl $number realurl
    regsub -all MSGTOSEND $realurl $arguments realurl
    regsub -all SMSID $realurl $id realurl
    regsub -all SMSUSER $realurl $user realurl
    regsub -all SMSPASS $realurl $pass realurl
 
    # regsub details into urlcreds url
    set realurlcreds $urlcreds
    regsub -all SMSID $realurlcreds $id realurlcreds
    regsub -all SMSUSER $realurlcreds $user realurlcreds
    regsub -all SMSPASS $realurlcreds $pass realurlcreds
 
    set token [http::geturl $realurl]
    set data_frm_url [http::data $token]
 
    putquick "PRIVMSG $channel :\002Sent:\002 $arguments"
    putquick "PRIVMSG $channel :\002To:\002 [lindex $args 0] ($number)"
    putquick "PRIVMSG $channel :\002Response:\002 $data_frm_url"
 
    set token [http::geturl $realurlcreds]
    set bal_frm_url [http::data $token]
 
    putquick "PRIVMSG $channel :\002Credits:\002 $bal_frm_url"
}
 
proc sms::number {nickname hostname handle channel arguments} {
    global chan datfile
    set args [split $arguments]
 
    if ![channel get $channel sms] return
 
    if {($arguments < 1) || ([llength $args] < 1)} {
        putquick "PRIVMSG $channel :\[\002SMS\017\] \002Format:\002 !number <name>"
        putquick "PRIVMSG $channel :."
        putquick "PRIVMSG $channel :Available entries:"
        putquick "PRIVMSG $channel :[getnames]"
        return 0
    }
 
    if {![validfeed [lindex $args 0] 1]} {
        putquick "PRIVMSG $channel :\[\002SMS\017\] \002Error:\002 please choose one of the following names: "
        putquick "PRIVMSG $channel :[getnames]"
        return 0
    }
    
    set nick [lindex $args 0]
    set number "0"
    set number [getnumber $nick]
 
    if {($nick == "") || ($number == "0")} {
        putlog "RSS: Warning: Couldn't load configuration for the \[$id\] feed."
        putquick "PRIVMSG $channel :\002Error:\002 couldnt get number for that user."
        return 0
    }
 
    putquick "PRIVMSG $channel :\[\002SMS\017\] \002[lindex $args 0]:\002 $number"
}
 
 
proc sms::validfeed {keyword type} {
    global datfile
 
    # Complain and exit if file does not exist
    if {![ file exists $datfile ] }     {
        putquick "PRIVMSG $channel :\[\002SMS\017\] \002Error: \002File \"$datfile\" not found!"
        return 0
    }
 
    # Complain and exit if file is not readable
    if {![ file readable $datfile ] }   {
        putquick "PRIVMSG $channel :\[\002SMS\017\] \002Error:\002 Permission denied to read $datfile!"
        return 0
    }
 
    # read sms data
    if { [ catch { set fileId [open $datfile r] } err ] }  {
        putquick "PRIVMSG $channel :\[\002SMS\017\] Error:\002 $err"
        return 0
    }
 
    set names [list]
    while {![eof $fileId]} {
        set line [gets $fileId]
        set data [split $line ":"]
        if {$data != ""} {        
            lappend names [lindex $data 0]
        }
    }
    close $fileId
 
    foreach id $names {
        if {[string equal -nocase $id $keyword]} {
            switch -exact -- $type {
                {1} { return 1 }
                {2} { return $id }
            }
        }
    }
    return 0
}
 
 
proc sms::getnames { } {
    global datfile
 
    # Complain and exit if file does not exist
    if {![ file exists $datfile ] }     {
        putquick "PRIVMSG $channel :\[\002SMS\017\] \002Error: \002File \"$datfile\" not found!"
        return 0
    }
 
    # Complain and exit if file is not readable
    if {![ file readable $datfile ] }   {
        putquick "PRIVMSG $channel :\[\002SMS\017\] \002Error:\002 Permission denied to read $datfile!"
        return 0
    }
 
    # read sms data
    if { [ catch { set fileId [open $datfile r] } err ] }  {
        putquick "PRIVMSG $channel :\[\002SMS\017\] Error:\002 $err"
        return 0
    }
 
    set names [list]
    while {![eof $fileId]} {
        set line [gets $fileId]
        set data [split $line ":"]
        if {$data != ""} {
            lappend names [lindex $data 0]
        }
    }
    close $fileId
 
    return $names
}
 
 
proc sms::getnumber {smsname} {
    global datfile
    set smsnum ""
 
    # read sms data
    if { [ catch { set fileId [open $datfile r] } err ] }  {
        putquick "PRIVMSG $channel :\[\002SMS\017\] Error:\002 $err"
        return 0
    }
 
    set names [list]
    while {![eof $fileId]} {
        set line [gets $fileId]
        set data [split $line ":"]
        if {$data != ""} {
            if {$smsname eq [lindex $data 0]} {
                set smsnum [lindex $data 1]
            }
        }
    }
    close $fileId
 
    return $smsnum
}
 
 
proc sms::smsver {nickname hostname handle channel arguments} {
    global smsver
 
    if ![channel get $channel sms] return
 
    putquick "PRIVMSG $channel :\[\002SMS\017\] ver. $smsver"
    putquick "PRIVMSG $channel :\002(C) 2005 EToS"
}
 
proc sms::credspublic {nickname hostname handle channel arguments} {
    global chan urlcreds user pass id
 
    if ![channel get $channel sms] return
 
    # regsub details into urlcreds url
    set realurlcreds $urlcreds
    regsub -all SMSID $realurlcreds $id realurlcreds
    regsub -all SMSUSER $realurlcreds $user realurlcreds
    regsub -all SMSPASS $realurlcreds $pass realurlcreds
 
    set token [http::geturl $realurlcreds]
    set bal_frm_url [http::data $token]
 
    putquick "PRIVMSG $channel :\[\002SMS\017\] \002Credits:\002 $bal_frm_url"
}
 
proc sms::smshelp {nickname hostname handle channel arguments} {
    global chan
 
    if ![channel get $channel sms] return
 
    putquick "PRIVMSG $channel :\[\002SMS\017\] \002CMDS HELP!:\017"
    putquick "PRIVMSG $channel : !sms <name> <message> - send a txt msg"
    putquick "PRIVMSG $channel : !number <name> - view a users number, ops only cmd"
    putquick "PRIVMSG $channel : !smscreds -  view credits on account"
    putquick "PRIVMSG $channel : !smsadd <name> <number> - ops only"
    putquick "PRIVMSG $channel : !smsdel - not implemented \(deliberately\)"
    putquick "PRIVMSG $channel : !smsver - version info"
    putquick "PRIVMSG $channel : !smshelp - err your here!"
}
Answered By: tillgeffken
Expert Since: 08/17/2008
Accepted Solutions: 28
tillgeffken has been an Expert for 4 months, during which he has posted 98 comments and answered 28 questions. tillgeffken is just one of 57 experts in the TCL Scripting Language Zone. 1 expert collaborated on this answer, which was graded a "C" by the asker.
 
 
20081119-EE-VQP-48 / EE_QW_2_20070628