Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

user message処理内でプラグイン間で連携できるように

  • Loading branch information...
commit 6740dd5330b8c5306e030017d945ecd4b49c8f71 1 parent f4d121f
@makamaka makamaka authored
Showing with 8 additions and 5 deletions.
  1. +2 −2 lib/Yancha.pm
  2. +6 −3 lib/Yancha/Core.pm
View
4 lib/Yancha.pm
@@ -163,7 +163,7 @@ sub register_calling_tag {
}
sub tag_trigger {
- my ( $self, $socket, $tags, $message_ref ) = @_;
+ my ( $self, $socket, $tags, $message_ref, $ctx ) = @_;
unless ( scalar( @$tags ) ) {
for ( @{ $self->{ tag_trigger_no_tag } || [] } ) {
@@ -176,7 +176,7 @@ sub tag_trigger {
next unless exists $self->{ tag_trigger }->{ $_ };
for ( @{ $self->{ tag_trigger }->{ $_ } } ) {
my ($subref, $args) = @{ $_ };
- $subref->( $self, $socket, $_, $message_ref, $tags, @$args );
+ $subref->( $self, $socket, $_, $tags, $message_ref, $ctx, @$args );
}
}
}
View
9 lib/Yancha/Core.pm
@@ -122,12 +122,13 @@ sub join_tag { #参加タグの登録(タグ毎のコネクションプール
sub user_message {
my ( $self, $socket, $message ) = @_;
+ my $ctx = { record_post => 1 }; # このメッセージに対する各プラグイン間でのやりとり用
- $self->sys->call_hook( 'user_message', $socket, \$message );
+ $self->sys->call_hook( 'user_message', $socket, \$message, $ctx );
my @tags = $self->sys->extract_tags_from_text( $message );
- $self->sys->tag_trigger( $socket, \@tags, \$message );
+ $self->sys->tag_trigger( $socket, \@tags, \$message, $ctx );
$self->sys->add_default_tag( \@tags, \$message ) unless @tags;
@@ -144,7 +145,9 @@ sub user_message {
my $post = $self->sys->data_storage
->make_post({ text => $message, tags => [ @tags ], user => $user });
- $post = $self->sys->data_storage->add_post( $post );
+ $self->sys->call_hook( 'before_send_post', $socket, $post, $ctx );
+
+ $post = $self->sys->data_storage->add_post( $post ) if $ctx->{ record_post };
$post->{is_message_log} = JSON::false;
Please sign in to comment.
Something went wrong with that request. Please try again.