def privmsg(m)
if(m.address? && m.private?)
case m.message
when (/^setlevel\s+(\S+)\s+(\d+)$/)
if( @bot.auth.allow?( 'auth', m.source, m.replyto ) )
@bot.auth.setlevel( $1, $2.to_i )
m.reply "level for #$1 set to #$2"
end
when( /^useradd\s+(\S+)/ )
if( @bot.auth.allow?( 'auth', m.source, m.replyto ) )
@bot.auth.useradd( $1 )
m.reply "added user #$1, please set him up correctly"
end
when( /^userdel\s+(\S+)/ )
if( @bot.auth.allow?( 'auth', m.source, m.replyto ) )
@bot.auth.userdel( $1 )
m.reply "user #$1 is gone"
end
when( /^usermod\s+(\S+)\s+(\S+)\s+(\S+)/ )
if( @bot.auth.allow?('auth', m.source, m.replyto ) )
if( @bot.auth.usermod( $1, $2, $3 ) )
m.reply "Set #$2 of #$1 to #$3"
else
m.reply "Failed to set #$2 of #$1 to #$3"
end
end
when( /^setpassword\s+(\S+)/ )
password = $1
user = @bot.auth.matchingUser( m.source )
if user
if @bot.auth.usermod(user, 'password', password)
m.reply "Your password has been set to #{password}"
else
m.reply "Couldn't set password"
end
else
m.reply 'You don\'t belong to any user.'
end
when (/^auth\s+(\S+)/)
if( $1 == @bot.config['auth.password'] )
if ! @users.has_key? 'master'
@bot.auth.useradd( 'master', 1000, @bot.config['auth.password'], m.source )
else
@bot.auth.usermod( 'master', '+hostmask', m.source )
end
m.reply 'Identified, security level maxed out'
else
m.reply 'Incorrect password'
end
when( /^identify\s+(\S+)\s+(\S+)/ )
if @bot.auth.identify( m.source, $1, $2 )
m.reply "Identified as #$1 (#{@users[$1].level})"
else
m.reply 'Incorrect username/password'
end
when( 'whoami' )
user = @bot.auth.matchingUser( m.source )
if user
m.reply "I recognize you as #{user} (#{@users[user].level})"
else
m.reply 'You don\'t belong to any user.'
end
when( /^users\s+(\S+)/ )
m.reply @bot.auth.showdetails( $1 ) if( @bot.auth.allow?( 'auth', m.source, m.replyto ) )
when ( 'levels' )
m.reply @bot.auth.showlevels if( @bot.auth.allow?( 'config', m.source, m.replyto ) )
when ( 'users' )
m.reply @bot.auth.showusers if( @bot.auth.allow?( 'users', m.source, m.replyto ) )
end
end
end