X-Git-Url: https://git.harvie.cz/?a=blobdiff_plain;f=purple%2Fanswerscripts.d%2F10-menu.pl;h=0fcccb0f1b7333475efbe497a0e011b83b7fdbf4;hb=2aa9b0a92c77cbc9f9f44b0b5596650a1c7233f1;hp=40f22b4b2bd57e74daac0c22451bd5d7a75ae750;hpb=8ddbf94e3bd6d96862182bc6a054a2d411016e02;p=mirrors%2Flibpurple-core-answerscripts.git diff --git a/purple/answerscripts.d/10-menu.pl b/purple/answerscripts.d/10-menu.pl index 40f22b4..0fcccb0 100755 --- a/purple/answerscripts.d/10-menu.pl +++ b/purple/answerscripts.d/10-menu.pl @@ -2,16 +2,21 @@ #Just for you to see that you can use almost any language :-) use strict; use warnings; -use Switch; +use v5.10; #given/when (if you need to use older PERL, you can find older version in GIT) -switch ($ENV{ANSW_MSG}) { - case /^!help$/ { print qx{ grep -o 'case /[^\$/]*' "$0" | grep -o '!.*' | tr '\n' ',' }; } - case /^!ping$/ { print "PONG"; } - case /^!whoami$/ { print "You are: $ENV{ANSW_FROM}"; } - case /^!status$/ { print "[$ENV{ANSW_STATUS}] $ENV{ANSW_STATUS_MSG}"; } - case /^!(reboot|reset|restart|halt)$/ { print "Broadcast message: The system is going down for reboot NOW !!"; } - case /^!google/ { print "UTFG Yourself: http://google.com/"; } - case /^!uptime$/ { print qx{uptime}; } - case /^!date$/ { print qx{date}; } - case /^!dmesg$/ { print qx{ dmesg | tail -n 5 | tr '\n' '\t' } } +$ENV{ANSW_MSG} =~ m/^([^\s]*)\s*(.*)$/; +my $args = $2; +given ($1) { + when (/^!help$/) { print qx{ grep -o 'when \(/[^\$/]*' "$0" | grep -o '!.*' | tr '\n' ',' }."\n"; } + when (/^!ping$/) { print "PONG"; } + when (/^!whoami$/) { print "You are $ENV{ANSW_R_ALIAS} also known as $ENV{ANSW_R_NAME}"; } + when (/^!whoareyou$/) { print "Hello, my name is $ENV{ANSW_L_ALIAS} ($ENV{ANSW_L_NAME}) ;-)"; } + when (/^!version$/) { print "$ENV{ANSW_L_AGENT} $ENV{ANSW_L_AGENT_VERSION}"; } + when (/^!status$/) { print "[$ENV{ANSW_L_STATUS}] $ENV{ANSW_L_STATUS_MSG}"; } + when (/^!(reboot|reset|restart|halt)$/) { print "Broadcast message: The system is going down for reboot NOW !!"; } + when (/^!google$/) { my $q = $args; $q =~ s/ /+/g; print "UTFG Yourself: http://google.com/search?q=$q"; } + when (/^!uptime$/) { print qx{uptime}; } + when (/^!date$/) { print qx{date}; } + when (/^!dmesg$/) { print qx{ dmesg | tail -n 5 | tr '\n' '\t' } } + when (/^!df$/) { print qx{ df -hlP / | tail -n 1 } } }