#!/usr/bin/perl -w # RitBits is Jen's first script... first of anything like this actually. So expect bugs. # Official Page: http://caffeinated-dreams.net/2005/06/28/rit-bits-perl-script-for-x-chat/ # Version: 0.3 (June 29th, 2005) # Do whatever to this script. I don't care. # ################ Credits ################ # Gamakichi for being awesome, hardrive/cpu/netstat display improvement and perl support. # Neovanglist for FreeBSD-fu. # Good folks in #Xion on IRC for support and allowing us to spam our testing. That's probably only because they were sleeping though. =) # # # TODO RAM display improvement, temperature sensors(?), xmms/beep media player/amarok support (??!) # # Only edit hardrive information ($hdd2), the part that may need editing is labled. Otherwise do not touch below this unless you know what you're doing. :P IRC::register("RitBits", "0.3", "", ""); IRC::print "\cC2\cBRitBits loaded!\003 Commands are: /ritbits /client /gfx /os /desk /cpu /sound /netstat /disk /uptime"; IRC::add_command_handler("ritbits", "ritbits"); IRC::add_command_handler("gfx", "gfx"); IRC::add_command_handler("os", "os"); IRC::add_command_handler("client", "client"); IRC::add_command_handler("desk", "desk"); IRC::add_command_handler("cpu", "cpu"); IRC::add_command_handler("sound", "sound"); IRC::add_command_handler("netstat", "netstat"); IRC::add_command_handler("disk", "disk"); IRC::add_command_handler("uptime", "uptime"); # About sub ritbits { IRC::command("( \cC2\cBRit Bits\cB\003 ) - A n00b script by Jen for X-Chat, version 0.3 (\cBhttp://caffeinated-dreams.net\cB)"); return 1; } # Video card, resolution sub gfx { $xorg = `xdpyinfo | grep X.Org"."version`; chomp ($xorg); $res = `xdpyinfo | grep dimensions | awk '{print \$2}'`; chomp ($res); $vid = `sysctl dev.drm.0.\%desc | cut -d : -f 2`; chomp ($vid); @bits = `xwininfo -root`; foreach (@bits) { if (/^ +?Depth: (.+)/i) {$bits = $1;} } IRC::command("( \cC2\cBGraphics\cB\003 ) \cB $vid \cB,\cB\ $xorg \cB\ ( \cC2\cBResolution\cB\003 ) \cB $res \cB ( \cC2\cBBits\cB\003 ) \cB $bits \cB "); return 1; } # Operating System sub os { $os =`uname -srm`; chomp ($os); IRC::command("( \cC2\cBOperating System\cB\003 ) \cB $os \cB"); return 1; } # Desktop Environment (Only KDE at the moment) sub desk { #TODO Make it recognize and detect any desktop, gnome, kde, flux, xfce, etc... $desk =`kde-config -version | grep KDE`; chomp ($desk); IRC::command("( \cC2\cBDesktop Environment\cB\003 ) \cB $desk \cB"); return 1; } # CPU sub cpu { system "dmesg | grep CPU: > .cpu"; open(AWKFILE, ">.cpuawk") or die "Can't open .dawk: $!"; print AWKFILE '{ print $6 }'; system "awk -f .cpuawk .cpu > .cpu2"; $model = `sysctl hw.model | cut -d : -f 2`; chomp ($model); $freq = `cut -c2-8 .cpu2`; chomp ($freq); IRC::command("( \cC2\cBCPU\cB\003 ) \cB $model \cB ( \cC2\cBFrequency\cB\003 ) \cB $freq \cB MHz"); close AWKFILE; system "rm .cpu"; system "rm .cpu2"; system "rm .cpuawk"; return 1; } # Hardrives, can support multiple disks. # Uncomment the lines below for a second disk. sub disk { open(AWKFILET, ">.awkT") or die "Can't open .awkT: $!"; open(AWKFILEU, ">.awkU") or die "Can't open .awkU: $!"; print AWKFILET '{ print $2 }'; print AWKFILEU '{ print $3 }'; $usrT = `df -h | grep /usr | awk -f .awkT`; $usrU = `df -h | grep /usr | awk -f .awkU`; # $usr2T = `df -h | grep /usr2 | awk -f .awkT`; # $usr2U = `df -h | grep /usr2 | awk -f .awkU`; chomp ($usrT); chomp ($usrU); # chomp ($usr2T); # chomp ($usr2U); IRC::command("( \cC2\cBHardrives\cB\003 ) \cC2/usr\003: \cB Used\: $usrU \\ Total: $usrT \cB");# \cC2/usr2\003: \cB Used\: $usr2U \\ Total: $usr2T \cB"); close AWKFILET; close AWKFILEU; system "rm .awkT"; system "rm .awkU"; return 1; } # Soundcard sub sound { $sound = `sysctl dev.pcm.0.\%desc | cut -d : -f 2`; chomp ($sound); IRC::command("( \cC2\cBSoundcard\cB\003 ) \cB $sound \cB"); return 1; } # Network statistic, shows KB down and up. sub netstat { open(AWKFILEI, ">.awkI") or die "Can't open .awkI: $!"; open(AWKFILEO, ">.awkO") or die "Can't open .awkO: $!"; print AWKFILEI '{ print $7 }'; print AWKFILEO '{ print $10 }'; $Idata = `netstat -bi | grep Link#1 | awk -f .awkI`; $Odata = `netstat -bi | grep Link#1 | awk -f .awkO`; chomp ($Idata); chomp ($Odata); $Idata /= 1024 ; $Odata /= 1024 ; $In = sprintf("%.2f", $Idata); $Out = sprintf("%.2f", $Odata); IRC::command("( \cC2\cBNetwork Statistics\cB\003 ) \cB Down\: $In KB \\ Up\: $Out KB \cB"); close AWKFILEI; close AWKFILEO; system "rm .awkI"; system "rm .awkO"; return 1; } # Uptime sub uptime { $uptime =`uptime`; chomp ($uptime); IRC::command("( \cC2\cBCurrent Uptime\cB\003 ) \cB $uptime \cB"); return 1; } # X-Chat version sub client { $client = IRC::get_info(0); chomp ($client); IRC::command("( \cC2\cBIRC Client\cB\003 ) \cB X-Chat $client \cB"); return 1; }