package require http
####
# EggSMS by ube (ube@rajraj.nu)
#
# For eggdrops 1.3.x
# NOTE: THIS TCL REQUIRES =< TCL8.0
#
# please mail bugs to ube@rajraj.nu
#
####
# Syntax:
# /msg <botnick> sms <userhandle> <text>
# /msg <botnick> smshelp
####
# Changelog:
# 99/06/04: First beta release
# 99/06/04: First release
# - Logging included
# 99/07/20: Version 2.0 by xiv :
# a) Added the possibility to send an SMS by specifying a user's handle.
# To change a user's phone number : .chphone <user> <phone #>
# You have to overwrite your userinfo1.0.tcl with the one included with this file
# b) Removed the unneeded text in the SMS message "EggSMS by ube" to gain some more space
# (hope ube doesn't mind) :-)
# c) Replaced the $botnick in the SMS message by the a customizable message (found it more interesting)
# d) Only registered ops can use this feature (to avoid abuse)
# e) added public !sms command
#
# Thanks to ube for providing the original script, and to ^DaRk^ from whom I ripped some code from "ICQdrop.tcl"
# to apply it here :-)
#
####
# Log options
# 0 - Don't log
# 1 - Timestamp (ex. EggSMS sent SMS at 04 Jun 1999 11:45)
# 2 - Timestamp, user (ex. EggSMS: ube!ube@rajraj.nu sent SMS at 04 Jun 1999 11:45)
# 3 - Timestamp, user, number (ex. EggSMS: ube!ube@rajraj.nu sent SMS to 46709123456 at 04 Jun 1999 11:45)
# 4 - Timestamp, user, number, text (ex. EggSMS: ube!ube@rajraj.nu sent SMS (Hi Kids! Do you like violence) to 46709123456 at 04 Jun 1999 11:45)
#
# Loglevel 3 is a wise choise.. You don't log _what_ the user sends, but you know to whom and when...
# (if you ever get in trouble for SMS flooding)
####
set loglevel 3
set logfile "/home/xiv/eggdrop/EggSMS.log"
# is a basic message that will be added after the SMS message (add + between words)
set epilog "Sent+from+#abc99"
bind pub -|- "!sms" pub_sms
bind msg -|- "smshelp" sms_help
bind dcc -|- "sms *" sms_send
bind msg -|- "sms" msg_sms
proc pub_sms {nick host handle chan args} {
set args [lindex $args 0]
msg_sms $nick $host $handle $args
return 0
}
proc sms_help { nick host handle args } {
global botnick epilog
set temp [string length "$epilog $nick by "]
set temp [expr "143 - $temp"]
putserv "NOTICE $nick :EggSMS By ube (ube@rajraj.nu) updated by xiv (lokiniade@hotmail.com)"
putserv "NOTICE $nick :Sends GSM/SMS messages to GSM celluar phone"
putserv "NOTICE $nick :- Syntax /msg $botnick sms <handle> <text>"
putserv "NOTICE $nick :- EX: /msg $botnick sms ube Hi kids! Do you like violence?"
putserv "NOTICE $nick :- This text will be added to your message: '$epilog by $nick' "
putserv "NOTICE $nick :- This will limit your text length to $temp chars"
putserv "NOTICE $nick :- NOTE: You can't send '+' in your message"
}
proc sms_send {hand idx args} {
global epilog
set args [lindex $args 0]
set whom [lindex $args 0]
if {[validuser $whom] == 0 } {
putdcc $idx "no user by that name, sorry"
return 0
}
if {[getuser $whom XTRA PHONE] == "" } {
putdcc $idx "no PHONE # for $whom registered.. (make sure you have the userfile modified to hold an PHONE field"
return 0
}
set phone [getuser $whom XTRA PHONE]
set text [lrange $args 1 end]
set url "www.mtnsms.com/sms.asp?msgTo=$phone&msgText=[format_text $text]"
::http::geturl "$url"
}
proc msg_sms {nick host handle args} {
global botnick epilog
set args [lindex $args 0]
set whom [lindex $args 0]
if {[validuser $whom] == 0 } {
putserv "NOTICE $nick :no user by that name, sorry"
putserv "NOTICE $nick :syntax /msg $botnick sms <handle> <text>"
return 0
}
if {[getuser $whom XTRA PHONE] == "" } {
putserv "NOTICE $nick :no PHONE # for $whom registered.. "
return 0
}
if { ([lindex $args 1] == "") } {
putserv "NOTICE $nick :syntax /msg $botnick sms <handle> <text>"
return 0
}
set temp [string length "$epilog $nick by "]
set temp [expr "143 - $temp"]
set phone [getuser $whom XTRA PHONE ]
set text [lrange $args 1 end]
set url "www.mtnsms.com/sms.asp?msgTo=$phone&msgText=[format_text $text]+$epilog+by+$nick"
set lng [string length $text]
incr lng -1
set text "[string range $text 0 $lng]"
if { [string length $temp] > 143 } {
putserv "NOTICE $nick :Message NOT sent. Reason: Message to long"
putserv "NOTICE $nick :Maximum number of chars=$temp"
} {
::http::geturl "$url"
putserv "NOTICE $nick :EggSMS sent $text to $phone"
sms_log $phone $nick $host $text
}
}
proc format_text { text } {
set lng [string length $text]
incr lng -1
set text "[string range $text 0 $lng]"
incr lng +1
set tmp ""
set i 0
while { $i != $lng } {
set temp [string range $text $i $i]
if { $temp == " " } {
set tmp "$tmp+"
} {
set tmp "$tmp$temp"
}
incr i
}
return $tmp
}
proc sms_log {phone nick host text} {
global loglevel logfile
if {$loglevel} {
if ![catch {open $logfile a} filelog] {
if {$loglevel == "1"} {
puts $filelog "EggSMS sent SMS at[date] [time]"
close $filelog
}
if {$loglevel == "2"} {
puts $filelog "EggSMS: $nick!$host sent SMS at[date] [time]"
close $filelog
}
if {$loglevel == "3"} {
puts $filelog "EggSMS: $nick!$host sent SMS to $phone at[date] [time]"
close $filelog
}
if {$loglevel == "4"} {
puts $filelog "EggSMS: $nick!$host sent SMS ($text) to $phone at[date] [time]"
close $filelog
}
} {
putlog "**** EggSMS ERROR! Could not log to file: $logfile"
}
}
}
putlog "**** EggSMS by ube (ube@rajraj.nu) updated by xiv (lokiniade@hotmail.com)"
putlog "**** Loglevel: $loglevel"
putlog "**** Logging to: $logfile"
Sunday, August 28, 2011
eggsms.tcl
Labels:
tCL
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment