]>
iEval git - app-fonbot-daemon.git/blob - IRC.pm
71904c5c20384f6f0ab6906a24ed2f7062deb962
1 package App
:: FonBot
:: Plugin
:: IRC
;
3 our $VERSION = '0.000_5' ;
9 use Apache2
:: Authen
:: Passphrase qw
/pwcheck/ ;
10 use IRC
:: Utils qw
/parse_user/ ;
11 use Log
:: Log4perl qw
// ;
13 use POE
:: Component
:: IRC qw
// ;
15 use Text
:: ParseWords qw
/shellwords/ ;
16 use subs qw
/shutdown/ ;
18 use App
:: FonBot
:: Plugin
:: Common
;
20 ##################################################
28 $self ->{ log }-> info ( "initializing $ns " );
29 tie
my %nick_to_username , DB_File
=> "nick_to_username- $ns .db" ;
30 $self ->{ nick_to_username
}= \
%nick_to_username ;
37 $selves { $ns }->{ log }-> info ( "finishing $ns " );
38 $selves { $ns }->{ irc
}-> yield ( shutdown => "finishing $ns " ) if defined $selves { $ns }->{ irc
};
39 untie $selves { $ns }->{ nick_to_username
};
40 POE
:: Kernel
-> post ( $selves { $ns }->{ session
} => 'shutdown' );
44 ##################################################
51 log => Log
:: Log4perl
-> get_logger ( $ns ),
56 $self ->{ session
} = POE
:: Session
-> create (
57 object_states
=> [ $self => [ '_start' , 'send_message' , 'irc_001' , 'irc_msg' , 'irc_public' , 'shutdown' ] ],
64 my ( $from , $msg , $self )= @_ [ ARG0
, ARG2
, OBJECT
];
65 my $nick = parse_user
$from ;
67 my $username = $self ->{ nick_to_username
}{ $from };
68 my $address = $_ [ KERNEL
]-> alias_list ;
72 my @args = shellwords
$msg ;
77 $self ->{ irc
}-> yield ( privmsg
=> $nick , $from );
81 my ( $user , $pass ) = @args ;
83 eval { pwcheck
$user , $pass };
86 $self ->{ log }-> debug ( "Login for $user failed" );
87 $self ->{ irc
}-> yield ( privmsg
=> $nick , 'Bad username/password combination' );
89 $self ->{ log }-> debug ( "Login for $user succeded" );
90 $self ->{ nick_to_username
}{ $from } = $user ;
91 $self ->{ irc
}-> yield ( privmsg
=> $nick , "Logged in as $user " );
96 delete $self ->{ nick_to_username
}{ $from };
100 if ( defined $username ) {
101 $self ->{ prefix
}{ $username } = [ @args ];
103 $self ->{ irc
}-> yield ( privmsg
=> $nick , 'You are not logged in. Say "login your_username your_password" (where your_username and your_password are your login credentials) to login.' );
108 if ( defined $username ) {
109 delete $self ->{ prefix
}{ $username }
111 $self ->{ irc
}-> yield ( privmsg
=> $nick , 'You are not logged in. Say "login your_username your_password" (where your_username and your_password are your login credentials) to login.' );
116 if ( defined $username ) {
117 $ok_user_addresses { " $username $address " }= 1 ;
118 $self ->{ log }-> debug ( "Command $cmd @args from $username " );
119 if ( exists $self ->{ prefix
}{ $username }) {
120 sendmsg
$username , undef , $address , @
{ $self ->{ prefix
}{ $username }}, $cmd , @args ;
122 sendmsg
$username , undef , $address , $cmd , @args ;
125 $self ->{ irc
}-> yield ( privmsg
=> $nick , 'You are not logged in. Say "login your_username your_password" (where your_username and your_password are your login credentials) to login.' );
141 my ( $self , $address , $content )= @_ [ OBJECT
, ARG0
, ARG1
];
142 $self ->{ irc
}-> yield ( privmsg
=> $address , $_ ) for map { unpack '(A400)*' } split " \n " , $content
146 $_ [ KERNEL
]-> alias_remove ( $_ ) for $_ [ KERNEL
]-> alias_list ;
This page took 0.06654 seconds and 3 git commands to generate.