use Mojo::Webqq;
use Mojo::Webqq::Friend;
use Mojo::Util qw(md5_sum);
use Encode;
use Mojo::Webqq::Message::Recv::Message;
use Mojo::Webqq::Plugin::SmartReply;
use Sys::Hostname;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
use Net::SMTP;
my
my
my
my
my
sub section() {
my
sub vmstat() {
§ion(“VMSTAT”);
undef @arr_cpu ;
open (FH,”vmstat 2 5|”);
while() {
chomp;
next if /Linux/;
@array=split /s+/,_;
#匹配开头和结尾
print “$array[-3] isarray[-3]
”;
next if (
}
};
初始化一个客户端对象
my $client=Mojo::Webqq->new(ua_debug=>0);
my
my
#客户端进行登录
#客户端加载ShowMsg插件,用于打印发送和接收的消息到终端
$client->load("ShowMsg");
$client->load("StockInfo");
#设置接收消息事件的回调函数,在回调函数中对消息以相同内容进行回复
$client->on(receive_message=>sub{
my ($client,$msg)=@_;
#已以相同内容回复接收到的消息
#$var group name
print "-----------------";
eval{$friend=$msg->sender->nick;};
eval{$var=$msg->group->gname};
$var = encode("gbk",decode("utf8","$var"));
$frined=$msg->sender->nick;
$friend=encode("gbk",decode("utf8","$friend"));
$content=$msg->content;
#$content 消息内容
$content=encode("gbk",decode("utf8","$content"));
print $content ;
print $friend;
$client->load("SmartReply");
if ( ($friend =~/悠悠球/i) or ($friend =~/美创-应以峰/i) or ($var =~/Oracle/i) or ($friend =~/zjcap/i) or ($friend =~/scan/i) or ($var =~/oracle小筑/i) or ($var =~/PERL学习交流/i) )
{
print "come in
";
chomp($content);
print "$content is $content
";
if (($content =~/sb/i) or ($content =~/2b/i) or ($content !~/cat/i) or ($friend =~/scan/i) or ($friend =~/Flyinthesky/i and $var =~/oracle小筑/) or ($content =~/get .*?/)
or ($friend =~/zjcap/i and $var =~/PERL学习交流/)) {
if ($content =~/sb/){eval{$client->reply_message($msg,"you are really sb")}}
elsif ($content =~/2b/){eval{$client->reply_message($msg,"you are really 2b")}}
elsif ($content =~/赵/){eval{$client->reply_message($msg,"xiao li ya")}}
elsif ($content =~/爸/){eval{$client->reply_message($msg,"your die is I")}}
elsif ($content =~/爹/){eval{$client->reply_message($msg,"your father is I")}}
elsif ($content eq "get cpu"){&vmstat(); foreach (@arr_cpu){$client->reply_message($msg,"$_")} }
elsif (($content !~/cpu/) and ($content =~/get/) and ($content !~/init/) and ($content !~/shutdown/) and ($content !~/halt/) and ($content !~/rm/))
{$command=(split/s+/, "$content")[1]; $hostname=`$command`; $client->reply_message($msg,"$hostname") }
else{
eval{$client->reply_message($msg,$msg->content)}} ;
}
#你也可以使用$msg->dump() 来打印消息结构
}
}
);
#客户端开始运行
$client-> run();