class Message
Public Class Methods
Source
# File plugins/message.rb, line 44 def self.admin_allowed?(network:, channel:, nick:, is_op:) RabbotDb.user_allowed_at_level?( network: network, channel: channel, nick: nick, is_op: is_op, minimum: RabbotDb::LEVEL_ADMIN ) end
Source
# File plugins/message.rb, line 16 def self.command_pattern /say(?: (.+))?$/i end
Source
# File plugins/message.rb, line 26 def self.denied_message "Only channel ops and registered admins can use this command." end
Source
# File plugins/message.rb, line 54 def self.dispatch_command(args_text, user_channels:, bot_channels:, network:, nick:, is_op: false) text = args_text.to_s.strip return { error: usage_message } if text.empty? parsed = parse_command(text) return parsed if parsed[:error] target = Silence.resolve_explicit_channel( channel: parsed[:channel], user_channels: user_channels, bot_channels: bot_channels ) return target if target[:error] channel = target[:channel] RabbotUser.seed_channel_defaults(network: network, channel: channel) unless admin_allowed?(network: network, channel: channel, nick: nick, is_op: is_op) return { error: denied_message } end { channel: channel, message: parsed[:message], private_message: "Sent to #{channel}." } end
Source
# File plugins/message.rb, line 30 def self.parse_command(text) stripped = text.to_s.strip return { error: usage_message } if stripped.empty? match = stripped.match(/\A(#\S+)\s*(.*)\z/m) return { error: usage_message } unless match channel = match[1].strip message = match[2].strip return { error: "Message cannot be empty." } if message.empty? { channel: channel, message: message } end
Source
# File plugins/message.rb, line 22 def self.usage_message "Usage: /msg <bot> !say <#channel> <text>" end
Public Instance Methods
Source
# File plugins/message.rb, line 81 def execute(m, args_text = nil) result = self.class.dispatch_command( args_text, user_channels: m.user.channels.map(&:name), bot_channels: bot.channels.map(&:name), network: bot.config.server, nick: m.user.nick ) if result[:error] flood_safe_reply(m, result[:error]) return end channel_name = result[:channel] Channel(channel_name).send(result[:message]) Ai.append_log( channel_name, nick: bot.nick, text: result[:message], network: bot.config.server, from_bot: true ) flood_safe_reply(m, result[:private_message]) end