| 1 | package Bot::Cobalt::IRC::Role::UserEvents; | ||
| 2 | $Bot::Cobalt::IRC::Role::UserEvents::VERSION = '0.021002'; | ||
| 3 | ## POD lives in Bot::Cobalt::IRC for now ... | ||
| 4 | |||
| 5 | use 5.12.1; | ||
| 6 | |||
| 7 | use Bot::Cobalt; | ||
| 8 | use Bot::Cobalt::Common; | ||
| 9 | |||
| 10 | use Moo::Role; | ||
| 11 | |||
| 12 | use strictures 2; | ||
| 13 | |||
| 14 | requires qw/ | ||
| 15 | ircobjs | ||
| 16 | /; | ||
| 17 | |||
| 18 | sub Bot_send_message { Bot_message(@_) } | ||
| 19 | sub Bot_message { | ||
| 20 | my ($self, $core) = splice @_, 0, 2; | ||
| 21 | |||
| 22 | unless (defined $_[2]) { | ||
| 23 | logger->error("Bot_message received without enough arguments"); | ||
| 24 | return PLUGIN_EAT_NONE | ||
| 25 | } | ||
| 26 | |||
| 27 | my $context = ${$_[0]}; | ||
| 28 | my $target = ${$_[1]}; | ||
| 29 | my $txt = ${$_[2]}; | ||
| 30 | |||
| 31 | return PLUGIN_EAT_NONE | ||
| 32 | unless defined $self->ircobjs->{$context} | ||
| 33 | and $core->is_connected($context); | ||
| 34 | |||
| 35 | ## USER event Outgoing_message for output filters | ||
| 36 | my @msg = ( $context, $target, $txt ); | ||
| 37 | my $eat = $core->send_user_event( 'message', \@msg ); | ||
| 38 | |||
| 39 | unless ($eat == PLUGIN_EAT_ALL) { | ||
| 40 | my ($target, $txt) = @msg[1,2]; | ||
| 41 | |||
| 42 | if (defined $target && defined $txt && $txt ne '') { | ||
| 43 | $self->ircobjs->{$context}->yield( 'privmsg', | ||
| 44 | $target, | ||
| 45 | $txt | ||
| 46 | ); | ||
| 47 | |||
| 48 | broadcast( 'message_sent', | ||
| 49 | $context, $target, $txt | ||
| 50 | ); | ||
| 51 | |||
| 52 | ++$core->State->{Counters}->{Sent}; | ||
| 53 | } else { | ||
| 54 | logger->error( | ||
| 55 | "Bot_message without defined target and txt after Outgoing_message" | ||
| 56 | ) | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | return PLUGIN_EAT_NONE | ||
| 61 | } | ||
| 62 | |||
| 63 | |||
| 64 | sub Bot_send_notice { Bot_notice(@_) } | ||
| 65 | sub Bot_notice { | ||
| 66 | my ($self, $core) = splice @_, 0, 2; | ||
| 67 | |||
| 68 | unless (defined $_[2]) { | ||
| 69 | logger->error("Bot_notice received without enough arguments"); | ||
| 70 | return PLUGIN_EAT_NONE | ||
| 71 | } | ||
| 72 | |||
| 73 | my $context = ${$_[0]}; | ||
| 74 | my $target = ${$_[1]}; | ||
| 75 | my $txt = ${$_[2]}; | ||
| 76 | |||
| 77 | return PLUGIN_EAT_NONE | ||
| 78 | unless defined $self->ircobjs->{$context} | ||
| 79 | and $core->is_connected($context); | ||
| 80 | |||
| 81 | ## USER event Outgoing_notice | ||
| 82 | my @notice = ( $context, $target, $txt ); | ||
| 83 | my $eat = $core->send_user_event( 'notice', \@notice ); | ||
| 84 | |||
| 85 | unless ($eat == PLUGIN_EAT_ALL) { | ||
| 86 | my ($target, $txt) = @notice[1,2]; | ||
| 87 | |||
| 88 | $self->ircobjs->{$context}->yield( 'notice', | ||
| 89 | $target, | ||
| 90 | $txt | ||
| 91 | ); | ||
| 92 | |||
| 93 | broadcast( 'notice_sent', $context, $target, $txt ); | ||
| 94 | } | ||
| 95 | |||
| 96 | return PLUGIN_EAT_NONE | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
| 100 | sub Bot_send_action { Bot_action(@_) } | ||
| 101 | sub Bot_action { | ||
| 102 | my ($self, $core) = splice @_, 0, 2; | ||
| 103 | |||
| 104 | unless (defined $_[2]) { | ||
| 105 | logger->error("Bot_action received without enough arguments"); | ||
| 106 | return PLUGIN_EAT_NONE | ||
| 107 | } | ||
| 108 | |||
| 109 | my $context = ${$_[0]}; | ||
| 110 | my $target = ${$_[1]}; | ||
| 111 | my $txt = ${$_[2]}; | ||
| 112 | |||
| 113 | return PLUGIN_EAT_NONE | ||
| 114 | unless defined $self->ircobjs->{$context} | ||
| 115 | and $core->is_connected($context); | ||
| 116 | |||
| 117 | ## USER event Outgoing_ctcp (CONTEXT, TYPE, TARGET, TEXT) | ||
| 118 | my @ctcp = ( $context, 'ACTION', $target, $txt ); | ||
| 119 | my $eat = $core->send_user_event( 'ctcp', \@ctcp ); | ||
| 120 | |||
| 121 | unless ($eat == PLUGIN_EAT_ALL) { | ||
| 122 | my ($target, $txt) = @ctcp[2,3]; | ||
| 123 | |||
| 124 | $self->ircobjs->{$context}->yield( 'ctcp', | ||
| 125 | $target, | ||
| 126 | 'ACTION '.$txt | ||
| 127 | ); | ||
| 128 | |||
| 129 | broadcast( 'ctcp_sent', $context, 'ACTION', $target, $txt ); | ||
| 130 | } | ||
| 131 | |||
| 132 | return PLUGIN_EAT_NONE | ||
| 133 | } | ||
| 134 | |||
| 135 | |||
| 136 | sub Bot_topic { | ||
| 137 | my ($self, $core) = splice @_, 0, 2; | ||
| 138 | |||
| 139 | unless (defined $_[1]) { | ||
| 140 | logger->error("Bot_topic received without enough arguments"); | ||
| 141 | return PLUGIN_EAT_NONE | ||
| 142 | } | ||
| 143 | |||
| 144 | my $context = ${$_[0]}; | ||
| 145 | my $channel = ${$_[1]}; | ||
| 146 | my $topic = defined $_[2] ? ${$_[2]} : "" ; | ||
| 147 | |||
| 148 | return PLUGIN_EAT_NONE | ||
| 149 | unless defined $self->ircobjs->{$context} | ||
| 150 | and $core->is_connected($context); | ||
| 151 | |||
| 152 | return PLUGIN_EAT_NONE unless $core->is_connected($context); | ||
| 153 | |||
| 154 | $self->irc->yield( 'topic', $channel, $topic ); | ||
| 155 | |||
| 156 | return PLUGIN_EAT_NONE | ||
| 157 | } | ||
| 158 | |||
| 159 | sub Bot_mode { | ||
| 160 | my ($self, $core) = splice @_, 0, 2; | ||
| 161 | |||
| 162 | unless (defined $_[2]) { | ||
| 163 | logger->error("Bot_mode received without enough arguments"); | ||
| 164 | return PLUGIN_EAT_NONE | ||
| 165 | } | ||
| 166 | |||
| 167 | my $context = ${$_[0]}; | ||
| 168 | my $target = ${$_[1]}; ## channel or self normally | ||
| 169 | my $modestr = ${$_[2]}; ## modes + args | ||
| 170 | |||
| 171 | return PLUGIN_EAT_NONE | ||
| 172 | unless defined $self->ircobjs->{$context} | ||
| 173 | and $core->is_connected($context); | ||
| 174 | |||
| 175 | my ($mode, @args) = split ' ', $modestr; | ||
| 176 | |||
| 177 | $self->ircobjs->{$context}->yield( 'mode', $target, $mode, @args ); | ||
| 178 | |||
| 179 | return PLUGIN_EAT_NONE | ||
| 180 | } | ||
| 181 | |||
| 182 | sub Bot_kick { | ||
| 183 | my ($self, $core) = splice @_, 0, 2; | ||
| 184 | |||
| 185 | unless (defined $_[2]) { | ||
| 186 | logger->error("Bot_kick received without enough arguments"); | ||
| 187 | return PLUGIN_EAT_NONE | ||
| 188 | } | ||
| 189 | |||
| 190 | my $context = ${$_[0]}; | ||
| 191 | my $channel = ${$_[1]}; | ||
| 192 | my $target = ${$_[2]}; | ||
| 193 | my $reason = defined $_[3] ? ${$_[3]} : 'Kicked'; | ||
| 194 | |||
| 195 | return PLUGIN_EAT_NONE | ||
| 196 | unless defined $self->ircobjs->{$context} | ||
| 197 | and $core->is_connected($context); | ||
| 198 | |||
| 199 | return PLUGIN_EAT_NONE unless $core->is_connected($context); | ||
| 200 | |||
| 201 | $self->ircobjs->{$context}->yield( 'kick', $channel, $target, $reason | ||
| 202 | ); | ||
| 203 | |||
| 204 | return PLUGIN_EAT_NONE | ||
| 205 | } | ||
| 206 | |||
| 207 | |||
| 208 | sub Bot_join { | ||
| 209 | my ($self, $core) = splice @_, 0, 2; | ||
| 210 | |||
| 211 | unless (defined $_[1]) { | ||
| 212 | logger->error("Bot_join received without enough arguments"); | ||
| 213 | return PLUGIN_EAT_NONE | ||
| 214 | } | ||
| 215 | |||
| 216 | my $context = ${$_[0]}; | ||
| 217 | my $channel = ${$_[1]}; | ||
| 218 | |||
| 219 | return PLUGIN_EAT_NONE | ||
| 220 | unless defined $self->ircobjs->{$context} | ||
| 221 | and $core->is_connected($context); | ||
| 222 | |||
| 223 | $self->ircobjs->{$context}->yield( 'join', $channel ); | ||
| 224 | |||
| 225 | return PLUGIN_EAT_NONE | ||
| 226 | } | ||
| 227 | |||
| 228 | sub Bot_part { | ||
| 229 | my ($self, $core) = splice @_, 0, 2; | ||
| 230 | |||
| 231 | unless (defined $_[1]) { | ||
| 232 | logger->error("Bot_part received without enough arguments"); | ||
| 233 | return PLUGIN_EAT_NONE | ||
| 234 | } | ||
| 235 | |||
| 236 | my $context = ${$_[0]}; | ||
| 237 | my $channel = ${$_[1]}; | ||
| 238 | my $reason = defined $_[2] ? ${$_[2]} : 'Leaving' ; | ||
| 239 | |||
| 240 | return PLUGIN_EAT_NONE | ||
| 241 | unless defined $self->ircobjs->{$context} | ||
| 242 | and $core->is_connected($context); | ||
| 243 | |||
| 244 | $self->ircobjs->{$context}->yield( 'part', $channel, $reason ); | ||
| 245 | |||
| 246 | return PLUGIN_EAT_NONE | ||
| 247 | } | ||
| 248 | |||
| 249 | sub Bot_send_raw { | ||
| 250 | my ($self, $core) = splice @_, 0, 2; | ||
| 251 | |||
| 252 | unless (defined $_[1]) { | ||
| 253 | logger->error("Bot_send_Raw received without enough arguments"); | ||
| 254 | return PLUGIN_EAT_NONE | ||
| 255 | } | ||
| 256 | |||
| 257 | my $context = ${$_[0]}; | ||
| 258 | my $raw = ${$_[1]}; | ||
| 259 | |||
| 260 | return PLUGIN_EAT_NONE | ||
| 261 | unless defined $self->ircobjs->{$context} | ||
| 262 | and $core->is_connected($context); | ||
| 263 | |||
| 264 | $self->ircobjs->{$context}->yield( 'quote', $raw ); | ||
| 265 | |||
| 266 | broadcast( 'raw_sent', $context, $raw ); | ||
| 267 | |||
| 268 | return PLUGIN_EAT_NONE | ||
| 269 | } | ||
| 270 | |||
| 271 | |||
| 272 | 1 |