Method: Cinch::Extensions::Authentication#login_strategy

Defined in:
lib/cinch/extensions/authentication.rb

#login_strategy(m, levels) ⇒ Object

Internal: Checks if the user sending the message has logged in.

m- The Cinch::Message. levels - The level Symbol(s).



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/cinch/extensions/authentication.rb', line 120

def (m, levels)
  if current_user(m).nil?
    m.user.notice "You are not authorized to run this command. Please " +
      "log in using !login [<username>] <password>."
    return false
  end

  levels = Array(levels)

  levels.each do |level|
    level_lambda = config[level] || bot.config.authentication.send(level)

    return true if level_lambda.call current_user(m)
  end

  # The previous check will fail if no level is given.
  return true if levels.nil?

  m.user.notice 'You are not authorized to run this command.'
  return false
end