A Basic conversion script for temperature.
See below for further details.
# Default trigger set to "!"
# Commands
# --------
# PUBLIC
# !convtemp on/off
# !convert c/f <-/number>
# (examples: !convert c 12 <- !convert f -14 <- !convert c -23 <- !convert f 120 <-)
# PRIVMSG
# /msg botnickname convtemp #anychannelname on/off
# -----------EDIT BELOW------------
# Set this to whatever trigger you like.
set mytrig "!"
# ------DONT TOUCH BELOW HERE!!!------
setudef flag convtemp
bind pub - ${mytrig}convtemp convtemp:pub
bind pub - ${mytrig}convert con:vert
bind msg - convtemp convtemp:msg
proc myTrig {} {
global mytrig
return $mytrig
}
proc convtemp:pub {nick uhost hand chan text} {
global botnick
if {[matchattr [nick2hand $nick] o|m $chan]} {
if {([lindex [split $text] 0] == "") && (![regexp c [getchanmode $chan]])} {putquick "PRIVMSG $chan :\037ERROR\037: Incorrect Parameters. \037SYNTAX\037: [myTrig]convtemp on/off"; return}
if {([lindex [split $text] 0] == "") && ([regexp c [getchanmode $chan]])} {putquick "PRIVMSG $chan :ERROR: Incorrect Parameters. SYNTAX: [myTrig]convtemp on/off"; return}
if {[lindex [split $text] 0] == "on"} {
if {[channel get $chan convtemp] && ![regexp c [getchanmode $chan]]} {putquick "PRIVMSG $chan :\037ERROR\037: This setting is already enabled."; return}
if {[channel get $chan convtemp] && [regexp c [getchanmode $chan]]} {putquick "PRIVMSG $chan :ERROR: This setting is already enabled."; return}
channel set $chan +convtemp
puthelp "PRIVMSG $chan :Enabled Temperature Conversion for $chan"
}
if {[lindex [split $text] 0] == "off"} {
if {![channel get $chan convtemp] && ![regexp c [getchanmode $chan]]} {putquick "PRIVMSG $chan :\037ERROR\037: This setting is already disabled."; return}
if {![channel get $chan convtemp] && [regexp c [getchanmode $chan]]} {putquick "PRIVMSG $chan :ERROR: This setting is already disabled."; return}
channel set $chan -convtemp
puthelp "PRIVMSG $chan :Disabled Temperature Conversion for $chan"
}
}
}
proc convtemp:msg {nick uhost hand arg} {
global botnick
set chan [strlwr [lindex $arg 0]]
if {[matchattr [nick2hand $nick] o|m $chan]} {
if {[lindex [split $arg] 0] == ""} {putquick "NOTICE $nick :\037ERROR\037: Incorrect Parameters. \037SYNTAX\037: /msg $botnick convtemp #channelname on/off"; return}
if {([lindex [split $arg] 1] == "") && ([string match "*#*" $chan])} {putquick "NOTICE $nick :\037ERROR\037: Incorrect Parameters. \037SYNTAX\037: /msg $botnick convtemp $chan on/off"; return}
if {([lindex [split $arg] 1] == "on") && ([string match "*#*" $chan])} {
if {[channel get $chan convtemp]} {putquick "NOTICE $nick :\037ERROR\037: This setting is already enabled."; return}
channel set $chan +convtemp
putquick "NOTICE $nick :Enabled Temperature Conversion for $chan"
}
if {([lindex [split $arg] 1] == "off") && ([string match "*#*" $chan])} {
if {![channel get $chan convtemp]} {putquick "NOTICE $nick :\037ERROR\037: This setting is already disabled."; return}
channel set $chan -convtemp
putquick "NOTICE $nick :Disabled Temperature Conversion for $chan"
}
}
}
proc con:vert {nick uhost hand chan text} {
if {[validuser [nick2hand $nick]] || [isop $nick $chan] || [isvoice $nick $chan]} {
if {![channel get $chan convtemp]} {putquick "PRIVMSG $chan :\037ERROR\037: Conversion Module is not currently enabled for $chan"; return}
if {![regexp c [getchanmode $chan]]} {
if {[lindex [split $text] 0] == ""} {putquick "PRIVMSG $chan :\037ERROR\037: Incorrect Parameters. \037SYNTAX\037: [myTrig]convert c/f temp"; return}
if {[lindex [split $text] 0] == "c"} {
if {[lindex [split $text] 1] == ""} {putquick "PRIVMSG $chan :\037ERROR\037: Incorrect Parameters. \037SYNTAX\037: [myTrig]convert c/f temp"; return}
set ctemp [lindex [split $text] 1]
if {![isnum $ctemp]} {putquick "PRIVMSG $chan :\037ERROR\037: Incorrect Parameters. \037SYNTAX\037: [myTrig]convert c/f temp"; return}
if {$ctemp == 0} {putquick "PRIVMSG $chan :\002\037C\037\002onverted: 0\xB0 C equals 32\xB0 F"; return}
if {!$ctemp == 0} {
set calctemp [expr {$ctemp * 1.8}]
set calcnum [expr {$calctemp + 32}]
putquick "PRIVMSG $chan :\002\037C\037\002onverted: $ctemp\xB0 C equals [expr $calcnum]\xB0 F"
}
}
if {[lindex [split $text] 0] == "f"} {
if {[lindex [split $text] 1] == ""} {putquick "PRIVMSG $chan :\037ERROR\037: Incorrect Parameters. \037SYNTAX\037: [myTrig]convert c/f temp"; return}
set ctemp [lindex [split $text] 1]
if {![isnum $ctemp]} {putquick "PRIVMSG $chan :\037ERROR\037: Incorrect Parameters. \037SYNTAX\037: [myTrig]convert c/f temp"; return}
if {$ctemp == 0} {putquick "PRIVMSG $chan :\002\037C\037\002onverted: 0\xB0 F equals -17.77\xB0 C"; return}
if {!$ctemp == 0} {
set calctemp [expr {$ctemp - 32}]
set calcnum [expr {$calctemp * 0.55555555555555555555555555555556}]
putquick "PRIVMSG $chan :\002\037C\037\002onverted: $ctemp\xB0 F equals [expr $calcnum]\xB0 C"
}
}
}
if {[regexp c [getchanmode $chan]]} {
if {[lindex [split $text] 0] == ""} {putquick "PRIVMSG $chan :ERROR: Incorrect Parameters. SYNTAX: [myTrig]convert c/f temp"; return}
if {[lindex [split $text] 0] == "c"} {
if {[lindex [split $text] 1] == ""} {putquick "PRIVMSG $chan :ERROR: Incorrect Parameters. SYNTAX: [myTrig]convert c/f temp"; return}
set ctemp [lindex [split $text] 1]
if {![isnum $ctemp]} {putquick "PRIVMSG $chan :ERROR: Incorrect Parameters. SYNTAX: [myTrig]convert c/f temp"; return}
if {$ctemp == 0} {putquick "PRIVMSG $chan :Converted: 0\xB0 C equals 32\xB0 F"; return}
if {!$ctemp == 0} {
set calctemp [expr {$ctemp * 1.8}]
set calcnum [expr {$calctemp + 32}]
putquick "PRIVMSG $chan :Converted: $ctemp\xB0 C equals [expr $calcnum]\xB0 F"
}
}
if {[lindex [split $text] 0] == "f"} {
if {[lindex [split $text] 1] == ""} {putquick "PRIVMSG $chan :ERROR: Incorrect Parameters. SYNTAX: [myTrig]convert c/f temp"; return}
set ctemp [lindex [split $text] 1]
if {![isnum $ctemp]} {putquick "PRIVMSG $chan :ERROR: Incorrect Parameters. SYNTAX: [myTrig]convert c/f temp"; return}
if {$ctemp == 0} {putquick "PRIVMSG $chan :Converted: 0\xB0 F equals -17.77\xB0 C"; return}
if {!$ctemp == 0} {
set calctemp [expr {$ctemp - 32}]
set calcnum [expr {$calctemp * 0.55555555555555555555555555555556}]
putquick "PRIVMSG $chan :Converted: $ctemp\xB0 F equals [expr $calcnum]\xB0 C"
}
}
}
}
}
proc isnum {string} {
if {[regexp {^-?\d+(\.\d+)?$} $string]} {
return 1;
}
return 0;
}
putlog "Conversion Module: Loaded"
I Translated this from mIRC, so it's easy to see the resemblance in the codes.
mIRC Snippet
on *:TEXT:*:#: {
if ($1 == !convert) {
if (!%no.flood. [ $+ [ $nick ] ]) {
if (!$2) { msg $chan ERROR $+ : Insufficient Parameters. SYNTAX $+ : !convert c/f <temperature> | return }
if ($2 isnum) { msg $chan ERROR $+ : Insufficient Parameters. SYNTAX $+ : !convert c/f <temperature> | return }
if ($2 == f) {
if ($3 == 0) { msg $chan Converting 0 $+ $chr(176) Fahrenheit to Celsius: -17.77 $+ $chr(176) $+ C | set -u5 %no.flood. [ $+ [ $nick ] ] 1 | return }
if (!$3) { msg $chan $nick $+ , I need a temperature to convert. }
if ($3 isletter) { msg $chan Converting $3 $+ : You're an Idiot? | set -u5 %no.flood. [ $+ [ $nick ] ] 1 | return }
if ($3 isnum) {
set %t1 $calc($3 - 32)
set %temp $calc(%t1 * 0.55555555555555555555555555555556)
msg $chan Converting $3 $+ $chr(176) Fahrenheit to Celsius: $round(%temp,2) $+ $chr(176) $+ C
set -u5 %no.flood. [ $+ [ $nick ] ] 1
}
}
if ($2 == c) {
if ($3 == 0) { msg $chan Converting 0 $+ $chr(176) Celsius to Fahrenheit: 32 $+ $chr(176) $+ F | set -u5 %no.flood. [ $+ [ $nick ] ] 1 | return }
if (!$3) { msg $chan $nick $+ , I need a temperature to convert. }
if ($3 isletter) { msg $chan Converting $3 $+ : You're an Idiot? | set -u5 %no.flood. [ $+ [ $nick ] ] 1 | return }
if ($3 isnum) {
set %t1 $calc($3 * 1.8)
set %temp $calc(%t1 + 32)
msg $chan Converting $3 $+ $chr(176) Celsius to Fahrenheit: $round(%temp,2) $+ $chr(176) $+ F
set -u5 %no.flood. [ $+ [ $nick ] ] 1
}
}
}
}
}
Enjoy either ;)