Last active
December 15, 2015 20:19
-
-
Save ichigotake/5317469 to your computer and use it in GitHub Desktop.
[動かない] 過去の発言をランダムにサルベージするYanchaプラグイン。サーバーをforkするためか、動作が不安定になる。別の実装に切り替えないとダメ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Yancha::Plugin::SalvageDarkHistory; | |
use strict; | |
use warnings; | |
sub setup { | |
my ($class, $sys) = @_;$sys->register_hook( 'before_send_post', sub { | |
my $int = int rand 100; #数字が低いほど高確率 | |
return if $int; | |
my $pid = fork; | |
return if $pid; | |
sleep 5; | |
my ( $sys, $socket, $post, $ctx ) = @_; | |
my $posts= $sys->data_storage->search_post( {}, {limit => 1, order_by => 'rand()'} ); | |
my $salvaged = $posts->[0]; | |
my $id = $salvaged->{id}; | |
my @ids; | |
push @ids, $_ for ($id-5..$id+5); | |
my $quot = $sys->config->{server_info}->{url}.'/quotation.html?id=' . join(',', @ids); | |
$ctx->{ record_post } = 0; | |
$post->{user_key} = '-:-2'; | |
$post->{nickname} = 'salvage_dark_history'; | |
$post->{text} = sprintf "%s\n\n%s: %s", $quot,$salvaged->{nickname},$salvaged->{text}; | |
$post->{profile_url} = 'salvage_dark_history'; | |
$post->{profile_image_url} = 'salvage_dark_history'; | |
$post->{id} = -2; | |
} ); | |
} | |
1; | |
__DATA__ | |
=head1 NAME | |
Yancha::Plugin::SalvageDarkHistory - 過去の発言をランダムにサルベージするYanchaプラグイン | |
=head1 DESCRIPTION | |
誰かが発言した時に一定確率で、過去の発言をランダムに抽出して流します | |
=head1 AUTHOR | |
ichigotake | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment