Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
eggdrop-scripts/calc.tcl
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
31 lines (25 sloc)
701 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # created by fedex | |
| bind pub - !calc safe_calc | |
| bind pub - .calc safe_calc | |
| setudef flag calc | |
| proc is_op {str} { | |
| return [expr [lsearch {{ } . + - * / ( ) %} $str] != -1] | |
| } | |
| proc safe_calc {nick uhost hand chan str} { | |
| if {![channel get $chan calc]} { return } | |
| foreach char [split $str {}] { | |
| if {![is_op $char] && ![string is integer $char]} { | |
| putserv "PRIVMSG $chan :$nick: Invalid expression for calc." | |
| return | |
| } | |
| } | |
| # make all values floating point | |
| set str [regsub -all -- {((?:\d+)?\.?\d+)} $str {[expr {\1*1.0}]}] | |
| set str [subst $str] | |
| if {[catch {expr $str} out]} { | |
| putserv "PRIVMSG $chan :$nick: Invalid equation." | |
| return | |
| } else { | |
| putserv "PRIVMSG $chan :$str = $out" | |
| } | |
| } |