Class: Tkellem::TkellemBot::PasswordCommand

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)


257
258
259
# File 'lib/tkellem/tkellem_bot.rb', line 257

def self.admin_only?
  false
end

Instance Method Details

#executeObject



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/tkellem/tkellem_bot.rb', line 261

def execute
  user = self.user

  if opts['username']
    if Command.admin_user?(user)
      user = User.where({ :username => opts['username'] }).first
    else
      raise Command::ArgumentError, "Only admins can change other passwords"
    end
  end

  unless user
    raise Command::ArgumentError, "User required"
  end

  password = args.shift || ''

  if password.size < 4
    raise Command::ArgumentError, "New password too short"
  end

  user.password = password
  user.save!
  respond "New password set for #{user.username}"
end