########################################################### ########################################################### ### ### ## mailtools1.0.tcl ## ## Copyright (c) 1999 ## ## Taske ## ## ## ## GENERAL INFO: ## ## ------------- ## ## This script will take a channel message containing ## ## predefined strings and send it to an email address. ## ## It will also make you able to send a mail to an ## ## address with a message and make the bot display this ## ## in channels. ## ## ## ## Adjust the global variables to suit your needs. ## ## Adjust the global variables in the perl script ## ## (mailtools.pl) to match the info here. ## ## Read the info in the perl script carefully and ## ## do what it says. ## ## For more information, type .mthelp in DCC to the bot. ## ## ## ## To be able to use the relaying of messages to a mail ## ## account the email address has to be specified on the ## ## bot (.help email) and the system has to have mailx ## ## installed (to check, type 'whereis mail' or ## ## 'whereis mailx'. If you get a path you have it.) ## ## ## ## I had to use a perl script for the checkmail part ## ## of this tcl. If anyone has a better idea on how ## ## to solve it (preferrably inside this tcl) please let ## ## me know. Place the perlscrip anywhere on your account ## ## and read the info in it. ## ## ## ## The relaying only supports one owner as of now. ## ## If the bot has more owners it will only relay to the ## ## first owner it finds in the userlist. ## ## ## ## COPYRIGHT INFO: ## ## --------------- ## ## You may use this script as a base for your own ## ## but please give me credits. You may NOT redistribute ## ## this script as your own. If you change the script ## ## please change its name too. ## ## ## ## DISCLAIMER: ## ## ----------- ## ## Use the script at your own risk! ## ## The author is not to be held responsible for anything.## ## ## ## CREDITS: ## ## -------- ## ## - Microlf for perl help. ## ### ### ########################################################### ########################################################### # GLOBAL VARIABLES (change these to suit you) # Set the time interval (in seconds) for the bot # to scan the mail for incoming msgs. set chk_time 60 # The email address for the account the bot is on. set chk_addr "nut@blackplasma.net" # The script looks for a specified subject in your mailbox # to know what mails it should process. # Every mail the bot is to process must have this subject. # Make it unique since all mails with this subject # will be trashed after being processed. set chk_subj "REPLAY: .*Upload Notice" # Your homedirectory set homedir "/home/nut" # Name of the tempfile to store mail to irc. set mailfile "botmail" # The handle (in the bot) of the owner. set owner "seymour" # The string(s) the bot should look for when relaying messages # on channels to a mail account. set relay_word { {word} {another} {third} {etc} } # Set the subject the relayed mail will have. set relay_subj "IRCrelay" ############################################### ### DO NOT CHANGE ANYTHING BELOW THIS LINE! ### ### If you do, strange things may happen. ### ############################################### # This script is NOT for pre-1.3.0 versions. if {![info exists numversion] || ($numversion < 1030000)} { if {[string range $version 0 2] != "1.3"} { putlog "*** Can't load $mailtoolver -- At least Eggdrop v1.3.0 required" return 0 } } # The binds bind dcc n mtcoff mtcoff bind dcc n mtcon mtcon bind dcc n mtron mtron bind dcc n mtroff mtroff bind dcc n mtstatus mtstatusdcc bind dcc - mthelp mthelpdcc bind dcc - mtinfo mtinfodcc bind msg n mtstatus mtstatusmsg bind msg - mthelp mthelpmsg bind msg - mtinfo mtinfomsg ## HELP ## # The dcc helpfiles for the script # Usage: .mthelp or .mthelp proc mthelpdcc {handle idx arg} { global mailtoolver set morehelp [lindex $arg 0] set morehelp [string tolower $morehelp] if {$morehelp == ""} { if {[matchattr $handle n]} { putdcc $idx "---" putdcc $idx "*** $mailtoolver ***" putdcc $idx "Valid commands are:" putdcc $idx "mtinfo mtcon mtcoff" putdcc $idx "mtron mtroff mtstatus" putdcc $idx " " putdcc $idx "Commands begin with '.' and all else goes to the party line." putdcc $idx "For further help: .mthelp " putdcc $idx "---" return 1 } { putdcc $idx "---" putdcc $idx "*** $mailtoolver ***" putdcc $idx "Valid command is:" putdcc $idx "mtinfo" putdcc $idx " " putdcc $idx "Commands begin with '.' and all else goes to the party line." putdcc $idx "For further help: .mthelp " putdcc $idx "---" return 1 } } if {$morehelp == "mtinfo"} { putdcc $idx "---" putdcc $idx "*** $mailtoolver ***" putdcc $idx "Usage: .mtinfo" putdcc $idx "Will display a short info message on what the script" putdcc $idx "can do." putdcc $idx "---" return 1 } if {$morehelp == "mtcon"} { if {[matchattr $handle n]} { putdcc $idx "---" putdcc $idx "*** $mailtoolver ***" putdcc $idx "Usage: .mtcon" putdcc $idx "Will turn the checking of mail on." putdcc $idx "---" return 1 } { putdcc $idx "What? Try .mthelp" return 1 } } if {$morehelp == "mtcoff"} { if {[matchattr $handle n]} { putdcc $idx "---" putdcc $idx "*** $mailtoolver ***" putdcc $idx "Usage: .mtcoff" putdcc $idx "Will turn checking of mail off." putdcc $idx "---" return 1 } { putdcc $idx "What? Try .mthelp" return 1 } } if {$morehelp == "mtron"} { if {[matchattr $handle n]} { putdcc $idx "---" putdcc $idx "*** $mailtoolver ***" putdcc $idx "Usage: .mtron" putdcc $idx "Will turn the relay part of the script on." putdcc $idx "---" } { putdcc $idx "What? Try .mthelp" return 1 } } if {$morehelp == "mtroff"} { if {[matchattr $handle n]} { putdcc $idx "---" putdcc $idx "*** $mailtoolver ***" putdcc $idx "Usage: .mtroff" putdcc $idx "Will turn the relay part of the script off." putdcc $idx "---" } { putdcc $idx "What? Try .mthelp" return 1 } } if {$morehelp == "mtstatus"} { if {[matchattr $handle n]} { putdcc $idx "---" putdcc $idx "*** $mailtoolver ***" putdcc $idx "Usage: .mtstatus" putdcc $idx "Displays the status of relaying and checking." putdcc $idx "---" } { putdcc $idx "What? Try .mthelp" return 1 } } { putdcc $idx "I don't know $morehelp. Try .mthelp" return 1 } } # The dcc info for the script # Usage: .mtinfo proc mtinfodcc {handle idx arg} { global mailtoolver chk_addr chk_subj if {[matchattr $handle n]} { putdcc $idx "---" putdcc $idx "*** $mailtoolver ***" putdcc $idx "This utility will make you able to send a mail" putdcc $idx "to $chk_addr with the subject '$chk_subj'." putdcc $idx "The bot will then display the message in the mail" putdcc $idx "on the channel you specified. Make sure the body" putdcc $idx "of the mail is on ONE line and the first word" putdcc $idx "is a channel name (including the hash)." putdcc $idx "As an owner of the bot you will be able to" putdcc $idx "specify a word or range of words for the bot" putdcc $idx "to check to display in a mail message to you." putdcc $idx "---" return 1 } { putdcc $idx "---" putdcc $idx "*** $mailtoolver ***" putdcc $idx "This utility will make you able to send a mail" putdcc $idx "to $chk_addr with the subject '$chk_subj'." putdcc $idx "The bot will then display the message in the mail" putdcc $idx "on the channel you specified. Make sure the body" putdcc $idx "of the mail is on ONE line and the first word" putdcc $idx "is a channel name (including the hash)." putdcc $idx "---" return 1 } } # The msg help for the script # Usage: mthelp or mthelp proc mthelpmsg {nick uhost hand chan} { global mailtoolver set morehelp [lindex $chan 0] set morehelp [string tolower $morehelp] if {$morehelp == ""} { if {[matchattr $hand n]} { puthelp "NOTICE $nick :---" puthelp "NOTICE $nick :*** $mailtoolver ***" puthelp "NOTICE $nick :Valid commands are:" puthelp "NOTICE $nick :mtinfo mtstatus" puthelp "NOTICE $nick :" puthelp "NOTICE $nick :For further help: mthelp " puthelp "NOTICE $nick :---" return 1 } { puthelp "NOTICE $nick :---" puthelp "NOTICE $nick :*** $mailtoolver ***" puthelp "NOTICE $nick :Valid command is:" puthelp "NOTICE $nick :mtinfo" puthelp "NOTICE $nick :" puthelp "NOTICE $nick :For further help: mthelp " puthelp "NOTICE $nick :---" return 1 } } if {$morehelp == "mtinfo"} { puthelp "NOTICE $nick :---" puthelp "NOTICE $nick :*** $mailtoolver ***" puthelp "NOTICE $nick :Usage: mtinfo" puthelp "NOTICE $nick :Will display a short info message on what the script" puthelp "NOTICE $nick :can do." puthelp "NOTICE $nick :---" return 1 } if {$morehelp == "mtcon"} { if {[matchattr $hand n]} { puthelp "NOTICE $nick :---" puthelp "NOTICE $nick :*** $mailtoolver ***" puthelp "NOTICE $nick :Only available through DCC." puthelp "NOTICE $nick :Usage: .mtcon" puthelp "NOTICE $nick :Will turn the checking of mail on." puthelp "NOTICE $nick :---" return 1 } { puthelp "NOTICE $nick :What? Try mthelp" return 1 } } if {$morehelp == "mtcoff"} { if {[matchattr $hand n]} { puthelp "NOTICE $nick :---" puthelp "NOTICE $nick :*** $mailtoolver ***" puthelp "NOTICE $nick :Only available through DCC." puthelp "NOTICE $nick :Usage: .mtcoff" puthelp "NOTICE $nick :Will turn the checking of mail off." puthelp "NOTICE $nick :---" return 1 } { puthelp "NOTICE $nick :What? Try mthelp" return 1 } } if {$morehelp == "mtron"} { if {[matchattr $hand n]} { puthelp "NOTICE $nick :---" puthelp "NOTICE $nick :*** $mailtoolver ***" puthelp "NOTICE $nick :Only available through DCC." puthelp "NOTICE $nick :Usage: .mtron" puthelp "NOTICE $nick :Will turn the relay part of the script on." puthelp "NOTICE $nick :---" } { puthelp "NOTICE $nick :What? Try mthelp" return 1 } } if {$morehelp == "mtroff"} { if {[matchattr $hand n]} { puthelp "NOTICE $nick :---" puthelp "NOTICE $nick :*** $mailtoolver ***" puthelp "NOTICE $nick :Only available through DCC." puthelp "NOTICE $nick :Usage: .mtroff" puthelp "NOTICE $nick :Will turn the relay part of the script off." puthelp "NOTICE $nick :---" } { puthelp "NOTICE $nick :What? Try mthelp" return 1 } } if {$morehelp == "mtstatus"} { if {[matchattr $hand n]} { puthelp "NOTICE $nick :---" puthelp "NOTICE $nick :*** $mailtoolver ***" puthelp "NOTICE $nick :Usage: .mtstatus" puthelp "NOTICE $nick :Displays the status of relaying and checking." puthelp "NOTICE $nick :---" } { puthelp "NOTICE $nick :What? Try mthelp" return 1 } } { puthelp "NOTICE $nick :I don't know $morehelp. Try .mthelp" return 0 } } # The msg info for the script # Usage: mtinfo proc mtinfomsg {nick uhost hand chan} { global mailtoolver chk_addr chk_subj if {[matchattr $hand n]} { puthelp "NOTICE $nick :---" puthelp "NOTICE $nick :*** $mailtoolver ***" puthelp "NOTICE $nick :This utility will make you able to send a mail" puthelp "NOTICE $nick :to $chk_addr with the subject '$chk_subj'." puthelp "NOTICE $nick :The bot will then display the message in the mail" puthelp "NOTICE $nick :on the channel you specified. Make sure the body" puthelp "NOTICE $nick :of the mail is on ONE line and the first word" puthelp "NOTICE $nick :is a channel name (including the hash)." puthelp "NOTICE $nick :As an owner of the bot you will be able to" puthelp "NOTICE $nick :specify a word or range of words for the bot" puthelp "NOTICE $nick :to check to display in a mail message to you." puthelp "NOTICE $nick :---" return 1 } { puthelp "NOTICE $nick :---" puthelp "NOTICE $nick :*** $mailtoolver ***" puthelp "NOTICE $nick :This utility will make you able to send a mail" puthelp "NOTICE $nick :to $chk_addr with the subject chk_subj'." puthelp "NOTICE $nick :The bot will then display the message in the mail" puthelp "NOTICE $nick :on the channel you specified. Make sure the body" puthelp "NOTICE $nick :of the mail is on ONE line and the first word" puthelp "NOTICE $nick :is a channel name (including the hash)." puthelp "NOTICE $nick :---" return 1 } } ## MAIN PROCS ## # These line are to ensure the values do not start uninitialized set relay "Off" set check "On" set indx 0 set lastmsg "" set check_timer [utimer ${chk_time} check_mail] # Turn the relaying on proc mtron {handle idx arg} { global relay_word relay indx if {$relay == "Off"} { while {$indx < [llength $relay_word]} { bind pubm * "*[lindex $relay_word $indx]*" send_mail incr indx 1 } set relay "On" putlog "Mailtool relaying turned on..." set indx 0 return 0 } { putlog "Mailtool relaying already turned on..." } } # Turn the relaying off proc mtroff {handle idx arg} { global relay_word relay number indx if {$relay == "On"} { set number [llength $relay_word] while {$indx < [llength $relay_word]} { unbind pubm * "*[lindex $relay_word $indx]*" send_mail incr indx 1 } set relay "Off" putlog "Mailtool relaying turned off..." set indx 0 return 0 } { putlog "Mailtool relaying already turned off..." } } # Turn the checking of mail on proc mtcon {handle idx arg} { global check chk_time check_timer reset_utimer set check_timer [utimer ${chk_time} check_mail] putlog "Mailtool checking on..." set check "On" return 0 } # Turn the checking of mail off proc mtcoff {handle idx arg} { global check check_timer reset_utimer putlog "Mailtool checking off..." set check "Off" return 0 } # The function to relay messages on irc to a mail address. proc send_mail {nick uhost hand chan args} { global owner relay_file relay_word relay_subj lastmsg relay set email [getuser $owner XTRA EMAIL] set text [lindex $args 0] set message "$nick $chan: $text" if {$email == ""} { putlog "Owner has not specified email. Aborting relay." } { if {$message != $lastmsg && $relay == "On"} { set fd [open "|mail -s $relay_subj $email" "w"] puts $fd $message close $fd putlog "Sent mail to $email..." set lastmsg $message return 1 } } } # Resets the utimer proc reset_utimer {} { global check_timer if {[info exists check_timer]} { kill_utimer $check_timer unset check_timer } } # Kills the given utimer id if it exists proc kill_utimer {utimer} { foreach i [utimers] { if {[string compare [lindex $i 2] $utimer] == 0} { killutimer $utimer return 1 } } return 0 } # The function to check messages in the mailbox and display them # on irc. This is really hairy code including a perl script. proc check_mail {} { global chk_subj check mailfile homedir chk_time set mfile $homedir/$mailfile if {[file exists $mfile]} { set fd [open $mfile r] while {![eof $fd]} { set inp [gets $fd] if {[eof $fd]} {break} set channel [string tolower [lindex $inp 0]] set msg [lrange $inp 1 end] if {[validchan $channel]} { putlog "$msg" putmsg $channel "$msg" } } close $fd file delete $mfile reset_utimer set check_timer [utimer ${chk_time} check_mail] return 1 } { reset_utimer set check_timer [utimer ${chk_time} check_mail] } } # Display status in dcc proc mtstatusdcc {handle idx arg} { global mailtoolver check relay if {[matchattr $handle n]} { putdcc $idx "---" putdcc $idx "### $mailtoolver ###" putdcc $idx "Status:" putdcc $idx "Mail relay: $relay" putdcc $idx "Mail check: $check" putdcc $idx "---" return 1 } { putdcc $idx "What? Try .mthelp" return 1 } } # Display status in msg proc mtstatusmsg {nick uhost hand chan} { global mailtoolver check relay if {[matchattr $hand n]} { puthelp "NOTICE $nick :---" puthelp "NOTICE $nick :### $mailtoolver ###" puthelp "NOTICE $nick :Status:" puthelp "NOTICE $nick :Mail relay: $relay" puthelp "NOTICE $nick :Mail check: $check" puthelp "NOTICE $nick :---" return 1 } { puthelp "NOTICE $nick :What? Try mthelp" return 1 } } # This script's identification set mailtoolver "Mailtools v1.0 - by Taske" putlog "$mailtoolver loaded..." putlog "Use .mthelp for more info."