module BannerDispatch
BannerDispatch — route !banner in channel vs PM relay to a shared channel. Public: private_message?, parse_pm_command, dispatch_command Depends: BannerReport, ChanOps Tests: test/lib/banner_dispatch_test.rb, test/plugins/banner_test.rb
Public Instance Methods
Source
# File lib/banner_dispatch.rb, line 48 def dispatch_channel(args, **kwargs) BannerReport.format_command(args, **kwargs).merge(relay: false) end
Source
# File lib/banner_dispatch.rb, line 40 def dispatch_command(args, channel:, user_channels:, bot_channels:, **kwargs) if private_message?(channel) dispatch_private(args, user_channels: user_channels, bot_channels: bot_channels, **kwargs) else dispatch_channel(args, **kwargs) end end
Source
# File lib/banner_dispatch.rb, line 52 def dispatch_private(args, user_channels:, bot_channels:, **kwargs) text = args.to_s.strip return BannerReport.error_result(pm_usage_message) if text.empty? parsed = parse_pm_command(text) return BannerReport.error_result(parsed[:error]) if parsed[:error] target = ChanOps.resolve_explicit_channel( channel: parsed[:channel], user_channels: user_channels, bot_channels: bot_channels ) return BannerReport.error_result(ChanOps.channel_gate_error) if target[:error] result = BannerReport.format_command(parsed[:banner_args], **kwargs) return result.merge(relay: false) if result[:error] { error: false, relay: true, channel: target[:channel], reply: result[:reply], private_message: format_pm_acknowledgment(channel: target[:channel]) } end
Source
# File lib/banner_dispatch.rb, line 36 def format_pm_acknowledgment(channel:) "Sent banner to #{channel}." end
Source
# File lib/banner_dispatch.rb, line 22 def parse_pm_command(text) stripped = text.to_s.strip return { error: pm_usage_message } if stripped.empty? match = stripped.match(/\A(#\S+)\s*(.*)\z/m) return { error: pm_usage_message } unless match channel = match[1].strip banner_args = match[2].strip return { error: "Banner parameters cannot be empty." } if banner_args.empty? { channel: channel, banner_args: banner_args } end
Source
# File lib/banner_dispatch.rb, line 18 def pm_usage_message "Usage: /msg <bot> !banner <#channel> [<engine>] <heading> [. <label> <body> …]" end
Source
# File lib/banner_dispatch.rb, line 14 def private_message?(channel) channel.nil? || channel.to_s.strip.empty? end