diff options
| -rw-r--r-- | beinc_weechat.py | 93 |
1 files changed, 62 insertions, 31 deletions
diff --git a/beinc_weechat.py b/beinc_weechat.py index fe2772c..59c27db 100644 --- a/beinc_weechat.py +++ b/beinc_weechat.py | |||
| @@ -253,6 +253,25 @@ class WeechatTarget(object): | |||
| 253 | 'BEINC DEBUG: send_notify_message_notification-ERROR ' | 253 | 'BEINC DEBUG: send_notify_message_notification-ERROR ' |
| 254 | 'for "{0}": {1}'.format(self.__name, e)) | 254 | 'for "{0}": {1}'.format(self.__name, e)) |
| 255 | 255 | ||
| 256 | def send_broadcast_notification(self, message): | ||
| 257 | """ | ||
| 258 | """ | ||
| 259 | try: | ||
| 260 | post_values = {'title': 'BEINC broadcast', | ||
| 261 | 'message': message, | ||
| 262 | 'password': self.__password} | ||
| 263 | data = urllib.urlencode(post_values) | ||
| 264 | if not self.__send_beinc_message(data) and self.__debug: | ||
| 265 | beinc_prnt( | ||
| 266 | 'BEINC DEBUG: send_broadcast_notification-ERROR ' | ||
| 267 | 'for "{0}": __send_beinc_message -> False'.format( | ||
| 268 | self.__name)) | ||
| 269 | except Exception as e: | ||
| 270 | if self.__debug: | ||
| 271 | beinc_prnt( | ||
| 272 | 'BEINC DEBUG: send_broadcast_notification-ERROR ' | ||
| 273 | 'for "{0}": {1}'.format(self.__name, e)) | ||
| 274 | |||
| 256 | def __fetch_formatted_str(self, template, values): | 275 | def __fetch_formatted_str(self, template, values): |
| 257 | """ | 276 | """ |
| 258 | """ | 277 | """ |
| @@ -309,6 +328,19 @@ def beinc_prnt(message_str): | |||
| 309 | weechat.prnt('', message_str) | 328 | weechat.prnt('', message_str) |
| 310 | 329 | ||
| 311 | 330 | ||
| 331 | def beinc_cmd_broadcast_handler(cmd_tokens): | ||
| 332 | """ | ||
| 333 | handles: '/beinc broadcast' command actions | ||
| 334 | """ | ||
| 335 | if not cmd_tokens: | ||
| 336 | beinc_prnt('beinc broadcast <message>') | ||
| 337 | return weechat.WEECHAT_RC_OK | ||
| 338 | for target in target_list: | ||
| 339 | if target.enabled: | ||
| 340 | target.send_broadcast_notification(' '.join(cmd_tokens)) | ||
| 341 | return weechat.WEECHAT_RC_OK | ||
| 342 | |||
| 343 | |||
| 312 | def beinc_cmd_target_handler(cmd_tokens): | 344 | def beinc_cmd_target_handler(cmd_tokens): |
| 313 | """ | 345 | """ |
| 314 | handles: '/beinc target' command actions | 346 | handles: '/beinc target' command actions |
| @@ -362,6 +394,8 @@ def beinc_command(data, buffer_obj, args): | |||
| 362 | elif args == 'reload': | 394 | elif args == 'reload': |
| 363 | beinc_prnt('Reloading BEINC...') | 395 | beinc_prnt('Reloading BEINC...') |
| 364 | beinc_init() | 396 | beinc_init() |
| 397 | elif cmd_tokens[0] == 'broadcast': | ||
| 398 | return beinc_cmd_broadcast_handler(cmd_tokens[1:]) | ||
| 365 | elif cmd_tokens[0] == 'target': | 399 | elif cmd_tokens[0] == 'target': |
| 366 | return beinc_cmd_target_handler(cmd_tokens[1:]) | 400 | return beinc_cmd_target_handler(cmd_tokens[1:]) |
| 367 | else: | 401 | else: |
| @@ -383,40 +417,39 @@ def beinc_privmsg_handler(data, signal, signal_data): | |||
| 383 | ph_values['own_nick'] = weechat.info_get('irc_nick', ph_values['server']) | 417 | ph_values['own_nick'] = weechat.info_get('irc_nick', ph_values['server']) |
| 384 | ph_values['channel'] = prvmsg_dict['arguments'].split(':')[0].strip() | 418 | ph_values['channel'] = prvmsg_dict['arguments'].split(':')[0].strip() |
| 385 | ph_values['source_nick'] = prvmsg_dict['nick'] | 419 | ph_values['source_nick'] = prvmsg_dict['nick'] |
| 386 | ph_values['message'] = ':'.join(prvmsg_dict['arguments'].split(':')[1:]).strip() | 420 | ph_values['message'] = ':'.join( |
| 421 | prvmsg_dict['arguments'].split(':')[1:]).strip() | ||
| 387 | if ph_values['channel'] == ph_values['own_nick']: | 422 | if ph_values['channel'] == ph_values['own_nick']: |
| 388 | # priv messages are handled here | 423 | # priv messages are handled here |
| 389 | if not global_values['global_private_messages_policy']: | 424 | if not global_values['global_private_messages_policy']: |
| 390 | return weechat.WEECHAT_RC_OK | 425 | return weechat.WEECHAT_RC_OK |
| 391 | p_messages_policy = global_values['global_private_messages_policy'] | 426 | p_messages_policy = global_values['global_private_messages_policy'] |
| 392 | if p_messages_policy == BEINC_POLICY_LIST_ONLY and \ | 427 | if p_messages_policy == BEINC_POLICY_LIST_ONLY and \ |
| 393 | '{0}.{1}'.format( | 428 | '{0}.{1}'.format( |
| 394 | ph_values['server'], | 429 | ph_values['server'], |
| 395 | ph_values['source_nick'].lower() | 430 | ph_values['source_nick'].lower() |
| 396 | ) not in global_values['global_nicks']: | 431 | ) not in global_values['global_nicks']: |
| 397 | return weechat.WEECHAT_RC_OK | 432 | return weechat.WEECHAT_RC_OK |
| 398 | for target in target_list: | 433 | for target in target_list: |
| 399 | if not target.enabled: | 434 | if not target.enabled: |
| 400 | continue | 435 | continue |
| 401 | if target.private_messages_policy == BEINC_POLICY_ALL or \ | 436 | p_messages_policy = target.private_messages_policy |
| 402 | ( | 437 | if p_messages_policy == BEINC_POLICY_ALL or ( |
| 403 | target.private_messages_policy == BEINC_POLICY_LIST_ONLY and \ | 438 | p_messages_policy == BEINC_POLICY_LIST_ONLY and |
| 404 | '{0}.{1}'.format( | 439 | '{0}.{1}'.format( |
| 405 | ph_values['server'], | 440 | ph_values['server'], |
| 406 | ph_values['source_nick'].lower()) in target.nicks | 441 | ph_values['source_nick'].lower()) in target.nicks): |
| 407 | ): | ||
| 408 | target.send_private_message_notification(ph_values) | 442 | target.send_private_message_notification(ph_values) |
| 409 | elif ph_values['own_nick'].lower() in ph_values['message'].lower(): | 443 | elif ph_values['own_nick'].lower() in ph_values['message'].lower(): |
| 410 | # notify messages are handled here | 444 | # notify messages are handled here |
| 411 | if not global_values['global_notifications_policy']: | 445 | if not global_values['global_notifications_policy']: |
| 412 | return weechat.WEECHAT_RC_OK | 446 | return weechat.WEECHAT_RC_OK |
| 413 | notifications_policy = global_values['global_notifications_policy'] | 447 | notifications_policy = global_values['global_notifications_policy'] |
| 414 | if notifications_policy == BEINC_POLICY_LIST_ONLY and \ | 448 | if notifications_policy == BEINC_POLICY_LIST_ONLY and ( |
| 415 | ( | 449 | '{0}.{1}'.format( |
| 416 | '{0}.{1}'.format( | 450 | ph_values['server'], |
| 417 | ph_values['server'], | 451 | ph_values['channel'].lower() |
| 418 | ph_values['channel'].lower() | 452 | ) not in global_values['global_chans'] |
| 419 | ) not in global_values['global_chans'] | ||
| 420 | ): | 453 | ): |
| 421 | return weechat.WEECHAT_RC_OK | 454 | return weechat.WEECHAT_RC_OK |
| 422 | for target in target_list: | 455 | for target in target_list: |
| @@ -434,24 +467,22 @@ def beinc_privmsg_handler(data, signal, signal_data): | |||
| 434 | if not global_values['global_notifications_policy']: | 467 | if not global_values['global_notifications_policy']: |
| 435 | return weechat.WEECHAT_RC_OK | 468 | return weechat.WEECHAT_RC_OK |
| 436 | c_messages_policy = global_values['global_channel_messages_policy'] | 469 | c_messages_policy = global_values['global_channel_messages_policy'] |
| 437 | if c_messages_policy == BEINC_POLICY_LIST_ONLY and \ | 470 | if c_messages_policy == BEINC_POLICY_LIST_ONLY and ( |
| 438 | ( | 471 | '{0}.{1}'.format( |
| 439 | '{0}.{1}'.format( | 472 | ph_values['server'], |
| 440 | ph_values['server'], | 473 | ph_values['channel'].lower() |
| 441 | ph_values['channel'].lower() | 474 | ) not in global_values['global_chans'] |
| 442 | ) not in global_values['global_chans'] | ||
| 443 | ): | 475 | ): |
| 444 | return weechat.WEECHAT_RC_OK | 476 | return weechat.WEECHAT_RC_OK |
| 445 | for target in target_list: | 477 | for target in target_list: |
| 446 | if not target.enabled: | 478 | if not target.enabled: |
| 447 | continue | 479 | continue |
| 448 | if target.channel_messages_policy == BEINC_POLICY_ALL or \ | 480 | c_messages_policy = target.channel_messages_policy |
| 449 | ( | 481 | if c_messages_policy == BEINC_POLICY_ALL or ( |
| 450 | target.channel_messages_policy == BEINC_POLICY_LIST_ONLY and \ | 482 | c_messages_policy == BEINC_POLICY_LIST_ONLY and |
| 451 | '{0}.{1}'.format( | 483 | '{0}.{1}'.format( |
| 452 | ph_values['server'], | 484 | ph_values['server'], |
| 453 | ph_values['channel'].lower()) in target.chans | 485 | ph_values['channel'].lower()) in target.chans): |
| 454 | ): | ||
| 455 | target.send_channel_message_notification(ph_values) | 486 | target.send_channel_message_notification(ph_values) |
| 456 | return weechat.WEECHAT_RC_OK | 487 | return weechat.WEECHAT_RC_OK |
| 457 | 488 | ||
