| 1 | package Mojo::Webqq::Plugin::MobileInfo; | ||
| 2 | our $PRIORITY = 93; | ||
| 3 | use Mojo::DOM; | ||
| 4 | use Encode; | ||
| 5 | |||
| 6 | sub call{ | ||
| 7 | my $client = shift; | ||
| 8 | my $data = shift; | ||
| 9 | my $callback = sub{ | ||
| 10 | my($client,$msg)=@_; | ||
| 11 | return if $msg->class eq "send" and $msg->from ne "api" and $msg->from ne "irc"; | ||
| 12 | if ($msg->content =~ m/^手机\s+([0-9]{7,11})/g) { | ||
| 13 | my $phone = $1; | ||
| 14 | return unless $phone; | ||
| 15 | $msg->allow_plugin(0); | ||
| 16 | my $reply; | ||
| 17 | my $sender_nick = $msg->sender->displayname; | ||
| 18 | $client->http_get("http://www.ip138.com:8080/search.asp?mobile=$phone&action=mobile",sub{ | ||
| 19 | my $data = shift; | ||
| 20 | return unless defined $data; | ||
| 21 | $data =~ s/ //g; | ||
| 22 | my $dom = Mojo::DOM->new($data); | ||
| 23 | my @commands = $dom->find('td.tdc2')->each;#获取所有的子命令 | ||
| 24 | #$client->debug(encode('utf8',decode('gbk',join(" ",@commands)))); | ||
| 25 | if (scalar(@commands) == 5) { | ||
| 26 | $reply .= "\@$sender_nick 您查询的手机号码信息如下:\n"; | ||
| 27 | $reply .= "手机号: ".(shift @commands)->text."\n"; | ||
| 28 | $reply .= "归属地: ".encode("utf8",decode("gbk",(shift @commands)->text))."\n"; | ||
| 29 | $reply .= "卡类型: ".encode("utf8",decode("gbk",(shift @commands)->text))."\n"; | ||
| 30 | $reply .= "区 号: ".(shift @commands)->text."\n"; | ||
| 31 | $reply .= "邮 编: ".(shift @commands)->text; | ||
| 32 | } | ||
| 33 | unless ($reply) { | ||
| 34 | return; | ||
| 35 | } | ||
| 36 | $client->reply_message($msg,$reply); | ||
| 37 | }); | ||
| 38 | } | ||
| 39 | }; | ||
| 40 | $client->on(receive_message=>$callback,send_message=>$callback); | ||
| 41 | } | ||
| 42 | 1; |