Class: Tkellem::TkellemBot::AtConnectCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/tkellem/tkellem_bot.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #bouncer, #conn, #options, #opts

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

admin_option, admin_user?, build_options, #initialize, option, register, resources, #respond, run, #show_help, #user

Constructor Details

This class inherits a constructor from Tkellem::TkellemBot::Command

Class Method Details

.admin_only?Boolean

Returns:

  • (Boolean)


294
295
296
# File 'lib/tkellem/tkellem_bot.rb', line 294

def self.admin_only?
  false
end

Instance Method Details

#executeObject



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/tkellem/tkellem_bot.rb', line 309

def execute
  if opts['network'].present? # only settable by admins
    target = Network.where(["name = ? AND user_id IS NULL", opts['network'].downcase]).first
  else
    target = bouncer.try(:network_user)
  end
  raise(Command::ArgumentError, "No network found") unless target

  if args.size == 0
    r "At connect:"
    list(target)
  else
    line = args.join(' ')
    raise(Command::ArgumentError, "atconnect commands must start with a /") unless line[0] == '/'[0]
    if opts['remove']
      target.at_connect = (target.at_connect || []).reject { |l| l == line }
    else
      target.at_connect = (target.at_connect || []) + [line]
    end
    target.save
    r "At connect commands modified:"
    list(target)
  end
end

#list(target) ⇒ Object



298
299
300
301
302
303
304
305
306
307
# File 'lib/tkellem/tkellem_bot.rb', line 298

def list(target)
  target.reload
  if target.is_a?(NetworkUser) && target.network.public?
    r "Network-wide commands are prefixed with [N], user-specific commands with [U]."
    r "Network-wide commands can only be modified by admins."
    list(target.network)
  end
  prefix = target.is_a?(Network) ? 'N' : 'U'
  target.at_connect.try(:each) { |line| r "    [#{prefix}] #{line}" }
end