#!/usr/bin/perl -w # # RitBits is Jen's first script... first of anything like this actually. So expect bugs. # Authors: Jen (and now!) Max # Official Page: http://caffeinated-dreams.net/2005/06/28/rit-bits-perl-script-for-x-chat/ # Contact via E-Mail: Jen@Caffeinated-Dreams.Net # Version: 0.5 (July 7th, 2005) # Usage Rules: Do whatever to this script. I don't care. # ################################### COMMANDS ###################################### # # ALL COMMANDS ARE SHOWN IN CHANNEL YOU TYPE TO. They will not/should not show up in any other channels except for the one you typed the command in. # If it does, I don't know what to tell you. # # /ritbits - Displays the script name, version, authors, and homepage in the channel of this script. # /gfx - Displays graphic information: video card, resolution, bits. # /kernal - Displays your Operating System. # /desktop - Displays your desktop environment (gnome, kde, etc) or window manager (fluxbox, enlightenment, etc). # /cpu - Displays CPU information. # /sound - Shows your soundcard. # /netstat - Displays network information, current KB's in/out. # /disk - Displays hardrive information, has support for multiple drives but requires user-intervention to make it work for your own setup. # /uptime - Shows current uptime in days/hours/minutes. # /date - Displays the current time/day/date. # /client - Shows your current X-Chat client version. # ################################################################################### # # CREDITS: # - Gamakichi (Max) for being awesome and making the bulk of this display/work properly. # - 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, improve colors. # Only edit hardrive information, the part that may need editing is labled. Otherwise do not touch below this unless you know what you're doing. :P # ################################################################################### IRC::register("Rit Bits", "0.5.1", "", ""); IRC::print "\cC2\cBRit Bits loaded!\003 Commands are: /ritbits /client /gfx /os /desktop /cpu /sound /netstat /disk /date /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("desktop", "desktop"); 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"); IRC::add_command_handler("date", "date"); # About sub ritbits { IRC::command("( \cC6\RitBits\003 ) - \cC2A n00b script by Jen & Max for X-Chat, version 0.4.1\003 (\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("( \cC6Graphics\003 ) \cC2 $vid , $xorg \003 ( \cC6Resolution\003 ) \cC2 $res \003 ( \cC6Bits\003 ) \cC2 $bits \003"); return 1; } # Operating System sub os { $os =`uname -srm`; chomp ($os); IRC::command("( \cC6Operating System\003 ) $os "); return 1; } # Desktop Environment sub desktop { system "ps -a | grep startkde > .a1"; system "ps -a | grep gnome-session > .a2"; system "ps -a | grep fluxbox > .a3"; system "ps -a | grep enlightenment > .a4"; system "ps -a | grep xfce4 > .a5"; $desktop = `kde-config -version | grep KDE` if -s ".a1"; $desktop = `gnome-config --version | grep gnome` if -s ".a2"; $desktop = `fluxbox -version | cut -d" " -f1-2` if -s ".a3"; $desktop = `enlightenment -version | cut -d" " -f1,3` if -s ".a4"; $desktop = `xfwm4 --version | grep Xfce | cut -c10-50 | cut -d" " -f5,6` if -s ".a5"; chomp ($desktop); IRC::command("( \cC6Desktop Environment\003 ) $desktop"); system "rm .a*"; return 1; } # CPU sub cpu { $model = `sysctl hw.model | cut -d: -f2`; chomp ($model); $freq = `dmesg | grep CPU: | cut -d" " -f6 | cut -c2-8`; chomp ($freq); IRC::command("( \cC6CPU\003 ) $model ( \cC6Frequency\003 ) $freq MHz"); return 1; } # Hardrives, can support multiple disks. # Change where commented if needed. sub disk { open(AWKU, ">.awkU"); open(AWKT, ">.awkT"); print AWKU '{ print $3 }'; print AWKT '{ print $2 }'; $A = `df -h | grep -m1 /usr | awk -f .awkU`; $B = `df -h | grep -m1 /usr | awk -f .awkT`; $C = `df -h | grep -m1 /usr2 | awk -f .awkU`; #Change /usr2 to your second hardrive mount point. $D = `df -h | grep -m1 /usr2 | awk -f .awkT`; #Change /usr2 to your second hardrive mount point. chomp ($A); chomp ($B); chomp ($C); chomp ($D); #In the following IRC Command, there is /usr: and /usr2: (Seen as \cB/usr:\cB\ etc), change the "/usr:" to whatever you want it to display in the channel. IRC::command("( \cC6Hardrives\003 ) \cB/usr:\cB\ \cC6Used:\003 ".$A." \cB\\\cB\ Total: ".$B." \cB/usr2:\cB\ \cC6Used:\003 ".$C." \cB\\\cB\ Total: ".$D.""); close AWKU; close AWKT; system "rm .awk*"; return 1; } # Soundcard sub sound { $sound = `sysctl dev.pcm.0.\%desc | cut -d: -f2`; chomp ($sound); IRC::command("( \cC6Soundcard\003 ) \cC2 $sound \003"); return 1; } # Network statistic, shows KB down and up. #TODO THIS IS FUCKING B0RKED AND CRASHES X-CHAT! sub netstat { open(AWKFILEI, ">.awkI"); open(AWKFILEO, ">.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("( \cC6Network Statistics\003 ) \cB\Down\cB: \cC2 $In KB\003 \cB\\\cB\ \cBUp\cB\: \cC2 $Out KB\003"); close AWKFILEI; close AWKFILEO; system "rm .awk*"; return 1; } # Uptime sub uptime { $up = `uptime`; open(AWK1, ">.t1"); open(AWK2, ">.t2"); open(AWK3, ">.t3"); open(AWK4, ">.t4"); open(AWK5, ">.t5"); open(AWK6, ">.t6"); print AWK1 '{ print $1 }'; print AWK2 '{ print $2 }'; print AWK3 '{ print $3 }'; print AWK4 '{ print $4 }'; print AWK5 '{ print $5 }'; print AWK6 '{ print $6 }'; $when1 = `uptime | awk -f .t6`; $when2 = `uptime | awk -f .t5`; $when3 = `uptime | awk -f .t3`; $when4 = `uptime | awk -f .t4`; if ( length($up) >= 66 ) { if ( $when1 =~ /sec/ ) { $timeD = `uptime | awk -f .t3`; $timeS = `uptime | awk -f .t5`; chomp($timeD); chomp($timeS); IRC::command("( \cC2Current Uptime\003 ) ".$timeD." Day(s) ".$timeS." Second(s)"); } elsif ( $when1 =~ /min/ ) { $timeD = `uptime | awk -f .t3`; $timeM = `uptime | awk -f .t5`; chomp($timeD); chomp($timeM); IRC::command("( \cC2Current Uptime\003 ) ".$timeD." Day(s) ".$timeM." Minute(s)"); } else { if ( $when2 =~ /:/ ) { $timeH = `uptime | awk -f .t5 | awk -F: -f .t1`; $timeM = `uptime | awk -f .t5 | awk -F: -f .t2 | cut -c1-2`; $timeD = `uptime | awk -f .t3`; chomp($timeD); chomp($timeH); chomp($timeM); IRC::command("( \cC2Current Uptime\003 ) ".$timeD." Day(s) ".$timeH." Hour(s) ".$timeM." Minute(s)"); }; }; } elsif ( $when3 =~ /:/ ) { $timeH = `uptime | awk -f .t3 | awk -F: -f .t1`; $timeM = `uptime | awk -f .t3 | awk -F: -f .t2 | cut -c1-2`; chomp($timeH); chomp($timeM); IRC::command("( \cC2\cBCurrent Uptime\cB\003 ) \cB".$timeH." Hour(s) ".$timeM." Minute(s)"); } else { if ( $when4 =~ /sec/ ) { $timeS = `uptime | awk -f .t3`; chomp($timeS); IRC::command("Uptime: ".$timeS."sec"); } elsif ( $when4 =~ /min/ ) { $timeM = `uptime | awk -f .t3`; chomp($timeM); IRC::command("( \cC2\cBCurrent Uptime\cB\003 ) \cB".$timeM." Minute(s)"); }; }; close AWK1; close AWK2; close AWK3; close AWK4; close AWK5; close AWK6; system "rm .t*"; return 1; } # X-Chat version sub client { $client = IRC::get_info(0); chomp ($client); IRC::command("( \cC6IRC Client\003 ) \cC2 X-Chat $client \003"); return 1; } #Date and Time sub date { open(D1, ">.d1"); open(D2, ">.d2"); open(D3, ">.d3"); open(D4, ">.d4"); open(D6, ">.d6"); print D1 '{ print $1 }'; print D2 '{ print $2 }'; print D3 '{ print $3 }'; print D4 '{ print $4 }'; print D6 '{ print $6 }'; $_day = `date | awk -f .d1`; chomp($_day); $_mon = `date | awk -f .d2`; chomp($_mon); SWITCH: for ($_day) { /Sun/ && do { $day = "Sunday"; }; /Mon/ && do { $day = "Monday"; }; /Tue/ && do { $day = "Tuesday"; }; /Wed/ && do { $day = "Wednesday"; }; /Thu/ && do { $day = "Thursday"; }; /Fri/ && do { $day = "Friday"; }; /Sat/ && do { $day = "Saturday"; }; }; SWITCH: for ($_mon) { /Jan/ && do { $mon = "January"; }; /Feb/ && do { $mon = "February"; }; /Mar/ && do { $mon = "March"; }; /Apr/ && do { $mon = "April"; }; /May/ && do { $mon = "May"; }; /Jun/ && do { $mon = "June"; }; /Jul/ && do { $mon = "July"; }; /Aug/ && do { $mon = "August"; }; /Sep/ && do { $mon = "September"; }; /Oct/ && do { $mon = "October"; }; /Nov/ && do { $mon = "November"; }; /Dec/ && do { $mon = "December"; }; }; chomp($mon); $a = `date | awk -f .d3`; chomp($a); $b = `date | awk -f .d6`; chomp($b); $date = $mon." ".$a.", ".$b; $_hr = `date | awk -f .d4 | cut -d: -f1`; chomp($_hr); $_mn = `date | awk -f .d4 | cut -d: -f2`; chomp($_mn); if ( $_hr > 12 ) { $_hr -= 12; $time = $_hr.":".$_mn." PM"; } elsif ( $_hr == 12 ) { $time = $_hr.":".$_mn." PM"; } elsif ( $_hr < 10 ) { $_hr = `date | awk -f .d4 | cut -d: -f1 | cut -c2`; chomp($_hr); $time = $_hr.":".$_mn." AM"; }; chomp($day); chomp($date); chomp($time); IRC::command("( \cC2\cBTime\cB\003 ) $time ( \cC2\cBDay\cB\003 ) $day ( \cC2\cBDate\cB\003 ) $date"); close D1; close D2; close D3; close D4; close D6; system "rm .d*"; return 1; }