#!/usr/bin/perl use strict; use warnings; use POE qw(Sugar::Args Component::IRC); use Class::Inspector; use IO::All; use Getopt::Long; use DateTime; use List::MoreUtils; my $channel = '#test'; my $datafile = '/tmp/kouen.dat'; my $nick = 'kouen_mama'; my $server = 'localhost'; my $port = 6667; my $interval = 5; my $CMD_START = "公園デビューします"; my $CMD_OTOMODACHI = "公園のお友達は誰"; my $conf = { status => 'sleep' }; my $result = GetOptions ( "channel=s" => \$channel, "datafile=s" => \$datafile, "nick=s" => \$nick, "server=s" => \$server, "port=i" => \$port, "interval=i" => \$interval, ); POE::Component::IRC->spawn( alias => 'bot', nick => $nick, server => $server, port => $port, ); POE::Session->create( package_states => [ main => Class::Inspector->methods('main') ], args => \@ARGV, ); POE::Kernel->sig(INT => sub { POE::Kernel->stop }); POE::Kernel->run; sub _start { my $poe = sweet_args; $poe->kernel->post(bot => register => 'all'); $poe->kernel->post(bot => connect => {}); } sub irc_001 { my $poe = sweet_args; $poe->kernel->post($poe->sender => join => $channel); } sub irc_public { my $poe = sweet_args; my ($who ) = split('!' , $poe->args->[0] ); my $what = $poe->args->[2] ; # 公園デビュー開始最低条件 if( $CMD_START eq $what && $conf->{status} eq 'sleep' ) { my $io = io( $datafile ); my @_otomodachis = (); my $str_otomodaches = ''; while( my $line = $io->getline ) { chomp $line; my $name = $line; $str_otomodaches .= ' ' . $name ; push ( @_otomodachis , $name ); } if( scalar @_otomodachis == 0 || List::MoreUtils::none { $who eq $_ } @_otomodachis ) { $conf->{status} = 'introducing'; $conf->{til} = time + (60* $interval ); $conf->{otomodachis} = \@_otomodachis; $conf->{new_otomodachi} = $who ; $poe->kernel->post( $poe->sender => notice => $channel => $who . 'さんが公園デビューをするよ!お友達集まって!' . $str_otomodaches ); } else { # 既にデビューしてるよ。 $poe->kernel->post( $poe->sender => notice => $channel => $who . 'さんはすでに公園デビューしたお友達だよねー' ); } } if( $conf->{status} eq 'introducing' ) { # 終わり処理 if( $conf->{til} < time ) { $poe->kernel->post( $poe->sender => notice => $channel => $conf->{new_otomodachi} . 'さんがデビューできたよ!みんな仲良くしようね。' ); # 登録処理、初期化処理 io($datafile)->append($conf->{new_otomodachi} . "\n"); $conf = { status => 'sleep' }; } else { # 自分で発言 if( $conf->{new_otomodachi} eq $who ) { $poe->kernel->post( $poe->sender => notice => $channel => $conf->{new_otomodachi} . 'さん、その調子!いい感じだわ。' ); } # お友達が発言 else { my $reg = $conf->{new_otomodachi} ; # TODO RANDOM # 愛情のある発言 if( $what =~ /$reg/ ) { $poe->kernel->post( $poe->sender => notice => $channel => 'そうそう仲良くしようね。'. $who . 'さん偉いねー。' ); } # 愛情のない発言 else { $poe->kernel->post( $poe->sender => notice => $channel => $who . 'さん、' . $conf->{new_otomodachi} .'ちゃんに話しかけてあげてね。' ); } } } } } 1; =head1 NAME bot-kouen-debyu.pl - IRC公園デビューボット =head1 DESCRIPTION 公園デビューを愛情をもって見守るボット。お友達の皆さんも、デビューの人には仲良くしてあげてくださいね。 =head1 SYNOPSIS perl bot-kouen-debyu.pl --interval=5 --server='irc.freenode.net' --channel='#CodeRepos' --nick='kouen_mama' --datafile='/tmp/bot-kouen.dat' =head1 機能 =head2 「公園デビューします!」機能 公園デビューします!と、デビューがまだの人が発言すると、ボットさんが、愛情をもって見守り始めます。 具体的には、5分間の間、他の人が「@デビューしている人のnick 」をつけて発言しないと、怒ります。また、デビューしている人が発言すると、愛情を持って応援して上げます。 5分経ったら、デビュー終了処理をします。(イベントの発生は発言なので、実際には5分たった後に初めて発言した人の時に終了処理をします。) =head1 TODO =head2 公園デビューした時のログを確認できる、「公園デビュー走馬灯 @nick」コマンド(仮案) =head2 公園デビューやり直し機能。 発言数が少なかったり、お友達があまりその時にいなかった時は、公園デビュー失敗にする =head2 例外処理 何もしてない。途中で抜けたときとか。 =head1 作成動機 初めての部屋で発言しようとするとき、公園デビューを見守ってくれる、ママが欲しいと思ったから。また、DISられたい、添削されたい、修正されたいから。 19:41 (shunirr) さっきjoinしたから今まさにドキドキしてる 19:42 (Yappo) 公園デビューてきなものか =head1 AUTHOR Yet Another Newbie tomyhero =cut