Skip to content

Commit

Permalink
sendFile abc.jpg #没有以 "/" 或者 "." 开头,则以 media_dir 参数指定的目录查找文件
Browse files Browse the repository at this point in the history
  • Loading branch information
hexsum committed Apr 8, 2018
1 parent 06ef948 commit 5481416
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
9 changes: 6 additions & 3 deletions doc/Weixin.pod
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ Mojo::Weixin - A Weixin Client Framework base on Mojolicious
load_friend #0|1 默认是0 是否初始为每个好友生成irc虚拟帐号并加入频道 #我的好友
upload_api #图床api地址,将图片转为连接,方便在irc上查看图片
#支持兼容 http://img.vim-cn.com/ 的接口,考虑到隐私问题,默认不开启
media_dir #sendFile指令发送文件的默认目录,默认值与 new 中的 media_dir 参数相同

#以下参数需要 Mojo::IRC::Server::Chinese v1.8.1及以上版本

Expand Down Expand Up @@ -926,9 +927,11 @@ Mojo::Weixin - A Weixin Client Framework base on Mojolicious
特殊自定义指令:

#irc消息中 `sendFile `或者`!!`开头,则发送本地或者来自网络的图片、文件等媒体
sendFile /tmp/abc.jpg
sendFile http://example.com/abc.jpg
!!/tmp/abc.jpg
sendFile /tmp/abc.jpg #以绝对路径发送文件
sendFile http://example.com/abc.jpg #以url发送文件,会先把url指定的文件拉取下来
!!/tmp/abc.jpg #以绝对路径发送文件
sendFile ./tmp/abc.jpg #以相对路径发送文件
sendFile abc.jpg #没有以 "/" 或者 "." 开头,则以 media_dir 参数指定的目录查找文件

微信好友会默认加入到irc的 '#我的好友' 频道中

Expand Down
9 changes: 6 additions & 3 deletions lib/Mojo/Weixin.pod
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,7 @@ Mojo::Weixin - A Weixin Client Framework base on Mojolicious
load_friend #0|1 默认是0 是否初始为每个好友生成irc虚拟帐号并加入频道 #我的好友
upload_api #图床api地址,将图片转为连接,方便在irc上查看图片
#支持兼容 http://img.vim-cn.com/ 的接口,考虑到隐私问题,默认不开启
media_dir #sendFile指令发送文件的默认目录,默认值与 new 中的 media_dir 参数相同

#以下参数需要 Mojo::IRC::Server::Chinese v1.8.1及以上版本

Expand Down Expand Up @@ -926,9 +927,11 @@ Mojo::Weixin - A Weixin Client Framework base on Mojolicious
特殊自定义指令:

#irc消息中 `sendFile `或者`!!`开头,则发送本地或者来自网络的图片、文件等媒体
sendFile /tmp/abc.jpg
sendFile http://example.com/abc.jpg
!!/tmp/abc.jpg
sendFile /tmp/abc.jpg #以绝对路径发送文件
sendFile http://example.com/abc.jpg #以url发送文件,会先把url指定的文件拉取下来
!!/tmp/abc.jpg #以绝对路径发送文件
sendFile ./tmp/abc.jpg #以相对路径发送文件
sendFile abc.jpg #没有以 "/" 或者 "." 开头,则以 media_dir 参数指定的目录查找文件

微信好友会默认加入到irc的 '#我的好友' 频道中

Expand Down
8 changes: 8 additions & 0 deletions lib/Mojo/Weixin/Plugin/IRCShell.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package Mojo::Weixin::Plugin::IRCShell;
$Mojo::Weixin::Plugin::IRCShell::PRIORITY = 99;
use strict;
use List::Util qw(first);
use File::Spec ();
BEGIN{
$Mojo::Weixin::Plugin::IRCShell::has_mojo_irc_server = 0;
eval{
Expand All @@ -17,6 +18,7 @@ sub call{
$client->die("请先安装模块 Mojo::IRC::Server::Chinese") if not $Mojo::Weixin::Plugin::IRCShell::has_mojo_irc_server;
my $master_irc_nick = $data->{master_irc_nick};
my $upload_api = $data->{upload_api}; #'http://img.vim-cn.com/';
my $media_dir = $data->{media_dir} // $client->media_dir;
my $is_load_friend = defined $data->{load_friend}?$data->{load_friend}:0;
my %mode = ref($data->{mode}) eq "HASH"?%{$data->{mode}}:();
$data->{auto_join_channel} = 1 if not defined $data->{auto_join_channel};
Expand Down Expand Up @@ -54,6 +56,9 @@ sub call{
#if ($content =~ m/^(?:sendFile |!!)([^\s]+)$/i) {
if ($content =~ m/^(?:sendFile |!!)(?|"([^"]+)"|'([^']+)'|([^\s"']+))/i) {
my $media_path = $1;
if($media_path !~ /^(\/|\.)/){#没有使用绝对路径或者相对路径
$media_path = File::Spec->catfile($media_dir,$media_path);
}
if(-f $media_path or $media_path=~/^https?:\/\//){
$group->send_media($media_path);
}
Expand Down Expand Up @@ -105,6 +110,9 @@ sub call{
#if ($content =~ m/^(?:sendFile |!!)([^\s]+)$/i) {
if ($content =~ m/^(?:sendFile |!!)(?|"([^"]+)"|'([^']+)'|([^\s"']+))/i) {
my $media_path = $1;
if($media_path !~ /^(\/|\.)/){#没有使用绝对路径或者相对路径
$media_path = File::Spec->catfile($media_dir,$media_path);
}
if(-f $media_path or $media_path=~/^https?:\/\//){
$friend->send_media($media_path);
}
Expand Down

0 comments on commit 5481416

Please sign in to comment.